const getEnsuredArray = item => { if (!util.isArray(item)) { return [item]; } return item; }
this.persistence.persistNewState(util.isArray(preparedDoc) ? preparedDoc : [preparedDoc], function (err) { if (err) { return callback(err); } return callback(null, model.deepCopy(preparedDoc)); });
/** * Tells if an object is a primitive type or a "real" object * Arrays are considered primitive */ function isPrimitiveType (obj) { return ( typeof obj === 'boolean' || typeof obj === 'number' || typeof obj === 'string' || obj === null || util.isDate(obj) || util.isArray(obj)); }
//let proxy = config.proxy[0]; function toCookieObj(cookieInput) { let result = []; if (util.isArray(cookieInput)) { for (let el of cookieInput) { result.push(el.split(';')[0]); } return cookie.parse(result.join(';')); } else { return cookie.parse(cookieInput); } }
var eventedCallback = function (err, newDocs) { if (err) { return callback(err, newDocs) } var newDocsArr = util.isArray(newDocs) ? newDocs : [newDocs] // Ensure there are listeners registered before making a bunch of unnecessary function calls to `emit` if (self.listeners('inserted').length > 0) { newDocsArr.forEach(function (newDoc) { self.__events.emit('inserted', newDoc) }) } return callback(null, newDocs) }
//TODO: move to helper.js? function toCommandArgs(cmd, arch, keys) { let result = baseCommand(cmd, arch) if (typeof keys === 'string') { result.push(keys) } else if (util.isArray(keys)) { result = result.concat(keys) } else { debug('creating command without using keys %s', keys ? keys : '') } return result }
/** * Check a DB object and throw an error if it's not valid * Works by applying the above checkKey function to all fields recursively */ function checkObject (obj) { if (util.isArray(obj)) { obj.forEach(function (o) { checkObject(o); }); } if (typeof obj === 'object' && obj !== null) { Object.keys(obj).forEach(function (k) { checkKey(k, obj[k]); checkObject(obj[k]); }); } }
function browserSyncInit(baseDir, files, browser) { browser = browser === undefined ? 'default' : browser; var routes = null; if (baseDir === 'src' || (util.isArray(baseDir) && baseDir.indexOf('src') !== -1)) { routes = { // Should be '/bower_components': '../bower_components' // Waiting for https://github.com/shakyShane/browser-sync/issues/308 '/bower_components': 'bower_components', '/data': 'data' }; } browserSync.instance = browserSync.init(files, { startPath: '/', server: { baseDir: baseDir, middleware: middleware, routes: routes }, browser: browser //logLevel: 'debug' }); }
/** * Type-aware projection */ function projectForUnique (elt) { if (elt === null) { return '$null'; } if (typeof elt === 'string') { return '$string' + elt; } if (typeof elt === 'boolean') { return '$boolean' + elt; } if (typeof elt === 'number') { return '$number' + elt; } if (util.isArray(elt)) { return '$date' + elt.getTime(); } return elt; // Arrays and objects, will check for pointer equality }
//let proxy = config.proxy[0]; function toCookieObj(cookieInput) { let result = []; if (util.isArray(cookieInput)) { for (let el of cookieInput) { result.push(el.split(';')[0]); } return cookie.parse(result.join(';')); } else { return cookie.parse(cookieInput); } }
//let proxy = config.proxy[0]; function toCookieObj(cookieInput) { let result = []; if (util.isArray(cookieInput)) { for (let el of cookieInput) { result.push(el.split(';')[0]); } return cookie.parse(result.join(';')); } else { return cookie.parse(cookieInput); } }
/** * Type-aware projection */ function projectForUnique (elt) { if (elt === null) { return '$null'; } if (typeof elt === 'string') { return '$string' + elt; } if (typeof elt === 'boolean') { return '$boolean' + elt; } if (typeof elt === 'number') { return '$number' + elt; } if (util.isArray(elt)) { return '$date' + elt.getTime(); } return elt; // Arrays and objects, will check for pointer equality }
/** * Tells if an object is a primitive type or a "real" object * Arrays are considered primitive */ function isPrimitiveType (obj) { return ( typeof obj === 'boolean' || typeof obj === 'number' || typeof obj === 'string' || obj === null || util.isDate(obj) || util.isArray(obj)); }
this.persistence.persistNewState(util.isArray(preparedDoc) ? preparedDoc : [preparedDoc], function (err) { if (err) { return callback(err); } return callback(null, model.deepCopy(preparedDoc)); });
/** * Check a DB object and throw an error if it's not valid * Works by applying the above checkKey function to all fields recursively */ function checkObject (obj) { if (util.isArray(obj)) { obj.forEach(function (o) { checkObject(o); }); } if (typeof obj === 'object' && obj !== null) { Object.keys(obj).forEach(function (k) { checkKey(k, obj[k]); checkObject(obj[k]); }); } }