{"name":"balanced-match","version":"4.0.2","keywords":["match","regexp","test","balanced","parse"],"license":"MIT","_id":"balanced-match@4.0.2","maintainers":[{"name":"juliangruber","email":"julian@juliangruber.com"}],"homepage":"https://github.com/juliangruber/balanced-match#readme","bugs":{"url":"https://github.com/juliangruber/balanced-match/issues"},"dist":{"shasum":"241591ea634702bef9c482696f2469406e16d233","tarball":"http://registry-npm.ywwl.com/balanced-match/download/balanced-match-4.0.2.tgz","fileCount":13,"integrity":"sha512-x0K50QvKQ97fdEz2kPehIerj+YTeptKF9hyYkKf6egnwmMWAkADiO0QCzSp0R5xN8FTZgYaBfSaue46Ej62nMg==","signatures":[{"sig":"MEYCIQDE8FHhhr3qG7uHmZW3GGgTn+2Hqe2uLdSYaa8/q0RKogIhAOXMHqoSMA4qe+PPUv89Dkxp+t90LHP1SoPlzCU3KCDV","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":17629,"size":4214,"noattachment":false,"key":"/balanced-match/-/balanced-match-4.0.2.tgz"},"main":"./dist/commonjs/index.js","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":"20 || >=22"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"e0ea70da61430e33ba13a9394e0a3d0122095096","scripts":{"snap":"tap","test":"tap","format":"prettier --write .","prepare":"tshy","presnap":"npm run prepare","pretest":"npm run prepare","typedoc":"typedoc --tsconfig .tshy/esm.json ./src/*.ts","benchmark":"node benchmark/index.js","preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags"},"_npmUser":{"name":"juliangruber","email":"julian@juliangruber.com"},"repository":{"url":"git://github.com/juliangruber/balanced-match.git","type":"git"},"_npmVersion":"10.9.2","description":"Match balanced character pairs, like \"{\" and \"}\"","directories":{},"_nodeVersion":"22.14.0","dependencies":{"jackspeak":"^4.2.3"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^21.1.0","tshy":"^3.0.2","mkdirp":"^3.0.1","typedoc":"^0.28.5","prettier":"^3.3.2","@types/node":"^25.2.1","@types/brace-expansion":"^1.1.2"},"_npmOperationalInternal":{"tmp":"tmp/balanced-match_4.0.2_1770648647330_0.9219850390943709","host":"s3://npm-registry-packages-npm-production"},"readme":"# balanced-match\n\nMatch balanced string pairs, like `{` and `}` or `<b>` and\n`</b>`. Supports regular expressions as well!\n\n## Example\n\nGet the first matching pair of braces:\n\n```js\nimport { balanced } from 'balanced-match'\n\nconsole.log(balanced('{', '}', 'pre{in{nested}}post'))\nconsole.log(balanced('{', '}', 'pre{first}between{second}post'))\nconsole.log(\n  balanced(/\\s+\\{\\s+/, /\\s+\\}\\s+/, 'pre  {   in{nest}   }  post'),\n)\n```\n\nThe matches are:\n\n```bash\n$ node example.js\n{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }\n{ start: 3,\n  end: 9,\n  pre: 'pre',\n  body: 'first',\n  post: 'between{second}post' }\n{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }\n```\n\n## API\n\n### const m = balanced(a, b, str)\n\nFor the first non-nested matching pair of `a` and `b` in `str`, return an\nobject with those keys:\n\n- **start** the index of the first match of `a`\n- **end** the index of the matching `b`\n- **pre** the preamble, `a` and `b` not included\n- **body** the match, `a` and `b` not included\n- **post** the postscript, `a` and `b` not included\n\nIf there's no match, `undefined` will be returned.\n\nIf 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', '}']`.\n\n### const r = balanced.range(a, b, str)\n\nFor the first non-nested matching pair of `a` and `b` in `str`, return an\narray with indexes: `[ <a index>, <b index> ]`.\n\nIf there's no match, `undefined` will be returned.\n\nIf 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]`.\n","publish_time":1770648647458,"_cnpm_publish_time":1770648647458,"dist-tags":{"latest":"5.0.0"}}