Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kevlened/honnold
:mount_fuji: Quickly traverse large js objects without the weight
https://github.com/kevlened/honnold
recursive traversal tree walk
Last synced: about 1 month ago
JSON representation
:mount_fuji: Quickly traverse large js objects without the weight
- Host: GitHub
- URL: https://github.com/kevlened/honnold
- Owner: kevlened
- License: mit
- Created: 2019-09-06T14:51:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-10-01T16:23:30.000Z (about 2 years ago)
- Last Synced: 2024-10-30T13:23:59.679Z (about 2 months ago)
- Topics: recursive, traversal, tree, walk
- Language: JavaScript
- Homepage:
- Size: 74.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# honnold
Quickly traverse large js objects without the weight# Usage
```javascript
const honnold = require('honnold');const obj = {
some: {
deeply: {
nested: {
object: {
prop1: true,
prop2: 'hi'
}
}
}
}
};// Basic traversal
honnold(obj, {onLeaf: leaf => console.log(leaf)});
// > true
// > hi// Remove all leaves with a specific value
honnold(obj, {onLeaf: (leaf, {remove}) => {
if (leaf === 'hi') remove();
}});// Remove all leaves with a specific key
honnold(obj, {onLeaf: (leaf, {remove, key}) => {
if (key === 'prop2') remove();
}});// Replace all leaves with a specific value
honnold(obj, {onLeaf: (leaf, {replace}) => {
if (leaf === 'hi') replace('bye');
}});// Remove all leaves beyond a specific depth
honnold(obj, {onLeaf: (leaf, {remove, keys}) => {
if (keys.length > 4) remove();
}});// Loop through all internal nodes
honnold(obj, {onInternalNode: node => console.log(node)});
```## Why?
I thought the existing traversal libraries were bloated, slow, and difficult to use. Through benchmarking, I've learned the existing libraries (namely `tree-crawl`) are pretty fast, but `honnold` is still useful if size is important or you want a simpler interface.
## Stats
* honnold [![bundlephobia](https://img.shields.io/bundlephobia/minzip/honnold.svg)](https://bundlephobia.com/result?p=honnold)
* [traverse](https://github.com/substack/js-traverse) [![bundlephobia](https://img.shields.io/bundlephobia/minzip/traverse.svg)](https://bundlephobia.com/result?p=traverse)
* [tree-crawl](https://github.com/ngryman/tree-crawl) [![bundlephobia](https://img.shields.io/bundlephobia/minzip/tree-crawl.svg)](https://bundlephobia.com/result?p=tree-crawl)```
Leaf traverse (100 wide x 20 deep):honnold x 1,495 ops/sec ±1.33% (90 runs sampled)
traverse x 591 ops/sec ±3.59% (87 runs sampled)
tree-crawl x 2,108 ops/sec ±0.78% (91 runs sampled)Fastest is tree-crawl
Leaf with keys traverse (100 wide x 20 deep):
honnold x 831 ops/sec ±2.19% (89 runs sampled)
traverse x 559 ops/sec ±1.25% (92 runs sampled)
tree-crawl - N/A:Fastest is honnold
Leaf with depth traverse (100 wide x 20 deep):
honnold x 868 ops/sec ±2.10% (91 runs sampled)
traverse x 558 ops/sec ±2.59% (90 runs sampled)
tree-crawl x 2,087 ops/sec ±0.59% (94 runs sampled)Fastest is tree-crawl
Internal node traverse (100 wide x 20 deep):
honnold x 1,434 ops/sec ±2.57% (94 runs sampled)
traverse x 565 ops/sec ±0.43% (93 runs sampled)
tree-crawl x 2,044 ops/sec ±1.75% (93 runs sampled)Fastest is tree-crawl
```## License
MIT