The `perf-regexes` package (current version 1.0.1, last updated in late 2018) provides a collection of pre-optimized regular expressions tailored for common parsing tasks in JavaScript. This includes patterns for identifying HTML comments, JavaScript comments (single and multi-line), various types of strings (single and double-quoted), and managing line endings. It offers utilities for detecting empty lines, non-empty lines, trailing whitespace, and normalizing line-ending styles. The library supports both CommonJS and UMD builds, making it usable in Node.js environments (with a minimum requirement of Node.js 6.14) and directly in browsers via a global `R` object. A key differentiator is its focus on robust, pre-built, and tested regex patterns that simplify complex parsing challenges, especially for nested structures or escaped characters, which are notoriously difficult to handle with custom regexes. The package also ships with TypeScript definitions, enhancing developer experience in type-checked environments. Despite its utility, the package has not received updates since 2018, indicating it is no longer actively maintained.
npm install perf-regexesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `perf-regexes` to clean text by removing empty lines and trailing whitespace, normalize HTML by stripping comments, and convert double-quoted JavaScript strings to single-quoted strings.
Avoid using `JS_REGEX_P`. If you need to identify regexes, use `JS_REGEX` and perform additional validation or consider dedicated parsing libraries.
Before each `regex.exec(text)` call, ensure `regex.lastIndex = 0;` or create a new regex instance, e.g., `const newRegex = new RegExp(R.YOUR_REGEX.source, R.YOUR_REGEX.flags);`.
Ensure your Node.js environment is version 6.14 or higher. Update Node.js if necessary.
Limit the use of `JS_REGEX` to complement other utilities or for less critical parsing tasks. For robust JavaScript parsing, consider a dedicated AST parser or a more sophisticated tokenization library.
Replace `R.JS_REGEX_P` with `R.JS_REGEX` and implement additional validation, or consider using alternative parsing strategies.
Set `yourRegex.lastIndex = 0;` before each new `exec()` call on the same regex instance, or create a new `RegExp` instance each time.
In CommonJS, use `const R = require('perf-regexes');`. For ESM, use `import R from 'perf-regexes';`. In a browser, ensure `<script src="https://unpkg.com/perf-regexes/index.min.js"></script>` is loaded before attempting to access `window.R`.No dependency data recorded yet.