Graphmatch is a low-level utility designed for matching a string against a directed acyclic graph (DAG) composed of regular expressions. It provides flexible matching capabilities, supporting both full and partial string matches against these complex regex structures. Developers can exercise fine-grained control over partial matching behavior at the individual node level within the graph. A key feature is the ability to compile the entire graph into a single JavaScript RegExp object, which significantly optimizes performance for scenarios requiring multiple matches against the same graph. The package is currently at version 1.1.1 and appears to be actively maintained, though no specific release cadence is outlined in the documentation. Its core differentiation lies in offering a programmatic, graph-based approach to regex matching, which is more powerful and manageable than composing single, overly complex regular expressions or chaining multiple simple ones, particularly useful for structured pattern recognition like advanced globbing.
npm install graphmatchVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic full and partial string matching against a regex graph, and the compilation of a graph to a single RegExp for performance.
Ensure all `regex` properties in your graph nodes are created with identical flags, or no flags, consistently across the entire graph structure.
If matching needs to occur at arbitrary positions, you must manually iterate through substrings or modify your graph's root regex to optionally match leading characters, such as `/.*/`.
Thoroughly test your graph definitions, especially complex ones. Ensure `children` are always arrays of valid graph nodes and that `regex` properties are actual `RegExp` instances.
If you intend to match the same graph many times, use `graphmatch.compile(GRAPH_DEFINITION)` once to get a compiled RegExp and then use `compiledRe.test(string)` for subsequent checks.
For native ESM, use `import graphmatch from 'graphmatch';`. If in a CommonJS environment, you might need to use `const graphmatch = require('graphmatch').default;` or ensure your build setup correctly transpiles ESM imports.Verify that `import graphmatch from 'graphmatch';` is correctly acquiring the default export. The `compile` method is a property of the default `graphmatch` function, not a separate named export.
Review all `regex` properties in your graph definition and ensure that they all use the exact same set of RegExp flags, or no flags at all. For example, `regex: /pattern/i` should be consistent for all regexes if `i` is desired.
No dependency data recorded yet.