balanced-match 2.0.0 → 3.0.0

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.
package/README.md CHANGED
@@ -2,17 +2,15 @@
2
2
 
3
3
  Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
4
4
 
5
- [![build status](https://secure.travis-ci.org/juliangruber/balanced-match.svg)](http://travis-ci.org/juliangruber/balanced-match)
5
+ [![CI](https://github.com/juliangruber/balanced-match/actions/workflows/ci.yml/badge.svg)](https://github.com/juliangruber/balanced-match/actions/workflows/ci.yml)
6
6
  [![downloads](https://img.shields.io/npm/dm/balanced-match.svg)](https://www.npmjs.org/package/balanced-match)
7
7
 
8
- [![testling badge](https://ci.testling.com/juliangruber/balanced-match.png)](https://ci.testling.com/juliangruber/balanced-match)
9
-
10
8
  ## Example
11
9
 
12
10
  Get the first matching pair of braces:
13
11
 
14
12
  ```js
15
- var balanced = require('balanced-match')
13
+ import balanced from 'balanced-match'
16
14
 
17
15
  console.log(balanced('{', '}', 'pre{in{nested}}post'))
18
16
  console.log(balanced('{', '}', 'pre{first}between{second}post'))
@@ -34,7 +32,7 @@ $ node example.js
34
32
 
35
33
  ## API
36
34
 
37
- ### var m = balanced(a, b, str)
35
+ ### const m = balanced(a, b, str)
38
36
 
39
37
  For the first non-nested matching pair of `a` and `b` in `str`, return an
40
38
  object with those keys:
@@ -49,7 +47,7 @@ If there's no match, `undefined` will be returned.
49
47
 
50
48
  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
49
 
52
- ### var r = balanced.range(a, b, str)
50
+ ### const r = balanced.range(a, b, str)
53
51
 
54
52
  For the first non-nested matching pair of `a` and `b` in `str`, return an
55
53
  array with indexes: `[ <a index>, <b index> ]`.
package/index.js CHANGED
@@ -1,6 +1,9 @@
1
- 'use strict'
2
- module.exports = balanced
3
- function balanced (a, b, str) {
1
+ /**
2
+ * @param {string | RegExp} a
3
+ * @param {string | RegExp} b
4
+ * @param {string} str
5
+ */
6
+ export default function balanced (a, b, str) {
4
7
  if (a instanceof RegExp) a = maybeMatch(a, str)
5
8
  if (b instanceof RegExp) b = maybeMatch(b, str)
6
9
 
@@ -17,13 +20,21 @@ function balanced (a, b, str) {
17
20
  )
18
21
  }
19
22
 
23
+ /**
24
+ * @param {RegExp} reg
25
+ * @param {string} str
26
+ */
20
27
  function maybeMatch (reg, str) {
21
28
  const m = str.match(reg)
22
29
  return m ? m[0] : null
23
30
  }
24
31
 
25
- balanced.range = range
26
- function range (a, b, str) {
32
+ /**
33
+ * @param {string} a
34
+ * @param {string} b
35
+ * @param {string} str
36
+ */
37
+ export function range (a, b, str) {
27
38
  let begs, beg, left, right, result
28
39
  let ai = str.indexOf(a)
29
40
  let bi = str.indexOf(b, ai + 1)
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "balanced-match",
3
3
  "description": "Match balanced character pairs, like \"{\" and \"}\"",
4
- "version": "2.0.0",
4
+ "version": "3.0.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git://github.com/juliangruber/balanced-match.git"
8
8
  },
9
9
  "homepage": "https://github.com/juliangruber/balanced-match",
10
10
  "main": "index.js",
11
+ "type": "module",
11
12
  "scripts": {
12
- "test": "prettier-standard && standard && tape test/test.js",
13
+ "test": "standard --fix && node--test test/test.js",
13
14
  "bench": "matcha test/bench.js",
14
15
  "release": "np"
15
16
  },
16
17
  "devDependencies": {
17
18
  "@c4312/matcha": "^1.3.1",
18
- "np": "^7.4.0",
19
- "prettier-standard": "^16.4.1",
20
- "standard": "^16.0.3",
21
- "tape": "^4.6.0"
19
+ "np": "^8.0.4",
20
+ "standard": "^17.1.0",
21
+ "test": "^3.3.0"
22
22
  },
23
23
  "keywords": [
24
24
  "match",
@@ -48,5 +48,8 @@
48
48
  "iphone/6.0..latest",
49
49
  "android-browser/4.2..latest"
50
50
  ]
51
+ },
52
+ "engines": {
53
+ "node": ">= 16"
51
54
  }
52
55
  }
@@ -1,2 +0,0 @@
1
- tidelift: 'npm/balanced-match'
2
- patreon: juliangruber