
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
object-scan
Advanced tools
Find keys in object hierarchies using wildcard matching and callbacks.
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 for that key.parents
is an array containing all parents as [parent, grandparent, ...]
. Excludes arrays if useArraySelector
is false.isMatch
is true if exactly matched by at least one needle.matchedBy
are all needles matching the key exactly.traversedBy
are all needles involved in traversing the key.Type: function
Default: undefined
If function is defined, it is called for every exact match. If false
is returned, the current key is excluded from the result.
Can be used as a callback function to do processing as matching keys are traversed.
Called in same order as matches would appear in result.
This method is conceptually similar to the callback function in Array.filter().
Type: function
Default: undefined
If function is defined, it is called for every key that is traversed by
the search. If true
is returned, all keys nested under the current key are
skipped in the search and from the final result.
Note that breakFn
is called before the corresponding filterFn
might be called.
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.
Setting this to false
improves performance.
Note that _.get and _.set fully support lists.
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 should be used in any needles and arrays are automatically traversed.
Note that the results still include the array selectors.
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, it might be desirable to set the joined
option to false
.
Conceptually this package works as follows:
During initialization the needles are parsed and built into a search tree. Various information is pre-computed and stored for every node. Finally the search function is returned.
When the search function is called, the input is traversed simultaneously with the relevant nodes of the search tree. Processing multiple search tree branches in parallel allows for a single traversal of the input.
Having a separate initialization stage allows for a performant search and significant speed ups when applying the same search to different input.
FAQs
Traverse object hierarchies using matching and callbacks.
The npm package object-scan receives a total of 32,202 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.