{"name":"balanced-match","version":"4.0.3","keywords":["match","regexp","test","balanced","parse"],"license":"MIT","_id":"balanced-match@4.0.3","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":"6337a2f23e0604a30481423432f99eac603599f9","tarball":"http://registry-npm.ywwl.com/balanced-match/download/balanced-match-4.0.3.tgz","fileCount":13,"integrity":"sha512-1pHv8LX9CpKut1Zp4EXey7Z8OfH11ONNH6Dhi2WDUt31VVZFXZzKwXcysBgqSumFCmR+0dqjMK5v5JiFHzi0+g==","signatures":[{"sig":"MEUCIH9OWtdo8EnhAcjK9esL1IETptCuksF0jySSZcOQI5p9AiEAsdVu6z+xOeDvy/ChziovUL3Xw8vAkv6ZFBdJ8w4SYTo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":17578,"size":4194,"noattachment":false,"key":"/balanced-match/-/balanced-match-4.0.3.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":"8a7fed428dea3a947dfbc73c7c868f925d38392e","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","_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.3_1771409317176_0.6953458986225476","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":1771409317329,"_cnpm_publish_time":1771409317329,"dist-tags":{"latest":"5.0.0"}}