ngryman / tree-crawl Goto Github PK
View Code? Open in Web Editor NEW:leaves: Agnostic tree traversal library.
License: MIT License
:leaves: Agnostic tree traversal library.
License: MIT License
Hey, this package does exactly what I need!
I'm using TypeScript, and although I can import JS directly, I'd like to have proper types for IntelliSense and stuff.
I'm happy to write the types myself. Would you be willing to integrate them into the repo? It's just an index.d.ts
file in the root folder.
There're two alternatives: a file in the repo or a separate package @types/tree-crawl
with that file if you don't want to officially support it.
I have a tree that sometime has a args
property and sometimes has a content
property. Is a way to set getChildren
to more than one condition?
crawl(tree, n => console.log(n.type, n.value || n.op), {
getChildren: node => node.args || node.content
});
I want to get the path to a leaf inside the tree. Do you have any recommended way to do this?
Similar to this method https://github.com/joaonuno/tree-model-js#get-the-node-path
Thanks for your work on this, great library ๐
Hello, How can I get string path to node ?
like 'children[3].rows[0]' etc
Thx
I am trying this, but does not work:
const tree = [5, 8, -3, 10]
crawl(tree, (node, context) => {
if (node.valueOf() > 6) {
console.log('TEST WORKS')
}
})
How should it be done?
I am trying to update the top level element and getting the below error as it is not the children of any element.
Uncaught TypeError: Cannot read property 'children' of undefined
The code i written is
const idToSearch = 1;
const updatedValue = 'updated value';
crawl(records, (node, context) => {
if (idToSearch.id === node.id) {
const updatedNode = node;
updatedNode.name = updatedValue;
context.parent.children[context.index] = updatedNode; // eslint-disable-line no-param-reassign,max-len
context.replace(node);
}
});
I have a case in which I would like to arbitrarily suspend and later resume the iteration. I have a large tree structure, traversing through which would take a very long time and I would like to do it in 16 ms time slices to not block the UI and give live preview of the effect of traversal.
You can see my project here: https://github.com/mcalus3/open-fraksl (tree-crawl is used for rendering fractal elements, number of which multiplies with every depth level, that's why there is so much of them).
It would be helpful if you guide me, show where to add such a function and I would like to add it myself, as a pull request :)
I would like to use tree-crawl as an ES6 Module.
So far I have failed to build it โ just changing the output format to 'es'
does lead to a build error.
This package does not work in Node.js without an ESM bundling tool like Rollup or Webpack.
The main
field of package.json
points to a non-existent dist/tree-crawl.node.js
file. See here.
Node then falls back to index.js
which has ESM import
statements, which causes a crash.
I am getting 'GulpUglifyError: unable to minify JavaScript' when gulp is trying to minify tree-crawl. It may be happening because of the files in dist folder are in es6 and gulp uglify accepts es5 code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.