Registry / serialization / skip-regex

skip-regex

JSON →
library1.0.2jsnpmunverified

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.

npm install skip-regex
INSTALL
IMPORT
SIG · SKIP-REGEX
S
skip-regex
serializationjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

skipRegex
import skipRegex from 'skip-regex'
This is the standard ESM import. For TypeScript, `esModuleInterop` should be enabled in `tsconfig.json` for this style.
skipRegex
const skipRegex = require('skip-regex')
import skipRegex from 'skip-regex' // without esModuleInterop in TypeScript
This is the CommonJS import pattern, suitable for Node.js or bundlers configured for CJS.
skipRegex
import skipRegex = require('skip-regex')
import { skipRegex } from 'skip-regex' // Incorrect for default export
This TypeScript-specific import syntax explicitly uses a `require`-style import, useful when `esModuleInterop` is not enabled.

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.

import skipRegex from 'skip-regex' const source = 'const foo = bar /.*/g; // this is a regex \n const baz = 10 / 2; // division \n const qux = /* comment */ 5;' let start = 0; let currentIndex = 0; let detectedRegexes = []; while (currentIndex < source.length) { start = source.indexOf('/', currentIndex); if (start === -1) break; const end = skipRegex(source, start); if (end > start + 1) { // Detected as regex if end is greater than start + 1 (meaning it found a regex beyond the initial slash) const regex = source.slice(start, end); detectedRegexes.push({ regex, start, end }); currentIndex = end; } else { // Not a regex, could be division or comment start. // skipRegex returns start + 1 if it's not a regex, so we advance past the current slash. currentIndex = start + 1; } } console.log('Detected Regular Expressions:', detectedRegexes); // Example output shows how it distinguishes: // Detected Regular Expressions: [ // { regex: '/.*/g', start: 16, end: 22 } // ]
Debug
Known issues
gotchaThe `start` parameter provided to `skipRegex` *must* point to a forward slash (`/`) character within the `source` string. If `start` points to any other character, the function's behavior is undefined or incorrect.
fix
Always ensure `source[start] === '/'` before calling `skipRegex(source, start)`. Use `source.indexOf('/')` to find valid starting points for a potential regex.
affects: *
Errors
Common errors & fixes
Module '"skip-regex"' has no default export. Did you mean to use 'import skipRegex = require("skip-regex")'?
Using `import skipRegex from 'skip-regex'` in a TypeScript project without `esModuleInterop` enabled in `tsconfig.json`.
fix
Enable `esModuleInterop: true` in your `tsconfig.json` or change the import statement to `import skipRegex = require('skip-regex')`.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
skip-regex — npm install skip-regex · libregistry