Installations
npm install balanced-match
Score
99.9
Supply Chain
98.4
Quality
75.8
Maintenance
100
Vulnerability
100
License
Developer
juliangruber
Developer Guide
Module System
ESM
Min. Node Version
>= 16
Typescript Support
No
Node Version
20.3.1
NPM Version
9.6.7
Statistics
125 Stars
113 Commits
40 Forks
7 Watching
1 Branches
15 Contributors
Updated on 01 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
11,139,210,913
Last day
-21.5%
9,502,902
Compared to previous day
Last week
-4.6%
63,943,348
Compared to previous week
Last month
8.5%
270,265,523
Compared to previous month
Last year
14.7%
2,766,027,559
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
balanced-match
Match balanced string pairs, like {
and }
or <b>
and </b>
. Supports regular expressions as well!
Example
Get the first matching pair of braces:
1import balanced from 'balanced-match' 2 3console.log(balanced('{', '}', 'pre{in{nested}}post')) 4console.log(balanced('{', '}', 'pre{first}between{second}post')) 5console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'))
The matches are:
1$ node example.js 2{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' } 3{ start: 3, 4 end: 9, 5 pre: 'pre', 6 body: 'first', 7 post: 'between{second}post' } 8{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
API
const m = balanced(a, b, str)
For the first non-nested matching pair of a
and b
in str
, return an
object with those keys:
- start the index of the first match of
a
- end the index of the matching
b
- pre the preamble,
a
andb
not included - body the match,
a
andb
not included - post the postscript,
a
andb
not included
If there's no match, undefined
will be returned.
If the str
contains more a
than b
/ there are unmatched pairs, the first match that was closed will be used. For example, {{a}
will match ['{', 'a', '']
and {a}}
will match ['', 'a', '}']
.
const r = balanced.range(a, b, str)
For the first non-nested matching pair of a
and b
in str
, return an
array with indexes: [ <a index>, <b index> ]
.
If there's no match, undefined
will be returned.
If the str
contains more a
than b
/ there are unmatched pairs, the first match that was closed will be used. For example, {{a}
will match [ 1, 3 ]
and {a}}
will match [0, 2]
.
Installation
With npm do:
1npm install balanced-match
Security contact information
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
License
(MIT)
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/juliangruber/balanced-match/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/juliangruber/balanced-match/ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 3/19 approved changesets -- score normalized to 1
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
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Score
3.4
/10
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