Zeptomatch Unescape
zeptomatch-unescape is a small, specialized JavaScript utility designed to remove backslash escape sequences from glob patterns. It specifically targets characters commonly treated as special in glob syntax (e.g., `*`, `?`, `[`, `]`), converting `\*` to `*`, `\?` to `?`, and so on. This normalization is crucial when you need to interpret a glob pattern literally, especially if the pattern was generated dynamically or requires further processing without accidental escape interpretation. Currently at stable version 1.0.1, the package is maintained with a focus on reliability and correctness for its specific function, implying an infrequent release cadence. It integrates seamlessly into broader pattern matching pipelines, notably mentioned as a companion to `zeptomatch-is-static` for optimizing glob evaluation by first identifying and then handling truly static parts. This clear, single-purpose design differentiates it by offering a reliable component for complex pattern manipulation workflows.
Common errors
-
TypeError: zeptomatch_unescape_1.default is not a function
cause Incorrect CommonJS `require` syntax when trying to import a default export from an ES module.fixChange the import statement to `const unescape = require('zeptomatch-unescape');` in CommonJS files, or ensure your build configuration correctly handles ES module interop. -
Cannot find module 'zeptomatch-unescape'
cause The package is not installed or the import path is incorrect.fixRun `npm install zeptomatch-unescape` to install the package and double-check that the import path in your code exactly matches `zeptomatch-unescape`.
Warnings
- gotcha The utility specifically unescapes glob special characters (e.g., `*`, `?`, `[`, `]`). Other backslash escapes (e.g., `\n`, `\t`, or non-glob character escapes like `\-`) are preserved, as it's not a general-purpose string unescaper.
- gotcha This package performs only unescaping and does not validate the glob pattern's syntax or ensure it forms a valid glob after unescaping.
Install
-
npm install zeptomatch-unescape -
yarn add zeptomatch-unescape -
pnpm add zeptomatch-unescape
Imports
- unescape
import { unescape } from 'zeptomatch-unescape';import unescape from 'zeptomatch-unescape';
- unescape (CJS)
const { unescape } = require('zeptomatch-unescape');const unescape = require('zeptomatch-unescape'); - Types
import type { Unescape } from 'zeptomatch-unescape';
Quickstart
import unescape from 'zeptomatch-unescape';
// Example 1: Basic unescaping of glob special characters
const glob1 = 'foo\\*bar\\?';
const unescapedGlob1 = unescape(glob1);
console.log(`Original: "${glob1}" -> Unescaped: "${unescapedGlob1}"`);
// Expected: Original: "foo\*bar\?" -> Unescaped: "foo*bar?"
// Example 2: Glob with no special characters or escapes
const glob2 = 'path/to/file.txt';
const unescapedGlob2 = unescape(glob2);
console.log(`Original: "${glob2}" -> Unescaped: "${unescapedGlob2}"`);
// Expected: Original: "path/to/file.txt" -> Unescaped: "path/to/file.txt"
// Example 3: Mixed escapes and non-escaped characters
const glob3 = 'dir/\\*.js';
const unescapedGlob3 = unescape(glob3);
console.log(`Original: "${glob3}" -> Unescaped: "${unescapedGlob3}"`);
// Expected: Original: "dir/\*.js" -> Unescaped: "dir/*.js"
// Example 4: Escapes that are not glob special characters (should remain)
const glob4 = 'file\\-name.txt';
const unescapedGlob4 = unescape(glob4);
console.log(`Original: "${glob4}" -> Unescaped: "${unescapedGlob4}"`);
// Expected: Original: "file\-name.txt" -> Unescaped: "file\-name.txt"