![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
object-scan
Advanced tools
Find Keys using Wildcard matching and optional value function.
Install with npm:
$ npm install --save object-scan
const objectScan = require('object-scan');
objectScan(['a.*.f'])({ a: { b: { c: 'd' }, e: { f: 'g' } } });
// => [ 'a.e.f' ]
key.path
and [1]
*
and [*]
mark*
or [1*]
**
{a,b}
and [{0,1}]
Note on Functions: Signature for all functions is Fn(key, value, { parents, isMatch, matchedBy, traversedBy })
, where:
key
is the key that the function is called for (respects joined
option).value
is the value of that key.parents
is an array containing all parents as [parent, grandparent, ...]
. Contains parents that are arrays only iff useArraySelector
is true.isMatch
is true if exactly matched by at least one key. Indicates valid (intermittent) result.matchedBy
are all needles matching the key exactly.traversedBy
are all needles involved in traversing the keyType: function
Default: undefined
Called for every exact match. Iff function is defined and returns false, the entry is excluded from the final result.
This method is conceptually similar to Array.filter().
Type: function
Default: undefined
Called for every final result.
Type: function
Default: undefined
Called for every key that could be (part of) a matching key. If function is defined and returns true, all nested entries under the current key are excluded from search and from the final result.
Type: boolean
Default: true
Can be set to false to return each key as a list. When dealing with special characters this can be useful.
Important: Setting this to false
improves performance.
Type: boolean
Default: true
When set to false, joined paths for functions and the final result are not escaped.
Type: boolean
Default: true
When set to false no array selectors are used and arrays are automatically traversed.
More extensive examples can be found in the tests.
const objectScan = require('object-scan');
const obj = {
a: {
b: {
c: 'd'
},
e: {
f: 'g'
},
h: ['i', 'j']
},
k: 'l'
};
// top level keys
objectScan(['*'])(obj);
// => ["k", "a"]
// nested keys
objectScan(['a.*.f'])(obj);
// => ["a.e.f"]
objectScan(['*.*.*'])(obj);
// => ["a.e.f", "a.b.c"]
// or filter
objectScan(['a.*.{c,f}'])(obj);
// => ["a.e.f", "a.b.c"]
objectScan(['a.*.{c,f}'], { joined: false })(obj);
// => [["a", "e", "f"], ["a", "b", "c"]]
// list filter
objectScan(['*.*[*]'])(obj);
// => ["a.h[1]", "a.h[0]"]
objectScan(['*[*]'])(obj);
// => []
// deep star filter
objectScan(['**'])(obj);
// => ["k", "a.h[1]", "a.h[0]", "a.h", "a.e.f", "a.e", "a.b.c", "a.b", "a"]
objectScan(['**.f'])(obj);
// => ["a.e.f"]
objectScan(['**[*]'])(obj);
// => ["a.h[1]", "a.h[0]"]
// value function
objectScan(['**'], { filterFn: (key, value) => typeof value === 'string' })(obj);
// => ["k", "a.h[1]", "a.h[0]", "a.e.f", "a.b.c"]
objectScan(['**'], { breakFn: key => key === 'a.b' })(obj);
// => ["k", "a.h[1]", "a.h[0]", "a.h", "a.e.f", "a.e", "a.b", "a"]
The top level object(s) are matched by the empty needle ""
. Useful for matching objects nested in arrays by setting useArraySelector
to false
. Note that the empty string does not work with _.get and _.set.
The following Characters are considered special and need to
be escaped if they should be matched in a key: [
, ]
, {
, }
, ,
, .
and *
.
When dealing with special characters the joined
option might be desirable to set to false
.
FAQs
Traverse object hierarchies using matching and callbacks.
The npm package object-scan receives a total of 20,577 weekly downloads. As such, object-scan popularity was classified as popular.
We found that object-scan demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.