ast-monkey-traverse
Advanced tools
Comparing version 1.12.17 to 1.12.18
/** | ||
* ast-monkey-traverse | ||
* Utility library to traverse AST | ||
* Version: 1.12.17 | ||
* Version: 1.12.18 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -6,0 +6,0 @@ * License: MIT |
/** | ||
* ast-monkey-traverse | ||
* Utility library to traverse AST | ||
* Version: 1.12.17 | ||
* Version: 1.12.18 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -85,7 +85,7 @@ * License: MIT | ||
return module = { | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); | ||
} | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); | ||
} | ||
}, fn(module, module.exports), module.exports; | ||
@@ -92,0 +92,0 @@ } |
/** | ||
* ast-monkey-traverse | ||
* Utility library to traverse AST | ||
* Version: 1.12.17 | ||
* Version: 1.12.18 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -6,0 +6,0 @@ * License: MIT |
/** | ||
* ast-monkey-traverse | ||
* Utility library to traverse AST | ||
* Version: 1.12.17 | ||
* Version: 1.12.18 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -6,0 +6,0 @@ * License: MIT |
{ | ||
"name": "ast-monkey-traverse", | ||
"version": "1.12.17", | ||
"version": "1.12.18", | ||
"description": "Utility library to traverse AST", | ||
"license": "MIT", | ||
"repository": "https://gitlab.com/codsen/codsen/", | ||
"homepage": "https://codsen.com/os/ast-monkey-traverse/", | ||
"author": { | ||
"email": "roy@codsen.com", | ||
"name": "Roy Revelt", | ||
"url": "codsen.com" | ||
}, | ||
"keywords": [ | ||
@@ -36,2 +28,10 @@ "ast", | ||
], | ||
"homepage": "https://codsen.com/os/ast-monkey-traverse/", | ||
"repository": "https://gitlab.com/codsen/codsen/", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Roy Revelt", | ||
"email": "roy@codsen.com", | ||
"url": "codsen.com" | ||
}, | ||
"main": "dist/ast-monkey-traverse.cjs.js", | ||
@@ -55,3 +55,4 @@ "module": "dist/ast-monkey-traverse.esm.js", | ||
"pretest": "npm run build", | ||
"test": "npm run lint && npm run unittest && npm run clean_cov && npm run format", | ||
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format", | ||
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier", | ||
"tsd": "tsd", | ||
@@ -66,2 +67,13 @@ "unittest": "./node_modules/.bin/tap --no-only --output-file=testStats.md && npm run clean_cov && npm run perf", | ||
}, | ||
"tap": { | ||
"coverage-report": [ | ||
"json-summary", | ||
"text" | ||
], | ||
"nyc-arg": [ | ||
"--exclude=**/*.cjs.js", | ||
"--exclude=**/*.umd.js" | ||
], | ||
"timeout": 0 | ||
}, | ||
"lect": { | ||
@@ -96,3 +108,2 @@ "defaultExported": true, | ||
"req": "traverse", | ||
"typeSriptDefinitions": false, | ||
"various": { | ||
@@ -105,13 +116,2 @@ "devDependencies": [ | ||
}, | ||
"tap": { | ||
"coverage-report": [ | ||
"json-summary", | ||
"text" | ||
], | ||
"nyc-arg": [ | ||
"--exclude=**/*.cjs.js", | ||
"--exclude=**/*.umd.js" | ||
], | ||
"timeout": 0 | ||
}, | ||
"dependencies": { | ||
@@ -127,12 +127,12 @@ "lodash.clonedeep": "^4.5.0" | ||
"@babel/preset-env": "^7.11.5", | ||
"@rollup/plugin-babel": "^5.2.0", | ||
"@rollup/plugin-commonjs": "^15.0.0", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-strip": "^2.0.0", | ||
"benchmark": "^2.1.4", | ||
"eslint": "^7.8.1", | ||
"lect": "^0.13.11", | ||
"eslint": "^7.9.0", | ||
"lect": "^0.14.1", | ||
"lodash.isequal": "^4.5.0", | ||
"object-path": "^0.11.4", | ||
"rollup": "^2.26.10", | ||
"rollup": "^2.28.1", | ||
"rollup-plugin-ascii": "^0.0.3", | ||
@@ -139,0 +139,0 @@ "rollup-plugin-banner": "^0.2.1", |
@@ -5,3 +5,20 @@ # ast-monkey-traverse | ||
<img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> | ||
<div class="package-badges"> | ||
<a href="https://www.npmjs.com/package/ast-monkey-traverse" rel="nofollow noreferrer noopener"> | ||
<img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm"> | ||
</a> | ||
<a href="https://codsen.com/os/ast-monkey-traverse" rel="nofollow noreferrer noopener"> | ||
<img src="https://img.shields.io/badge/-Codsen-blue?style=flat-square" alt="page on npm"> | ||
</a> | ||
<a href="https://gitlab.com/codsen/codsen/tree/master/packages/ast-monkey-traverse" rel="nofollow noreferrer noopener"> | ||
<img src="https://img.shields.io/badge/-GitLab-blue?style=flat-square" alt="page on GitLab"> | ||
</a> | ||
<a href="https://npmcharts.com/compare/ast-monkey-traverse?interval=30" rel="nofollow noreferrer noopener" target="_blank"> | ||
<img src="https://img.shields.io/npm/dm/ast-monkey-traverse.svg?style=flat-square" alt="Downloads per month"> | ||
</a> | ||
<a href="https://prettier.io" rel="nofollow noreferrer noopener" target="_blank"> | ||
<img src="https://img.shields.io/badge/code_style-prettier-brightgreen.svg?style=flat-square" alt="Code style: prettier"> | ||
</a> | ||
<img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT License"> | ||
</div> | ||
@@ -14,10 +31,50 @@ ## Install | ||
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> | ||
## Quick Take | ||
```js | ||
import { strict as assert } from "assert"; | ||
import traverse from "ast-monkey-traverse"; | ||
const paths = []; | ||
const source = { | ||
a: { | ||
foo: { | ||
bar: [ | ||
{ | ||
foo: "c", | ||
}, | ||
], | ||
d: { | ||
e: { | ||
foo: "f", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
traverse(source, (key, val, innerObj) => { | ||
// if currently an object is traversed, you get both "key" and "val" | ||
// if it's array, only "key" is present, "val" is undefined | ||
const current = val !== undefined ? val : key; | ||
if ( | ||
// it's object (not array) | ||
val !== undefined && | ||
// and has the key we need | ||
key === "foo" | ||
) { | ||
// push the path to array in the outer scope | ||
paths.push(innerObj.path); | ||
} | ||
return current; | ||
}); | ||
// notice object-path notation "a.foo.bar.0.foo" - array segments use dots too: | ||
assert.deepEqual(paths, ["a.foo", "a.foo.bar.0.foo", "a.foo.d.e.foo"]); | ||
``` | ||
## Documentation | ||
Please [visit our documentation](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API and examples. | ||
Please [visit codsen.com](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API and examples. | ||
<img src="https://codsen.com/images/png-codsen-star.png" width="42" alt="star" align="center"> | ||
## Licence | ||
@@ -29,2 +86,2 @@ | ||
<img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center"> | ||
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center"> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90029
12
2099
85