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

balanced-match

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

balanced-match - npm Package Compare versions

Comparing version

to
0.4.0

8

index.js
module.exports = balanced;
function balanced(a, b, str) {
if (a instanceof RegExp) a = maybeMatch(a, str);
if (b instanceof RegExp) b = maybeMatch(b, str);
var r = range(a, b, str);

@@ -14,2 +17,7 @@

function maybeMatch(reg, str) {
var m = str.match(reg);
return m ? m[0] : null;
}
balanced.range = range;

@@ -16,0 +24,0 @@ function range(a, b, str) {

4

package.json
{
"name": "balanced-match",
"description": "Match balanced character pairs, like \"{\" and \"}\"",
"version": "0.3.0",
"version": "0.4.0",
"repository": {

@@ -16,3 +16,3 @@ "type": "git",

"devDependencies": {
"tape": "~4.2.2"
"tape": "~4.5.0"
},

@@ -19,0 +19,0 @@ "keywords": [

# balanced-match
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`.
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!

@@ -19,2 +19,3 @@ [![build status](https://secure.travis-ci.org/juliangruber/balanced-match.svg)](http://travis-ci.org/juliangruber/balanced-match)

console.log(balanced('{', '}', 'pre{first}between{second}post'));
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
```

@@ -32,2 +33,3 @@

post: 'between{second}post' }
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
```

@@ -34,0 +36,0 @@

@@ -83,3 +83,11 @@ var test = require('tape');

});
t.notOk(balanced(/\{/, /\}/, 'nope'), 'should be notOk');
t.deepEqual(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'), {
start: 3,
end: 17,
pre: 'pre',
body: 'in{nest}',
post: 'post'
});
t.end();
});