module.exports = function expand() { var args = slice(arguments); var len = args.length; var i = 0; var fn; var patterns = []; while (i < len) { var arg = args[i++]; if (typeof arg === 'string') { patterns.push(arg); } if (Array.isArray(arg)) { patterns.push.apply(patterns, arg); } if (typeof arg === 'function') { fn = arg; break; } } var plen = patterns.length; var arr = []; var j = 0; while (j < plen) { arr.push.apply(arr, braces(patterns[j++], fn)); } return uniq(arr); };
module.exports = function (array, filter) { if (!filter) { return unique(array); } return unique_with_filter(array, filter); };
module.exports = function braceExpandJoin() { if (arguments.length === 0) { throw new Error('More than 1 glob pattern string required.'); } var joinedPatterns = [].slice.call(arguments) .map(function(pattern) { return braceExpand(pattern).map(function(pattern) { return path.normalize(pattern); }); }) .reduce(function(parentPatterns, childPatterns) { return parentPatterns.reduce(function(ret, parentPattern) { return ret.concat(childPatterns.map(function(childPattern) { return path.join(parentPattern, childPattern); })); }, []); }); joinedPatterns = arrayUniq(joinedPatterns); if (joinedPatterns.length > 1) { return '{' + joinedPatterns.join(',') + '}'; } return joinedPatterns[0]; };
module.exports = function majorVersions (range, maximum) { if (!range) throw new Error('range is required') if (maximum != null && !semver.valid(maximum)) { throw new Error('maximum must be a valid semver') } // deduping has a side effect of sorting range = dedupeRange(range) var versions = new semver.Range(range) .set // filter out comparators that don't resolve .filter(resolves.comparators) // ensure there's a lower bound to the range // bound w/ 0 if needed .map(applyLowerBound) // enforce an upper bound .map(ensureUpperBound(range, maximum)) // get a list of major versions .map(comparators => getVersions(comparators, maximum)) // merge to a single array .reduce(merge(), []) // remove extra zeros .map(stripZeros) return unique(versions) }
util.ApiError = createErrorClass('ApiError', function(errorBody) { this.code = errorBody.code; this.errors = errorBody.errors; this.response = errorBody.response; try { this.errors = JSON.parse(this.response.body).error.errors; } catch (e) { this.errors = errorBody.errors; } const messages = []; if (errorBody.message) { messages.push(errorBody.message); } if (this.errors && this.errors.length === 1) { messages.push(this.errors[0].message); } else if (this.response && this.response.body) { messages.push(ent.decode(errorBody.response.body.toString())); } else if (!errorBody.message) { messages.push('Error during request.'); } this.message = uniq(messages).join(' - '); });
module.exports = function npmignore(npm, git, options) { if (typeof git !== 'string') { options = git; git = ''; } options = options || {}; if (typeof git === 'string') { git = split(git); } // get the relevant lines from `.npmignore` if (typeof npm === 'string') { npm = extract(npm); } if (options.unignore) { git = diff(git, arrayify(options.unignore)); npm = diff(npm, arrayify(options.unignore)); } // Remove the comment, we re-add later npm = diff(npm, comment.concat('#npmignore # npmignore')); npm = diff(npm, git); if (options.ignore) { npm = npm.concat(arrayify(options.ignore)); } return format(git, uniq(npm)); }
eachAsync(this.src(), function (src, i, next) { var options = objectAssign({}, this.options, src.options); var sizes = arrayUniq(src.sizes.filter(/./.test, /^\d{3,4}x\d{3,4}$/i)); var keywords = arrayDiffer(src.sizes, sizes); if (!src.url) { cb(new Error('URL required')); return; } this.urls.push(src.url); if (!sizes.length && keywords.indexOf('w3counter') !== -1) { this.resolution(src.url, options, next); return; } if (keywords.length) { this.viewport({url: src.url, sizes: sizes, keywords: keywords}, options, next); return; } sizes.forEach(function (size) { this.sizes.push(size); try { this.items.push(this.create(src.url, size, options)); } catch (err) { next(err); } }.bind(this)); next(); }.bind(this), function (err) {
module.exports = function braceExpandJoin() { var args = sliced(arguments); if (args.length === 0) { throw new TypeError('More than 1 glob pattern string required.'); } var len = args.length; var patterns = new Array(len); while (len--) { patterns[len] = braceExpansion(args[len]).map(path.normalize); } var joinedPatterns = patterns.reduce(function(parentPatterns, childPatterns) { return concatMap(parentPatterns, function(parentPattern) { return childPatterns.map(function(childPattern) { return path.join(parentPattern, childPattern); }); }); }); joinedPatterns = arrayUniq(joinedPatterns); if (joinedPatterns.length > 1) { return '{' + joinedPatterns.join(',') + '}'; } return joinedPatterns[0]; };
Module.getUpdated = function() { var command = 'git'; var args = ['diff']; if (!isPushToMaster()) { var remotes = spawn('git', ['remote', '-v'], { cwd: ROOT_DIR, stdio: null }); var remotesStdout = remotes.stdout && remotes.stdout.toString(); if (remotesStdout && remotesStdout.indexOf('temp') === -1) { run([ 'git remote add temp', 'https://github.com/GoogleCloudPlatform/google-cloud-node.git' ]); run('git fetch -q temp'); } args.push('HEAD', 'temp/master'); } else { args.push('HEAD^'); } args.push('--name-only'); console.log(command, args.join(' ')); // There's a Windows bug where child_process.exec exits early on `git diff` // which in turn does not return all of the files that have changed. This can // cause a false positive when checking for package changes on AppVeyor var output = spawn(command, args, { cwd: ROOT_DIR, stdio: null }); if (output.status || output.error) { console.error(output.error || output.stderr.toString()); exit(output.status || 1); } var files = output.stdout.toString(); console.log(files); var modules = files .trim() .split('\n') .filter(function(file) { return /^packages\/.+\.js/.test(file); }) .map(function(file) { return file.split('/')[1]; }); return uniq(modules).map(Module); };
}.bind(this), function (err) { if (err) { cb(err); return; } this.stats.urls = arrayUniq(this.urls).length; this.stats.sizes = arrayUniq(this.sizes).length; this.stats.screenshots = this.items.length; if (!this.dest()) { cb(null, this.items); return; } this.save(this.items, cb); }.bind(this));
/** * Return all the classes in a CSS selector. * * @param {String} selector A CSS selector * @return {String[]} An array of every class present in the CSS selector */ function getCssSelectorClasses(selector) { var list = [] var ast = cssSelector.parse(selector) visitRules(ast, function(ruleSet) { if (ruleSet.classNames) { list = list.concat(ruleSet.classNames) } }) return uniq(list) }
module.exports = (input, options = {}) => { if (typeof input !== 'string') { throw new TypeError(`Expected a string, got ${typeof input}`); } const reLoose = new RegExp(`(?:${semverRegex().source})|(?:v?(?:\\d+\\.\\d+)(?:\\.\\d+)?)`, 'g'); const matches = input.match(options.loose === true ? reLoose : semverRegex()) || []; return arrayUniq(matches.map(match => match.trim().replace(/^v/, '').replace(/^\d+\.\d+$/, '$&.0'))); };
export async function viewport(obj, options) { for (const item of await viewportListMem(obj.keywords)) { this.sizes.push(item.size); obj.sizes.push(item.size); } for (const size of arrayUniq(obj.sizes)) { this.items.push(this.create(obj.url, size, options)); } }
module.exports = function expand(val, fn) { val = Array.isArray(val) ? val : [val]; var len = val.length; var arr = []; var i = 0; while (i < len) { arr.push.apply(arr, braces(val[i++], fn)); } return uniq(arr); };
module.exports = function (str, opts) { var urls = str.match(urlRegex()); if (!urls) { return []; } return arrayUniq(urls.map(function (url) { return normalizeUrl(url.trim().replace(/\.*$/, ''), opts); })); };
module.exports = function expand(val, fn) { var args = slice(arguments); args[0] = Array.isArray(args[0]) ? args[0] : [args[0]]; var len = val.length; var arr = []; var i = 0; while (i < len) { arr = arr.concat(braces(val[i++], fn)); } return uniq(arr); };
_.each(file_filtered_list, function(file) { if (file != '' && !fs.lstatSync(file).isDirectory()) { var data = fs.readFileSync(file); if (data == undefined || data == null) {} else { for (depKey in pjson.dependencies) { if (data != undefined && data != null && (data.toString().indexOf(depKey)) > -1) { used_deps.push(depKey); } } used_deps = uniq(used_deps); } } });
runAfterChanges() { const dirtyStates = this.dirtyStates; this.dirtyStates = {}; const dirtyPaths = Object.keys(dirtyStates).filter(path => { if (this.touchedFiles.has(path)) { debug('Ignoring known touched file %s', path); this.touchedFiles.delete(path); return false; } return true; }); const dirtyTests = dirtyPaths.filter(this.avaFiles.isTest); const dirtySources = diff(dirtyPaths, dirtyTests); const addedOrChangedTests = dirtyTests.filter(path => dirtyStates[path] !== 'unlink'); const unlinkedTests = diff(dirtyTests, addedOrChangedTests); this.cleanUnlinkedTests(unlinkedTests); // No need to rerun tests if the only change is that tests were deleted if (unlinkedTests.length === dirtyPaths.length) { return; } if (dirtySources.length === 0) { // Run any new or changed tests this.run(addedOrChangedTests); return; } // Try to find tests that depend on the changed source files const testsBySource = dirtySources.map(path => { return this.testDependencies.filter(dep => dep.contains(path)).map(dep => { debug('%s is a dependency of %s', path, dep.file); return dep.file; }); }, this).filter(tests => tests.length > 0); // Rerun all tests if source files were changed that could not be traced to // specific tests if (testsBySource.length !== dirtySources.length) { debug('Sources remain that cannot be traced to specific tests: %O', dirtySources); debug('Rerunning all tests'); this.run(); return; } // Run all affected tests this.run(union(addedOrChangedTests, uniq(flatten(testsBySource)))); }
module.exports = function( str, opts ) { if( typeof str !== 'string' ) { throw new TypeError( 'Expected a string' ); } opts = opts || {}; var reLoose = new RegExp( '(?:' + semverRegex().source + ')|(?:v?(?:\\d+\\.\\d+)(?:\\.\\d+)?)', 'g' ); var matches = str.match( opts.loose === true ? reLoose : semverRegex() ) || []; return arrayUniq( matches.map( function( el ) { return el.trim().replace( /^v/, '' ).replace( /^\d+\.\d+$/, '$&.0' ); } ) ); };
module.exports = function (str, opts) { if (typeof str !== 'string') { throw new TypeError('Expected a string'); } opts = opts || {}; var loose = opts.loose === undefined ? false : opts.loose; var semverMatches = str.match(semverRegex()) || []; var looseMatches = loose ? findLoose(str) : []; return arrayUniq(semverMatches.concat(looseMatches).map(function (el) { return el.replace(/^v/, '').replace(/^\d+\.\d+$/, '$&.0'); })); };
Watcher.prototype.runAfterChanges = function () { var dirtyStates = this.dirtyStates; this.dirtyStates = {}; var dirtyPaths = Object.keys(dirtyStates); var dirtyTests = dirtyPaths.filter(this.isTest); var dirtySources = diff(dirtyPaths, dirtyTests); var addedOrChangedTests = dirtyTests.filter(function (path) { return dirtyStates[path] !== 'unlink'; }); var unlinkedTests = diff(dirtyTests, addedOrChangedTests); this.cleanUnlinkedTests(unlinkedTests); // No need to rerun tests if the only change is that tests were deleted. if (unlinkedTests.length === dirtyPaths.length) { return; } if (dirtySources.length === 0) { // Run any new or changed tests. this.run(addedOrChangedTests); return; } // Try to find tests that depend on the changed source files. var testsBySource = dirtySources.map(function (path) { return this.testDependencies.filter(function (dep) { return dep.contains(path); }).map(function (dep) { debug('%s is a dependency of %s', path, dep.file); return dep.file; }); }, this).filter(function (tests) { return tests.length > 0; }); // Rerun all tests if source files were changed that could not be traced to // specific tests. if (testsBySource.length !== dirtySources.length) { debug('Sources remain that cannot be traced to specific tests. Rerunning all tests'); this.run(); return; } // Run all affected tests. this.run(union(addedOrChangedTests, uniq(flatten(testsBySource)))); };
TransactionRequest.prototype.mutate_ = function(method, table, keyVals, cb) { keyVals = arrify(keyVals); var columns = uniq(flatten(keyVals.map(Object.keys))).sort(); var values = keyVals.map(function(keyVal, index) { var keys = Object.keys(keyVal); var missingColumns = columns.filter(column => keys.indexOf(column) === -1); if (missingColumns.length > 0) { throw new Error([ `Row at index ${index} does not contain the correct number of columns.`, `Missing columns: ${JSON.stringify(missingColumns)}` ].join('\n\n')); } return columns.map(function(column) { var value = keyVal[column]; return codec.encode(value); }); }); var mutation = { [method]: { table, columns, values } }; if (this.transaction) { this.queue_(mutation); return; } var reqOpts = { singleUseTransaction: { readWrite: {} }, mutations: [mutation] }; return this.request({ reqOpts: reqOpts, method: this.api.Spanner.commit.bind(this.api.Spanner) }, cb); };
function PluginError(plugin, message, opt) { if (!(this instanceof PluginError)) throw new Error('Call PluginError using new'); Error.call(this); var options = parseOptions(plugin, message, opt); var self = this; // if options has an error, grab details from it if (options.error) { // These properties are not enumerable, so we have to add them explicitly. arrayUniq(Object.keys(options.error).concat(nonEnumberableProperties)) .forEach(function(prop) { self[prop] = options.error[prop]; }); } var properties = ['name', 'message', 'fileName', 'lineNumber', 'stack', 'showStack', 'showProperties', 'plugin']; // options object can override properties.forEach(function(prop) { if (prop in options) this[prop] = options[prop]; }, this); // defaults if (!this.name) this.name = 'Error'; if (!this.stack) { // Error.captureStackTrace appends a stack property which relies on the toString method of the object it is applied to. // Since we are using our own toString method which controls when to display the stack trace if we don't go through this // safety object, then we'll get stack overflow problems. var safety = { toString: function() { return this._messageWithDetails() + '\nStack:'; }.bind(this) }; Error.captureStackTrace(safety, arguments.callee || this.constructor); this.__safety = safety; } if (!this.plugin) throw new Error('Missing plugin name'); if (!this.message) throw new Error('Missing error message'); }
var ApiError = createErrorClass('ApiError', function(errorBody) { this.errors = errorBody.errors; this.code = errorBody.code; this.response = errorBody.response; var messages = []; if (errorBody.message) { messages.push(errorBody.message); } if (errorBody.errors && errorBody.errors.length === 1) { messages.push(errorBody.errors[0].message); } else if (errorBody.response && errorBody.response.body) { messages.push(errorBody.response.body.toString()); } else if (!errorBody.message) { messages.push('Error during request.'); } this.message = uniq(messages).join(' - '); });
.then(data => { const ret = []; for (const x of data) { if (x.Territory !== '') { ret.push(x.Territory); } if (x['Local code'] !== '') { ret.push(x['Local code']); } if (x['Full code'] !== '') { ret.push(x['Full code']); } } const out = `'use strict';\nmodule.exports = () => (/(?:(${arrayUniq(ret).sort().join('|')}) )?[ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqrstuvwxyz0-9]{2,}\.[ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqrstuvwxyz0-9]{2,}(-[0-9]{1,8})?/g);\n`; fs.writeFileSync('index.js', out); });
function validateGitIgnoreFile (dir) { var ignores = [ 'node_modules', 'lib', 'dist' ]; var gitFile = path.join(dir, '.gitignore'), contents, len; fse.ensureFileSync(gitFile); contents = fs.readFileSync(gitFile, 'utf8'); contents = contents ? contents.split('\n') : []; len = contents.length; contents = unq(contents.concat(ignores)); logger.log('debug', 'writing .gitignore file contents back to file, added %d entries', contents.length - len); fs.writeFileSync(gitFile, contents.join('\n')); }
Charset.prototype.removeDuplicates = function() { var charMap = this.chars.split(''); charMap = arrayUniq(charMap); this.chars = charMap.join(''); }
module.exports = function () { return arrayUniq([].concat.apply([], arguments)); };
.then(function (typings) { return references_1.stringifyReferences(uniq(typings).sort(), cwd); });
import arrayUniq from 'array-uniq'; const a: Array<number> = arrayUniq([1, 1, 2, 3, 3]); //=> [1, 2, 3] const b: Array<string> = arrayUniq(['foo', 'foo', 'bar', 'foo']); //=> ['foo', 'bar'] // $ExpectError const c: Array<string> = arrayUniq([1, 2, 3]);