
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
recurserator
Advanced tools
Recurserator is a set of recursive generators for recursively accessing an object.
npm install --save recurserator
import RecursionBuilder from 'recurserator';
You can also use named imports.
import { RecursionBuilder } from 'recurserator';
RecursionBuilder
The RecursionBuilder builds a recursive alogorithm and iterates using that algorithm. Arguments are optional and can be supplied through a building pattern. A RecursionBuilder instance itself is an iterable. RecursionBuilder objects are also immutable.
Param | Type | Description |
---|---|---|
object | Object | The object to recursively access |
options.yieldOn | Function | A function that determines whether a value is yielded |
options.traverseOn | Function | A function that determines whether a value is accessed with recursion |
options.readEntry | Function | A function that extracts the key/value pair from an object. Defaults to the entries method or own enumerable keys for objects |
options.readNext | Function | A function that extracts the next item to iterate over |
import { RecursionBuilder } from 'recurserator';
const data = {
value1: 10,
aList: [{
listKey: 'HI!'
}],
nested: {
anotherNested: {
}
}
};
const builder = RecursionBuilder.create(data);
for (let { key, value, path, parent } of builder) {
//=> ['value1', 10, 'value1', data]
//=> ['aList', [...], 'aList', data]
//=> ['0', {...}, 'aList[0]', data.aList]
//=> ['listKey', 'Hi!', 'aList[0].listKey', data.aList[0]]
//=> ['nested', {...}, 'nested', data]
//=> ['anotherNested', {...}, 'nested.anotherNested', data.nested]
}
// Yield array value but don't access them
const truth = () => true;
const notArray = item => !Array.isArray(item);
for (let { key, value, path, parent } of builder.yieldOn(truth).traverseOn(notArray)) {
//=> ['value1', 10, 'value1', data]
//=> ['aList', [...], 'aList', data]
//=> ['nested', {...}, 'nested', data]
//=> ['anotherNested', {...}, 'nested.anotherNested', data.nested]
}
// Only yield objects
for (let { key, value, path, parent } of builder.yieldOn(isObject)) {
//=> ['aList', [...], 'aList', data]
//=> ['0', {...}, 'aList[0]', data.aList]
//=> ['nested', {...}, 'nested', data]
//=> ['anotherNested', {...}, 'nested.anotherNested', data.nested]
}
RecursionBuilder
Sets the yield filter property. This condition is called to test whether a value should be yielded. Returns a new RecursionBuilder instance.
Param | Type | Description |
---|---|---|
filter | Function | A function that determines whether a value is yielded |
RecursionBuilder
Sets the traverse filter property. This condition is called to test whether a value should be traversed. Returns a new RecursionBuilder instance.
Param | Type | Description |
---|---|---|
filter | Function | A function that determines whether a value is accessed with recursion |
RecursionBuilder
Sets the read next property. When this method is provided, instead of traversing to the next key. This method will be called to determine what the child of the value should be. Returns a new RecursionBuilder instance.
Param | Type | Description |
---|---|---|
readNext | Function | string |
RecursionBuilder
Sets the extractor property. Used to extract key/value pair from an object. Defaults to entries
iterator if it exists.
Returns a new RecursionBuilder instance.
Param | Type | Description |
---|---|---|
readEntry | Function | A function that extracts the key/value pair from an object. Defaults to the entries method or own enumerable keys for objects |
RecursionBuilder
Clones the builder object merging in the new state.
Param | Type | Description |
---|---|---|
newState | RecursionBuilderState | New state to merge in |
RecursionBuilder
Creates a RecursionBuilder.
Param | Type | Description |
---|---|---|
object | Object | The object to recursively access |
options.yieldOn | Function | A function that determines whether a value is yielded |
options.traverseOn | Function | A function that determines whether a value is accessed with recursion |
options.readEntry | Function | A function that extracts the key/value pair from an object. Defaults to the entries method or own enumerable keys for objects |
options.readNext | Function | A function that extracts the next item to iterate over |
Iterable
Runs the recursion algorithm on the provided data object.
Param | Type | Description |
---|---|---|
object | Object | The object to recursively access |
Iterable
Runs the recursion algorithm on the provided data object. Yields only keys. If no object is provided the storage object in the builder will be used.
Param | Type | Description |
---|---|---|
object | Object | The object to recursively access |
Iterable
Runs the recursion algorithm on the provided data object. Yields only values. If no object is provided the storage object in the builder will be used.
Param | Type | Description |
---|---|---|
object | Object | The object to recursively access |
Iterable
Runs the recursion algorithm on the provided data object. Yields only paths. If no object is provided the storage object in the builder will be used.
Param | Type | Description |
---|---|---|
object | Object | The object to recursively access |
Iterable
Runs the recursion algorithm on the provided data object. Yields only parents. If no object is provided the storage object in the builder will be used.
Param | Type | Description |
---|---|---|
object | Object | The object to recursively access |
Iterable
Runs the recursion algorithm on the provided data object. Yields the key from the RecursionResult object. If no object is provided the storage object in the builder will be used.
Param | Type | Description |
---|---|---|
key | string | The key to extract from the result object |
object | Object | The object to recursively access |
FAQs
Handle object recursion like a boss
We found that recurserator 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
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.