Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the example in readme to prevent "location" field displays wrong way when running as script with Node.js. (nested displayed as [Array]) #185

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ console.log(dependenciesName);
console.log(inTryDeps);
console.log(warnings);
fraxken marked this conversation as resolved.
Show resolved Hide resolved
```
---

If you meant to run this example with Node.js quickly in terminal, use this example below to correctly display the ``location`` field.
```js
import { runASTAnalysis } from "@nodesecure/js-x-ray";
import { readFileSync } from "fs";

const str = readFileSync("./file.js", "utf-8");
const { warnings, dependencies } = runASTAnalysis(str);

const dependenciesName = [...dependencies];
const inTryDeps = [...dependencies.getDependenciesInTryStatement()];

console.log(dependenciesName);
console.log(inTryDeps);
console.log(JSON.stringify(warnings, null, 2));
```
save content above to a ``.mjs`` file and run it with this command in your terminal``
node ./example_filename.mjs``

---

The analysis will return: `http` (in try), `crypto`, `util` and `fs`.

Expand Down