balanced-match 0.4.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ tidelift: "npm/balanced-match"
2
+ patreon: juliangruber
package/README.md CHANGED
@@ -47,7 +47,7 @@ object with those keys:
47
47
 
48
48
  If there's no match, `undefined` will be returned.
49
49
 
50
- 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', '']`.
50
+ 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', '}']`.
51
51
 
52
52
  ### var r = balanced.range(a, b, str)
53
53
 
@@ -56,7 +56,7 @@ array with indexes: `[ <a index>, <b index> ]`.
56
56
 
57
57
  If there's no match, `undefined` will be returned.
58
58
 
59
- 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 ]`.
59
+ 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]`.
60
60
 
61
61
  ## Installation
62
62
 
@@ -66,6 +66,12 @@ With [npm](https://npmjs.org) do:
66
66
  npm install balanced-match
67
67
  ```
68
68
 
69
+ ## Security contact information
70
+
71
+ To report a security vulnerability, please use the
72
+ [Tidelift security contact](https://tidelift.com/security).
73
+ Tidelift will coordinate the fix and disclosure.
74
+
69
75
  ## License
70
76
 
71
77
  (MIT)
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ 'use strict';
1
2
  module.exports = balanced;
2
3
  function balanced(a, b, str) {
3
4
  if (a instanceof RegExp) a = maybeMatch(a, str);
@@ -27,10 +28,13 @@ function range(a, b, str) {
27
28
  var i = ai;
28
29
 
29
30
  if (ai >= 0 && bi > 0) {
31
+ if(a===b) {
32
+ return [ai, bi];
33
+ }
30
34
  begs = [];
31
35
  left = str.length;
32
36
 
33
- while (i < str.length && i >= 0 && ! result) {
37
+ while (i >= 0 && !result) {
34
38
  if (i == ai) {
35
39
  begs.push(i);
36
40
  ai = str.indexOf(a, i + 1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "balanced-match",
3
3
  "description": "Match balanced character pairs, like \"{\" and \"}\"",
4
- "version": "0.4.1",
4
+ "version": "1.0.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git://github.com/juliangruber/balanced-match.git"
@@ -9,11 +9,12 @@
9
9
  "homepage": "https://github.com/juliangruber/balanced-match",
10
10
  "main": "index.js",
11
11
  "scripts": {
12
- "test": "make test"
12
+ "test": "tape test/test.js",
13
+ "bench": "matcha test/bench.js"
13
14
  },
14
- "dependencies": {},
15
15
  "devDependencies": {
16
- "tape": "~4.5.0"
16
+ "matcha": "^0.7.0",
17
+ "tape": "^4.6.0"
17
18
  },
18
19
  "keywords": [
19
20
  "match",
package/.npmignore DELETED
@@ -1,5 +0,0 @@
1
- test
2
- .gitignore
3
- .travis.yml
4
- Makefile
5
- example.js