{"library":"skip-regex","title":"skip-regex: Literal Regular Expression Detector","description":"skip-regex is a lightweight, zero-dependency JavaScript utility designed for the highly accurate and fast detection of literal regular expressions within a string. It is currently at version 1.0.2, with its last release in December 2018, indicating an abandoned or maintenance status rather than active development. The library provides a single function, `skipRegex(source: string, start: number)`, which identifies the end position of a regex given a starting slash. Its key differentiators include a minimal footprint, compatibility across NodeJS, various bundlers, and browsers (including IE9+), and comprehensive TypeScript definitions. This makes it suitable for parsing or code analysis tools that need to distinguish between division operators, comments, and regex literals reliably.","language":"javascript","status":"abandoned","last_verified":"Tue Apr 21","install":{"commands":["npm install skip-regex"],"cli":null},"imports":["import skipRegex from 'skip-regex'","const skipRegex = require('skip-regex')","import skipRegex = require('skip-regex')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import skipRegex from 'skip-regex'\n\nconst source = 'const foo = bar /.*/g; // this is a regex \\n const baz = 10 / 2; // division \\n const qux = /* comment */ 5;'\nlet start = 0;\nlet currentIndex = 0;\nlet detectedRegexes = [];\n\nwhile (currentIndex < source.length) {\n  start = source.indexOf('/', currentIndex);\n  if (start === -1) break;\n\n  const end = skipRegex(source, start);\n\n  if (end > start + 1) {\n    // Detected as regex if end is greater than start + 1 (meaning it found a regex beyond the initial slash)\n    const regex = source.slice(start, end);\n    detectedRegexes.push({ regex, start, end });\n    currentIndex = end;\n  } else {\n    // Not a regex, could be division or comment start.\n    // skipRegex returns start + 1 if it's not a regex, so we advance past the current slash.\n    currentIndex = start + 1;\n  }\n}\n\nconsole.log('Detected Regular Expressions:', detectedRegexes);\n// Example output shows how it distinguishes:\n// Detected Regular Expressions: [\n//   { regex: '/.*/g', start: 16, end: 22 }\n// ]","lang":"typescript","description":"This quickstart demonstrates how to iterate through a string to find and extract all literal regular expressions using `skipRegex`, differentiating them from division operators or comment starts.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}