{"name":"graphmatch","version":"1.0.2","keywords":["regex","regexp","dag","graph","match"],"_id":"graphmatch@1.0.2","maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"homepage":"https://github.com/fabiospampinato/graphmatch#readme","bugs":{"url":"https://github.com/fabiospampinato/graphmatch/issues"},"dist":{"shasum":"b0a4c80ec14057290509e083190dad9a747876db","tarball":"http://registry-npm.ywwl.com/graphmatch/download/graphmatch-1.0.2.tgz","fileCount":9,"integrity":"sha512-QcqjrGYos1NAMjFFsBvpWtZk11H8pAOWy5bFafwcTNo/fiiTvN6WzKfGpWyE8DZaZcxQaf28XC4ksLO4WJqCdA==","signatures":[{"sig":"MEYCIQCTrHo4NMVQuaJ4LquSkstOX/TnN1i1zVfrYwjxDIdRuQIhAP6sG3ebY4E8q/toBHNcqrJizdY6UP7TolLH8+M633z7","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8142,"size":3076,"noattachment":false,"key":"/graphmatch/-/graphmatch-1.0.2.tgz"},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","exports":"./dist/index.js","gitHead":"4f7cbc20cdcc0f55d81b973f2ccc9132a1267bd0","scripts":{"test":"tsex test","clean":"tsex clean","compile":"tsex compile","benchmark":"tsex benchmark","test:watch":"tsex test --watch","compile:watch":"tsex compile --watch","prepublishOnly":"tsex prepare","benchmark:watch":"tsex benchmark --watch"},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"repository":{"url":"git+https://github.com/fabiospampinato/graphmatch.git","type":"git"},"_npmVersion":"10.2.3","description":"A low-level utility for matching a string against a directed acyclic graph of regexes.","directories":{},"_nodeVersion":"18.19.0","_hasShrinkwrap":false,"devDependencies":{"fava":"^0.3.5","tsex":"^4.0.2","benchloop":"^2.1.1","typescript":"^5.9.3"},"_npmOperationalInternal":{"tmp":"tmp/graphmatch_1.0.2_1760876999217_0.6179548192822302","host":"s3://npm-registry-packages-npm-production"},"readme":"# Graphmatch\n\nA low-level utility for matching a string against a directed acyclic graph of regexes.\n\n- It supports matching strings partially too.\n- It supports fine-grained control over which nodes in the graph can be matched partially or not.\n- It supports compiling the whole graph to a regex, even for partial matches.\n- The graph will always be matched against the input string from the very start.\n- RegExp flags are supported as long as they are the same for all the regexes in the graph.\n\n## Install\n\n```sh\nnpm install graphmatch\n```\n\n## Usage\n\n```ts\nimport graphmatch from 'graphmatch';\n\n// Let's say we would like to match against this glob: foo/{bar,baz}/qux\n// Let's express that as a graph of regexes that this library can match against\n// Whether you reuse the \"qux\" node or not doesn't matter, both are supported\n\nconst GRAPH = {\n  regex: /foo/,\n  children: [\n    {\n      regex: /\\//,\n      children: [\n        {\n          regex: /bar/,\n          children: [\n            {\n              regex: /\\//,\n              children: [\n                {\n                  regex: /qux/\n                }\n              ]\n            }\n          ]\n        },\n        {\n          regex: /baz/,\n          children: [\n            {\n              regex: /\\//,\n              children: [\n                {\n                  regex: /qux/\n                }\n              ]\n            }\n          ]\n        }\n      ]\n    }\n  ]\n};\n\n// Let's now match against the graph, fully\n\ngraphmatch ( GRAPH, 'foo/bar/qux' ); // => true\ngraphmatch ( GRAPH, 'foo/baz/qux' ); // => true\n\ngraphmatch ( GRAPH, 'foo/bar/whoops' ); // => false\ngraphmatch ( GRAPH, 'foo/baz' ); // => false\n\n// Let's now match against the graph, partially\n// A partial match happens when any node in the graph sees the end of the string, either before or after the node's regex is executed\n\ngraphmatch ( GRAPH, 'foo/bar/qux', { partial: true } ); // => true\ngraphmatch ( GRAPH, 'foo/bar/', { partial: true } ); // => true\ngraphmatch ( GRAPH, 'foo/bar', { partial: true } ); // => true\ngraphmatch ( GRAPH, 'foo/', { partial: true } ); // => true\ngraphmatch ( GRAPH, 'foo', { partial: true } ); // => true\n\ngraphmatch ( GRAPH, 'foo/bar/whoops', { partial: true } ); // => false\ngraphmatch ( GRAPH, 'foo/barsomething', { partial: true } ); // => false\ngraphmatch ( GRAPH, 'bar', { partial: true } ); // => false\n\n// As we just saw partial matching is set to \"false\" by default, and there is an option to set it to \"true\" by default\n// But you can also decide on a node-by-node basis whether partial matching should be enabled or disabled for that particular node\n// A partial node will match if the whole input string has been consumed, right before or after the node's regex is executed\n// This has higher priority compared to the global setting\n// This is useful for fine-grained control over which nodes can be matched partially\n\nconst NODE_NEVER_PARTIAL = { // This node will never match partially\n  partial: false,\n  regex: /foo/,\n  children: [],\n};\n\nconst NODE_ALWAYS_PARTIAL = { // This node will always match partially\n  partial: true,\n  regex: /foo/,\n  children: [],\n};\n\n// Let's now compile the whole graph to a single regex\n// This is useful if you expect to match against the graph multiple times\n// It's faster to compile the graph once and match against it multiple times\n\nconst fullRe = graphmatch.compile ( GRAPH ); // => RegExp\n\nfullRe.test ( 'foo/bar/qux' ); // => true\nfullRe.test ( 'foo/bar' ); // => false\n\nconst partialRe = graphmatch.compile ( GRAPH, { partial: true } ); // => RegExp\n\npartialRe.test ( 'foo/bar/qux' ); // => true\npartialRe.test ( 'foo/bar' ); // => true\n```\n\n## License\n\nMIT © Fabio Spampinato\n","publish_time":1760876999412,"_cnpm_publish_time":1760876999412,"dist-tags":{"latest":"1.1.1"}}