object-scan
Advanced tools
Comparing version 1.1.6 to 1.2.0
const parser = require("./util/parser"); | ||
module.exports = (needles, valueFn = undefined, joined = true) => { | ||
const escape = input => String(input).replace(/[,.*[\]{}]/g, "\\$&"); | ||
module.exports = (needles, { | ||
filterFn = undefined, | ||
breakFn = undefined, | ||
joined = true | ||
} = {}) => { | ||
const search = needles.map(parser); | ||
@@ -10,3 +16,3 @@ | ||
if (checks.some(check => check.length === 0)) { | ||
if (valueFn === undefined || valueFn(haystack)) { | ||
if (filterFn === undefined || filterFn(pathIn.map(escape).join("."), haystack)) { | ||
result.push(joined ? pathIn.reduce((p, c) => { | ||
@@ -19,28 +25,30 @@ const isNumber = typeof c === "number"; | ||
if (haystack instanceof Object) { | ||
if (Array.isArray(haystack)) { | ||
for (let i = 0; i < haystack.length; i += 1) { | ||
checks.filter(check => check.length !== 0).forEach(check => { | ||
const pathOut = [].concat(...pathIn).concat(i); | ||
if (breakFn === undefined || !breakFn(pathIn.map(escape).join("."), haystack)) { | ||
if (haystack instanceof Object) { | ||
if (Array.isArray(haystack)) { | ||
for (let i = 0; i < haystack.length; i += 1) { | ||
checks.filter(check => check.length !== 0).forEach(check => { | ||
const pathOut = [].concat(...pathIn).concat(i); | ||
if (check[0] === "**") { | ||
result.push(...find(haystack[i], [check, check.slice(1)], pathOut)); | ||
} else if (check[0] === "[*]" || check[0] === `[${i}]` || check[0] instanceof Array && check[0].indexOf(`[${i}]`) !== -1) { | ||
result.push(...find(haystack[i], [check.slice(1)], pathOut)); | ||
} | ||
if (check[0] === "**") { | ||
result.push(...find(haystack[i], [check, check.slice(1)], pathOut)); | ||
} else if (check[0] === "[*]" || check[0] === `[${i}]` || check[0] instanceof Array && check[0].indexOf(`[${i}]`) !== -1) { | ||
result.push(...find(haystack[i], [check.slice(1)], pathOut)); | ||
} | ||
}); | ||
} | ||
} else { | ||
Object.keys(haystack).forEach(key => { | ||
checks.filter(check => check.length !== 0).forEach(check => { | ||
const escapedKey = escape(key); | ||
const pathOut = [].concat(...pathIn).concat(key); | ||
if (check[0] === "**") { | ||
result.push(...find(haystack[key], [check, check.slice(1)], pathOut)); | ||
} else if (check[0] === "*" || check[0] === escapedKey || check[0] instanceof Array && check[0].indexOf(escapedKey) !== -1) { | ||
result.push(...find(haystack[key], [check.slice(1)], pathOut)); | ||
} | ||
}); | ||
}); | ||
} | ||
} else { | ||
Object.keys(haystack).forEach(key => { | ||
checks.filter(check => check.length !== 0).forEach(check => { | ||
const escapedKey = key.replace(/[,.*[\]{}]/g, "\\$&"); | ||
const pathOut = [].concat(...pathIn).concat(key); | ||
if (check[0] === "**") { | ||
result.push(...find(haystack[key], [check, check.slice(1)], pathOut)); | ||
} else if (check[0] === "*" || check[0] === escapedKey || check[0] instanceof Array && check[0].indexOf(escapedKey) !== -1) { | ||
result.push(...find(haystack[key], [check.slice(1)], pathOut)); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -54,2 +62,2 @@ } | ||
}; | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6WyJwYXJzZXIiLCJyZXF1aXJlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm5lZWRsZXMiLCJ2YWx1ZUZuIiwidW5kZWZpbmVkIiwiam9pbmVkIiwic2VhcmNoIiwibWFwIiwiZmluZCIsImhheXN0YWNrIiwiY2hlY2tzIiwicGF0aEluIiwicmVzdWx0Iiwic29tZSIsImNoZWNrIiwibGVuZ3RoIiwicHVzaCIsInJlZHVjZSIsInAiLCJjIiwiaXNOdW1iZXIiLCJPYmplY3QiLCJBcnJheSIsImlzQXJyYXkiLCJpIiwiZmlsdGVyIiwiZm9yRWFjaCIsInBhdGhPdXQiLCJjb25jYXQiLCJzbGljZSIsImluZGV4T2YiLCJrZXlzIiwia2V5IiwiZXNjYXBlZEtleSIsInJlcGxhY2UiXSwibWFwcGluZ3MiOiJBQUFBLE1BQU1BLFNB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AgICBpZiAoY2hlY2tbMF0gPT09IFwiKipcIikge1xuICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKC4uLmZpbmQoaGF5c3RhY2tbaV0sIFtjaGVjaywgY2hlY2suc2xpY2UoMSldLCBwYXRoT3V0KSk7XG4gICAgICAgICAgICAgIH0gZWxzZSBpZiAoXG4gICAgICAgICAgICAgICAgY2hlY2tbMF0gPT09IFwiWypdXCIgfHxcbiAgICAgICAgICAgICAgICBjaGVja1swXSA9PT0gYFske2l9XWAgfHxcbiAgICAgICAgICAgICAgICAoY2hlY2tbMF0gaW5zdGFuY2VvZiBBcnJheSAmJiBjaGVja1swXS5pbmRleE9mKGBbJHtpfV1gKSAhPT0gLTEpXG4gICAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKC4uLmZpbmQoaGF5c3RhY2tbaV0sIFtjaGVjay5zbGljZSgxKV0sIHBhdGhPdXQpKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIE9iamVjdC5rZXlzKGhheXN0YWNrKS5mb3JFYWNoKChrZXkpID0+IHtcbiAgICAgICAgICBjaGVja3NcbiAgICAgICAgICAgIC5maWx0ZXIoY2hlY2sgPT4gY2hlY2subGVuZ3RoICE9PSAwKVxuICAgICAgICAgICAgLmZvckVhY2goKGNoZWNrKSA9PiB7XG4gICAgICAgICAgICAgIGNvbnN0IGVzY2FwZWRLZXkgPSBrZXkucmVwbGFjZSgvWywuKltcXF17fV0vZywgXCJcXFxcJCZcIik7XG4gICAgICAgICAgICAgIGNvbnN0IHBhdGhPdXQgPSBbXS5jb25jYXQoLi4ucGF0aEluKS5jb25jYXQoa2V5KTtcbiAgICAgICAgICAgICAgaWYgKGNoZWNrWzBdID09PSBcIioqXCIpIHtcbiAgICAgICAgICAgICAgICByZXN1bHQucHVzaCguLi5maW5kKGhheXN0YWNrW2tleV0sIFtjaGVjaywgY2hlY2suc2xpY2UoMSldLCBwYXRoT3V0KSk7XG4gICAgICAgICAgICAgIH0gZWxzZSBpZiAoXG4gICAgICAgICAgICAgICAgY2hlY2tbMF0gPT09IFwiKlwiIHx8XG4gICAgICAgICAgICAgICAgY2hlY2tbMF0gPT09IGVzY2FwZWRLZXkgfHxcbiAgICAgICAgICAgICAgICAoY2hlY2tbMF0gaW5zdGFuY2VvZiBBcnJheSAmJiBjaGVja1swXS5pbmRleE9mKGVzY2FwZWRLZXkpICE9PSAtMSlcbiAgICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goLi4uZmluZChoYXlzdGFja1trZXldLCBbY2hlY2suc2xpY2UoMSldLCBwYXRoT3V0KSk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KTtcbiAgICAgIH1cbiAgICB9XG4gICAgcmV0dXJuIHJlc3VsdDtcbiAgfTtcblxuICByZXR1cm4gaGF5c3RhY2sgPT4gZmluZChoYXlzdGFjaywgc2VhcmNoKTtcbn07XG4iXX0= | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6WyJwYXJzZXIiLCJyZXF1aXJlIiwiZXNjYXBlIiwiaW5wdXQiLCJTdHJpbmciLCJyZXBsYWNlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm5lZWRsZXMiLCJmaWx0ZXJGbiIsInVuZGVmaW5lZCIsImJyZWFrRm4iLCJqb2luZWQiLCJzZWFyY2giLCJtYXAiLCJmaW5kIiwiaGF5c3RhY2siLCJjaGVja3MiLCJwYXRoSW4iLCJyZXN1bHQiLCJzb21lIiwiY2hlY2siLCJsZW5ndGgiLCJqb2luIiwicHVzaCIsInJlZHVjZSIsInAiLCJjIiwiaXNOdW1iZXIiLCJPYmplY3QiLCJBcnJheSIsImlzQXJyYXkiLCJpIi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XG4gICAgICAgICAgICAgICAgICBjaGVja1swXSA9PT0gXCJbKl1cIlxuICAgICAgICAgICAgICAgICAgfHwgY2hlY2tbMF0gPT09IGBbJHtpfV1gXG4gICAgICAgICAgICAgICAgICB8fCAoY2hlY2tbMF0gaW5zdGFuY2VvZiBBcnJheSAmJiBjaGVja1swXS5pbmRleE9mKGBbJHtpfV1gKSAhPT0gLTEpXG4gICAgICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgICByZXN1bHQucHVzaCguLi5maW5kKGhheXN0YWNrW2ldLCBbY2hlY2suc2xpY2UoMSldLCBwYXRoT3V0KSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICB9XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgT2JqZWN0LmtleXMoaGF5c3RhY2spLmZvckVhY2goKGtleSkgPT4ge1xuICAgICAgICAgICAgY2hlY2tzXG4gICAgICAgICAgICAgIC5maWx0ZXIoY2hlY2sgPT4gY2hlY2subGVuZ3RoICE9PSAwKVxuICAgICAgICAgICAgICAuZm9yRWFjaCgoY2hlY2spID0+IHtcbiAgICAgICAgICAgICAgICBjb25zdCBlc2NhcGVkS2V5ID0gZXNjYXBlKGtleSk7XG4gICAgICAgICAgICAgICAgY29uc3QgcGF0aE91dCA9IFtdLmNvbmNhdCguLi5wYXRoSW4pLmNvbmNhdChrZXkpO1xuICAgICAgICAgICAgICAgIGlmIChjaGVja1swXSA9PT0gXCIqKlwiKSB7XG4gICAgICAgICAgICAgICAgICByZXN1bHQucHVzaCguLi5maW5kKGhheXN0YWNrW2tleV0sIFtjaGVjaywgY2hlY2suc2xpY2UoMSldLCBwYXRoT3V0KSk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChcbiAgICAgICAgICAgICAgICAgIGNoZWNrWzBdID09PSBcIipcIlxuICAgICAgICAgICAgICAgICAgfHwgY2hlY2tbMF0gPT09IGVzY2FwZWRLZXlcbiAgICAgICAgICAgICAgICAgIHx8IChjaGVja1swXSBpbnN0YW5jZW9mIEFycmF5ICYmIGNoZWNrWzBdLmluZGV4T2YoZXNjYXBlZEtleSkgIT09IC0xKVxuICAgICAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goLi4uZmluZChoYXlzdGFja1trZXldLCBbY2hlY2suc2xpY2UoMSldLCBwYXRoT3V0KSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gcmVzdWx0O1xuICB9O1xuXG4gIHJldHVybiBoYXlzdGFjayA9PiBmaW5kKGhheXN0YWNrLCBzZWFyY2gpO1xufTtcbiJdfQ== |
{ | ||
"name": "object-scan", | ||
"version": "1.1.6", | ||
"version": "1.2.0", | ||
"description": "Find Keys using Wildcard matching and optional value function.", | ||
@@ -38,3 +38,3 @@ "main": "lib/index.js", | ||
"babel-cli": "7.0.0-beta.3", | ||
"babel-eslint": "8.2.5", | ||
"babel-eslint": "8.2.6", | ||
"babel-plugin-transform-flow-comments": "7.0.0-beta.3", | ||
@@ -45,5 +45,5 @@ "babel-preset-flow": "7.0.0-beta.3", | ||
"coveralls": "3.0.2", | ||
"js-gardener": "1.26.3", | ||
"js-gardener": "1.27.3", | ||
"nyc": "12.0.2", | ||
"semantic-release": "15.6.0" | ||
"semantic-release": "15.8.1" | ||
}, | ||
@@ -50,0 +50,0 @@ "nyc": { |
@@ -23,3 +23,3 @@ # Object-Scan | ||
<!-- eslint-disable-next-line import/no-unresolved --> | ||
<!-- eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies --> | ||
```js | ||
@@ -32,12 +32,27 @@ const objectScan = require('object-scan'); | ||
### Value Function | ||
### Options | ||
Constructor takes second value function parameter which gets passed in the value of the key and is expected to return true or false. | ||
Only results where the value function returns true are returned. | ||
#### filterFn | ||
### Joined | ||
Type: `function`<br> | ||
Default: `undefined` | ||
When dealing with special characters it might be desired to not have the output merged. In this case | ||
the constructor takes a third option which can be set to false to return each key as a list. | ||
Takes arguments `key` (dot joined and escaped) and `value` (value for given key) and called for every potential result. | ||
If function is defined and returns false, the entry is filtered from the result. | ||
#### breakFn | ||
Type: `function`<br> | ||
Default: `undefined` | ||
Takes arguments `key` (dot joined and escaped) and `value` (value for given key) and called for every potential result. | ||
If function is defined and returns true, no nested entries are checked. | ||
#### joined | ||
Type: `boolean`<br> | ||
Default: `true` | ||
Can be set to false to return each key as a list. When dealing with special characters this can be useful. | ||
## Examples | ||
@@ -47,3 +62,3 @@ | ||
<!-- eslint-disable-next-line import/no-unresolved --> | ||
<!-- eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies --> | ||
```js | ||
@@ -78,3 +93,3 @@ const objectScan = require('object-scan'); | ||
// => ["a.b.c", "a.e.f"] | ||
objectScan(["a.*.{c,f}"], () => true, false)(obj); | ||
objectScan(["a.*.{c,f}"], { joined: false })(obj); | ||
// => [["a", "b", "c"], ["a", "e", "f"]] | ||
@@ -97,4 +112,6 @@ | ||
// value function | ||
objectScan(["**"], e => typeof e === "string")(obj); | ||
objectScan(["**"], { filterFn: (key, value) => typeof value === "string" })(obj); | ||
// => ["a.b.c", "a.e.f", "a.h[0]", "a.h[1]", "k"] | ||
objectScan(["**"], { breakFn: key => key === "a.b" })(obj); | ||
// => ["a", "a.b", "a.e", "a.e.f", "a.h", "a.h[0]", "a.h[1]", "k"]); | ||
``` | ||
@@ -101,0 +118,0 @@ |
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
21301
65
120