Gathering detailed insights and metrics for dfa
Gathering detailed insights and metrics for dfa
Gathering detailed insights and metrics for dfa
Gathering detailed insights and metrics for dfa
npm install dfa
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
61 Stars
16 Commits
10 Forks
7 Watching
1 Branches
2 Contributors
Updated on 02 Oct 2024
JavaScript (97.77%)
Makefile (2.23%)
Cumulative downloads
Total Downloads
Last day
-4.6%
350,707
Compared to previous day
Last week
1.4%
1,961,727
Compared to previous week
Last month
5.4%
8,322,214
Compared to previous month
Last year
28.2%
89,010,747
Compared to previous year
Compiles a regular expression like syntax to fast deterministic finite automata. Useful for pattern matching against non-string sequences.
This example matches Hangul syllables. The symbols defined in the machine are Unicode character categories which could be mapped from code points.
Machine definition:
1# define symbols 2X = 0; # Other character 3L = 1; # Leading consonant 4V = 2; # Medial vowel 5T = 3; # Trailing consonant 6LV = 4; # Composed <LV> syllable 7LVT = 5; # Composed <LVT> syllable 8M = 6; # Tone mark 9 10# define variables 11decomposed = L V T?; 12partial = LV T?; 13composed = LVT; 14 15# define main state machine pattern 16main = (decomposed | partial | composed) M?;
Visualized, the machine looks like this (double circles are accepting states):
Compiling and using the machine:
1import compile from 'dfa/compile'; 2import fs from 'fs'; 3 4let stateMachine = compile(fs.readFileSync('hangul.machine', 'utf8')); 5 6// find matches 7for (let [startIndex, endIndex] of stateMachine.match([0, 1, 2, 3, 0, 4, 6]) { 8 console.log('match:', startIndex, endIndex); 9}
Output:
match: 1 3
match: 5 6
A state machine file contains a list of assignment statements. Comments are also allowed
and are started with the #
character. Each statement is an assignment of a variable name
to a value or expression. Assigning a variable to a number produces a symbol, which is
added to the state machine's alphabet. Assigning a variable to an expression allows
for substitutions into later expressions. The special main
variable should always be
assigned to at the end of the file, and is the final expression that will be compiled.
A subset of common regular expression syntax is supported. A list of operators and their precedence is below. Operators with the same precedence are evaluated left to right.
Precedence | Syntax | Type | Meaning |
---|---|---|---|
1 | a | b | Alternation | Matches either a or b |
2 | a b | Concatenation | Matches a followed by b |
3 | a* | Repetition | Matches zero or more occurrences of a |
3 | a+ | Repetition | Matches one ore more occurrences of a |
3 | a? | Optional | Matches zero or one occurrence of a |
3 | a{n} | Repetition | Matches exactly n occurrences of a |
3 | a{n,} | Repetition | Matches n or more occurrences of a |
3 | a{,n} | Repetition | Matches up to n occurrences of a |
3 | a{n,m} | Repetition | Matches n to m occurrences of a |
4 | t:<expr> | Tag | Tags the following expression with tag t |
5 | (<expr>) | Grouping | Groups an expression |
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/15 approved changesets -- 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
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
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