Gathering detailed insights and metrics for regexp-to-ast
Gathering detailed insights and metrics for regexp-to-ast
Gathering detailed insights and metrics for regexp-to-ast
Gathering detailed insights and metrics for regexp-to-ast
npm install regexp-to-ast
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
27 Stars
74 Commits
11 Forks
2 Watching
25 Branches
4 Contributors
Updated on 14 May 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-7.3%
199,000
Compared to previous day
Last week
-3.7%
1,039,472
Compared to previous week
Last month
33.5%
4,494,814
Compared to previous month
Last year
24%
43,727,471
Compared to previous year
Reads a JavaScript Regular Expression literal(text) and outputs an Abstract Syntax Tree.
npm install regexp-to-ast
<script src="https://unpkg.com/regexp-to-ast/lib/parser.js"></script>
The API is defined as a TypeScript definition file.
Parsing to an AST:
1const RegExpParser = require("regexp-to-ast").RegExpParser 2const regexpParser = new RegExpParser() 3 4// from a regexp text 5const astOutput = regexpParser.pattern("/a|b|c/g") 6 7// text from regexp instance. 8const input2 = /a|b/.toString() 9// The same parser instance can be reused 10const anotherAstOutput = regexpParser.pattern(input2)
Visiting the AST:
1// parse to an AST as before. 2const { RegExpParser, BaseRegExpVisitor } = require("regexp-to-ast") 3const regexpParser = new RegExpParser() 4const regExpAst = regexpParser.pattern("/a|b|c/g") 5 6// Override the visitor methods to add your logic. 7class MyRegExpVisitor extends BaseRegExpVisitor { 8 visitPattern(node) {} 9 10 visitFlags(node) {} 11 12 visitDisjunction(node) {} 13 14 visitAlternative(node) {} 15 16 // Assertion 17 visitStartAnchor(node) {} 18 19 visitEndAnchor(node) {} 20 21 visitWordBoundary(node) {} 22 23 visitNonWordBoundary(node) {} 24 25 visitLookahead(node) {} 26 27 visitNegativeLookahead(node) {} 28 29 // atoms 30 visitCharacter(node) {} 31 32 visitSet(node) {} 33 34 visitGroup(node) {} 35 36 visitGroupBackReference(node) {} 37 38 visitQuantifier(node) {} 39} 40 41const myVisitor = new MyRegExpVisitor() 42myVisitor.visit(regExpAst) 43// extract visit results from the visitor state.
This library is written in ES5 style and is compatiable with all major browsers and modern node.js versions.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
25 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More