
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
obj-path-expression-parser
Advanced tools
A path expression is a string that matches a one or more values in an object. This package exposes a generator "expressionParser" that with the given path expression and object, returns paths matching the expression.
Example:
const expressionParser = require('obj-path-expression-parser');
const iter = expressionParser('hello.world', { hello: { world: 1 } });
Array.from(iter); // [['hello', 'world']]
The first argument "hello.world" is the path expression, the second is the object where the match happens. Only paths existing in the corresponding objects are returned!
const iter = expressionParser('hello.world', {});
Array.from(iter); // [] no matches in the object!
A path expression is formed by multiple path "fragments". A fragment is a string that tries to match an attribute:
hello.world
"hello" is a fragment matching the attribute "hello", and "world" matches the attribute "world" of the object inside "hello". Fragments can be separated by dots of wrapped in square brackets. The following is equivalent to "hello.world":
[hello][world]
The difference is that between square brackets, you can use any character you need, including square brackets if escaped with "". You can mix the fragment of the 2 types:
[hello]world
Every fragment can use globbing to match attributes: This matches any item contained in the "hello" or "world" attributes:
[hello|world][*]
The globbing library used is "micromatch". Check out for further details. The library supports escaping using "".
If the target item is an array, you can set a fragment to filter a specific slice of the array. If your object contains:
{ items: ['a', 'b', 'c', 'd'] }
You can specify the beginning and the end of the slice. It behaves in the same way as Array.prototype.slice:
items[:] // every item
Expands to:
items[1:] // every item except the first
Expands to:
items[:2] // from the first to the second
Expands to:
items[:2] // from the first to the second
Expands to:
items[1:-1] // from the first to the one before the last one
Expands to:
You can separate multiple path expressions with a comma:
a.b,x.y
returns the following paths (if they exist in the object):
[ ['a', 'b'], ['x', 'y']]
A nested expression is a path expression wrapped in round parenthesis, that is part of another path expression:
(products,services)items.prices
That expands to:
[
['products', 'items', 'prices'],
['services', 'items', 'prices']
]
Multiple levels of nesting are allowed:
(products.items,services(subscriptions,transactions))prices
That expands to:
[
['products', 'items', 'prices'],
['services', 'subscriptions', 'prices']
['services', 'transactions', 'prices']
]
If you need to perform a more complex filtering you can use a custom fragment. A custom fragment is wrapped in curly braces and calls a custom function with an argument:
numbers[:]{mod 3}
In this case the function is "mod" and the argument is a string "3". You need to pass the custom function to the expressionParser function:
const customFunctions = {
mod: (path, funcArgument, parent) => {
const n = parseInt(funcArgument, 10)
return parent % n === 0 ? [path] : []
}
};
const iter = pathExpressionParser('numbers[:]{mod 3}',
{ numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8] }, customFunctions);
The custom function takes as arguments:
The function should return an iterable with the valid paths.
FAQs
Parser for path expressions
The npm package obj-path-expression-parser receives a total of 38 weekly downloads. As such, obj-path-expression-parser popularity was classified as not popular.
We found that obj-path-expression-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.