{"library":"perf-regexes","title":"Optimized Regular Expressions for JavaScript","description":"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.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install perf-regexes"],"cli":null},"imports":["import R from 'perf-regexes';","import R from 'perf-regexes';\nconst htmlCommentRegex = R.HTML_CMNT;","import R from 'perf-regexes';\nconst jsStringRegex = R.JS_STRING;","import R from 'perf-regexes';\nconst deprecatedRegex = R.JS_REGEX_P;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const R = require('perf-regexes');\n\n// Function to remove trailing whitespace, empty lines, and normalize line-endings\nconst cleaner = (text) => text.split(R.OPT_WS_EOL).filter(Boolean).join('\\n');\n\nconsole.log('Cleaned text example:');\nconsole.dir(cleaner(' \\r\\r\\n\\nAA\\t\\t\\t\\r\\n\\rBB\\nCC  \\rDD  '));\n// Expected output: 'AA\\nBB\\nCC\\nDD'\n\n// Use the cleaner function to cleanup HTML text by first removing HTML comments\nconst htmlCleaner = (html) => cleaner(html.replace(R.HTML_CMNT, ''));\n\nconst rawHtml = '\\r<!--header--><h1>A</h1>\\r<div>B<br>\\r\\nC</div> <!--end-->\\n';\nconsole.log('\\nCleaned HTML example:');\nconsole.dir(htmlCleaner(rawHtml));\n// Expected output: '<h1>A</h1>\\n<div>B<br>\\nC</div>'\n\n// Demonstrating string conversion: Double-quoted to single-quoted strings\nconst toSingleQuotes = (text) => text.replace(R.JS_STRING, (str) => {\n  return str[0] === '\"'\n    ? `'${str.slice(1, -1).replace(/'/g, \"\\'\")}'`\n    : str;\n});\n\nconst stringWithQuotes = `\"A's\" 'B' \"C\" \"D\\\\\"E\" 'F\\\\\\'G'`;\nconsole.log('\\nString quote conversion example:');\nconsole.log(toSingleQuotes(stringWithQuotes));\n// Expected output: 'A\\'s' 'B' 'C' 'D\\\"E' 'F\\'G'","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}