nuclide-commons
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -13,2 +13,3 @@ "use strict"; | ||
exports.mapUnion = mapUnion; | ||
exports.mapCompact = mapCompact; | ||
exports.mapFilter = mapFilter; | ||
@@ -23,2 +24,3 @@ exports.mapTransform = mapTransform; | ||
exports.setDifference = setDifference; | ||
exports.setFilter = setFilter; | ||
exports.isEmpty = isEmpty; | ||
@@ -125,2 +127,12 @@ exports.keyMirror = keyMirror; | ||
function mapCompact(map) { | ||
const selected = new Map(); | ||
for (const [key, value] of map) { | ||
if (value != null) { | ||
selected.set(key, value); | ||
} | ||
} | ||
return selected; | ||
} | ||
function mapFilter(map, selector) { | ||
@@ -183,3 +195,3 @@ const selected = new Map(); | ||
function setIntersect(a, b) { | ||
return new Set(Array.from(a).filter(e => b.has(e))); | ||
return setFilter(a, e => b.has(e)); | ||
} | ||
@@ -214,2 +226,13 @@ | ||
function setFilter(set, predicate) { | ||
const out = new Set(); | ||
for (const item of set) { | ||
if (predicate(item)) { | ||
out.add(item); | ||
} | ||
} | ||
return out; | ||
} | ||
/** | ||
@@ -216,0 +239,0 @@ * O(1)-check if a given object is empty (has no properties, inherited or not) |
@@ -8,2 +8,4 @@ 'use strict'; | ||
var _asyncToGenerator = _interopRequireDefault(require('async-to-generator')); | ||
var _lruCache; | ||
@@ -37,4 +39,4 @@ | ||
constructor(configFileName) { | ||
this._configFileName = configFileName; | ||
constructor(configFileNames) { | ||
this._configFileNames = configFileNames; | ||
this._configCache = (0, (_lruCache || _load_lruCache()).default)({ | ||
@@ -46,10 +48,27 @@ max: 200, // Want this to exceed the maximum expected number of open files + dirs. | ||
getConfigDir(path) { | ||
if (!this._configCache.has(path)) { | ||
const result = (_fsPromise || _load_fsPromise()).default.findNearestFile(this._configFileName, path); | ||
let result = this._configCache.get(path); | ||
if (result == null) { | ||
result = this._findConfigDir(path); | ||
this._configCache.set(path, result); | ||
return result; | ||
} | ||
return this._configCache.get(path); | ||
return result; | ||
} | ||
_findConfigDir(path) { | ||
var _this = this; | ||
return (0, _asyncToGenerator.default)(function* () { | ||
const configDirs = yield Promise.all(_this._configFileNames.map(function (configFile) { | ||
return (_fsPromise || _load_fsPromise()).default.findNearestFile(configFile, path); | ||
})); | ||
// Find the result with the greatest length (the closest match). | ||
return configDirs.filter(Boolean).reduce(function (previous, configDir) { | ||
if (previous == null || configDir.length > previous.length) { | ||
return configDir; | ||
} | ||
return previous; | ||
}, null); | ||
})(); | ||
} | ||
dispose() { | ||
@@ -56,0 +75,0 @@ this._configCache.reset(); |
{ | ||
"name": "nuclide-commons", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Common Nuclide node modules.", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
300653
4328