🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

code-path-graph

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons

code-path-graph

0.0.0
unpublished
Source
npm
Version published
Weekly downloads
1
-80%
Maintainers
1
Weekly downloads
 
Created
Source

= +code-path-graph+

A library and command-line tool to create https://mermaid.js.org/syntax/stateDiagram.html[Mermaid state diagrams] of code paths in JavaScript files.

The diagrams are generated using the https://eslint.org/docs/latest/extend/code-path-analysis[code path analysis] functionality of ESLint can be embedded in GitHub markdown using fenced code blocks (i.e. pass:[```mermaid]pass:[```]).

== Usage

[source,console] code-path-graph [--detail=<...>] [--ecma-version=<...>] [--source-type=<...>]

detail controls the information printed in nodes of the graph. Valid values are:

+nodes+:: Print node traversal info only (default) +segments+:: Print segment names only +full+:: Print both segment names and node traversal info

+ecmaVersion+ specifies the JavaScript language version. Valid values are numbers or the string +latest+ (default).

+sourceType+ specifies the type of JavaScript code. Valid valus are:

+script+:: Script (default for ecmaVersion 3 or 5) +module+:: ECMAScript module (default for other values of ecmaVersion) +commonjs+:: CommonJS module

== Example

Given is a JavaScript file test.js with the following content: [source,js]

if (foo) { throw bar(); }

Running the command [source,console] npx code-graph-path test.js

produces the following output:

title: s1

stateDiagram-v2 classDef common fill: white, stroke: black, text-align: center classDef unreachable fill: #FF9800, stroke-dasharray: 5 5 classDef thrown fill: none, line-height: 1, stroke: none s1_1::: common: Program#58;enter\nIfStatement#58;enter\nIdentifier (foo) s1_2::: common: BlockStatement#58;enter\nThrowStatement#58;enter\nCallExpression#58;enter\nIdentifier (bar)\nCallExpression#58;exit\nThrowStatement#58;exit s1_4::: common: IfStatement#58;exit\nProgram#58;exit s1_3:::common: #60;#60;unreachable#62;#62;\nBlockStatement#58;exit s1_3:::unreachable thrown:::thrown: ✘ [] --> s1_1 s1_1 --> s1_2 s1_1 --> s1_4 s1_2 --> s1_3 s1_3 --> s1_4 s1_4 --> [] s1_2 --> thrown

This text can be inserted in a fenced code block (see below)

---
title: s1
---
stateDiagram-v2
classDef common fill: white, stroke: black, text-align: center
classDef unreachable fill: #FF9800, stroke-dasharray: 5 5
classDef thrown fill: none, line-height: 1, stroke: none
s1_1::: common: Program#58;enter\nIfStatement#58;enter\nIdentifier (foo)
s1_2::: common: BlockStatement#58;enter\nThrowStatement#58;enter\nCallExpression#58;enter\nIdentifier (bar)\nCallExpression#58;exit\nThrowStatement#58;exit
s1_4::: common: IfStatement#58;exit\nProgram#58;exit
s1_3:::common: #60;#60;unreachable#62;#62;\nBlockStatement#58;exit
s1_3:::unreachable
thrown:::thrown: ✘
[*] --> s1_1
s1_1 --> s1_2
s1_1 --> s1_4
s1_2 --> s1_3
s1_3 --> s1_4
s1_4 --> [*]
s1_2 --> thrown

to produce a visible diagram like the following.

---
title: s1
---
stateDiagram-v2
classDef common fill: white, stroke: black, text-align: center
classDef unreachable fill: #FF9800, stroke-dasharray: 5 5
classDef thrown fill: none, line-height: 1, stroke: none
s1_1::: common: Program#58;enter\nIfStatement#58;enter\nIdentifier (foo)
s1_2::: common: BlockStatement#58;enter\nThrowStatement#58;enter\nCallExpression#58;enter\nIdentifier (bar)\nCallExpression#58;exit\nThrowStatement#58;exit
s1_4::: common: IfStatement#58;exit\nProgram#58;exit
s1_3:::common: #60;#60;unreachable#62;#62;\nBlockStatement#58;exit
s1_3:::unreachable
thrown:::thrown: ✘
[*] --> s1_1
s1_1 --> s1_2
s1_1 --> s1_4
s1_2 --> s1_3
s1_3 --> s1_4
s1_4 --> [*]
s1_2 --> thrown

FAQs

Package last updated on 14 Sep 2023

Did you know?

Socket

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.

Install

Related posts