Gathering detailed insights and metrics for @textlint/regexp-string-matcher
Gathering detailed insights and metrics for @textlint/regexp-string-matcher
Gathering detailed insights and metrics for @textlint/regexp-string-matcher
Gathering detailed insights and metrics for @textlint/regexp-string-matcher
npm install @textlint/regexp-string-matcher
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
8 Stars
37 Commits
3 Watching
1 Branches
9 Contributors
Updated on 28 Jun 2022
TypeScript (99.45%)
Shell (0.55%)
Cumulative downloads
Total Downloads
Last day
-2.5%
13,741
Compared to previous day
Last week
2.6%
77,962
Compared to previous week
Last month
1.1%
331,007
Compared to previous month
Last year
38.3%
3,295,543
Compared to previous year
Regexp-like string matcher library.
Install with npm:
npm install @textlint/regexp-string-matcher
Interface:
1export interface matchPatternResult { 2 match: string; 3 startIndex: number; 4 endIndex: number; 5} 6/** 7 * Match regExpLikeStrings and return matchPatternResults 8 * @param text target text 9 * @param regExpLikeStrings an array of pattern string 10 */ 11export declare const matchPatterns: (text: string, regExpLikeStrings: string[]) => matchPatternResult[];
Example:
1import { matchPatterns } from "@textlint/regexp-string-matcher"; 2const inputText = ` 3GitHub is a web-based hosting service for version control using git. 4It is mostly used for computer code. 5GitHub launched in 2018-04-10.`; 6// RegExp like strings 7const inputPatterns = [ 8 "git", // => /git/g 9 "/github/i", // => /github/ig 10 "/(\\d{4})-(\\d{2})-(\\d{2})/" // => /\d{4}-\d{2}-\d{2}/g 11]; 12 13const results = matchPatterns(inputText, inputPatterns); 14assert.deepStrictEqual(results, [ 15 { match: "GitHub", startIndex: 1, endIndex: 7, captures: [] }, 16 { match: "git", startIndex: 65, endIndex: 68, captures: [] }, 17 { match: "GitHub", startIndex: 107, endIndex: 113, captures: [] }, 18 { match: "2018-04-10", startIndex: 126, endIndex: 136, captures: ["2018", "04", "10"] } 19]);
This library aim to represent RegExp in JSON and use it for ignoring words.
g
(global) flag and u
(unicode) is added by default.
Input | Ouput | Note |
---|---|---|
"str" | /str/gu | convert string to regexp with global |
"/str/" | /str/gu | |
"/str/g" | /str/gu | Duplicated g is just ignored |
"/str/i" | /str/igu | |
"/str/u" | /str/ug | |
"/str/m" | /str/mgu | |
"/str/y" | /str/ygu | |
--- | --- | --- |
"/\\d+/" | /\d+/gu | You should escape meta character like \d |
"/(\\d+)/" | /\d+/gu | You can use capture |
:warning: You should escape meta character like \d
in RegExp-like string.
For example, If you want to write \w
(any word) in RegExp-like string, you should escape \w
to \\w
.
Text:
This is a pen.
RegExp-like String:
1[ 2 "/a (\\w+)/" 3]
Results:
[ { match: 'a pen', startIndex: 8, endIndex: 13, captures: ["pen"] } ]
text:
1GitHub is a web-based hosting service for version control using git. 2It is mostly used for computer code. 3GitHub launched in 2018-04-10.
pattern:
1[ 2 "GitHub" 3]
results: 2 hits
1**GitHub** is a web-based hosting service for version control using git. 2It is mostly used for computer code. 3**GitHub** launched in 2018-04-10.
text:
1GitHub is a web-based hosting service for version control using git. 2It is mostly used for computer code. 3GitHub launched in 2018-04-10.
pattern:
1[ 2 "/git/i" 3]
results:: 3 hits
1**Git**Hub is a web-based hosting service for version control using **git**. 2It is mostly used for computer code. 3**Git**Hub launched in 2018-04-10.
You should escape special charactor like \d
in RegExp-like string.
text:
1GitHub is a web-based hosting service for version control using git. 2It is mostly used for computer code. 3GitHub launched in 2018-04-10.
pattern:
1[ 2 "/\\d{4}-\\d{2}-\\d{2}/" 3]
results:: 1 hit
1GitHub is a web-based hosting service for version control using git. 2It is mostly used for computer code. 3GitHub launched in **2018-04-10**.
text:
1===START=== 21st inline text. 3===END=== 4 5===START=== 62nd inline text. 7===END===
pattern:
1[ 2 "/===START===[\\s\\S]*?===END===/m" 3] 4
results:: 2 hits
1**===START=== 21st inline text. 3===END===** 4 5**===START=== 62nd inline text. 7===END===**
For more details, see test/snapshots
text:
1TODO [Issue #1]: it will be fixed
patterns:
1[ 2 "/TODO \\[Issue #\\d+\\]:/i" 3]
:memo: You should escape bracket both. \\[
and \\]
,
results:
**TODO [Issue #1]:** it will be fixed
See Releases page.
Install devDependencies and Run npm test
:
npm i -d && npm test
./snapshots/<name>/
input.txt
and input-patterns.json
npm run test:updateSnapshot
npm test
and pass itPull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © azu
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
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-18
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