Registry / serialization / sed-lite

sed-lite

JSON →
library1.1.0jsnpmunverified

JavaScript implementation of the sed command-line tool for text substitution. Current stable version 1.1.0 compiles sed expressions to functions, supporting flags like g (global) and custom delimiters. The library is lightweight, has no dependencies, and ships TypeScript declarations. It differs from alternatives like xregexp by focusing on sed syntax compatibility, enabling use in Node.js and browsers.

npm install sed-lite
INSTALL
IMPORT
SIG · SED-LITE
S
sed-lite
serializationjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

sed
✓ import { sed } from 'sed-lite'
✗ const { sed } = require('sed-lite')
ESM module; require() may work in Node, but ESM import is preferred.
default
✓ import sed from 'sed-lite'
✗ import { sed } from 'sed-lite' // if default export is used
sed-lite also exports a default function; both patterns work.
SedExpression
✓ import type { SedExpression } from 'sed-lite'
TypeScript type for compiled sed function. Not required at runtime.

Demonstrates basic usage: compile sed substitution, global flag, custom delimiter, and chaining expressions.

import { sed } from 'sed-lite'; const transform = sed('s/world/JavaScript/'); const result = transform('Hello, world!'); console.log(result); // Hello, JavaScript! // With global flag const replaceAll = sed('s/\d+/###/g'); console.log(replaceAll('Item 1, Item 2, Item 3')); // Item ###, Item ###, Item ### // Custom delimiter const changeFormat = sed('s#2024-01-01#01/01/2024#'); console.log(changeFormat('Date: 2024-01-01')); // Date: 01/01/2024 // Chain multiple expressions with semicolon const multi = sed('s/foo/bar/; s/bar/baz/'); console.log(multi('foo')); // baz
Debug
Known issues
gotchased-lite does not support all GNU sed features; only 's' command (substitute) is implemented. Attempting other commands like 'd', 'p', 'a', 'i' may throw or silently fail.
fix
Use only 's' command. For extended functionality, consider other libraries like xregexp or manual RegExp.
affects: >=1.0.0
gotchaRegular expression syntax follows JavaScript RegExp, not sed's BRE/ERE. Escaping patterns may differ from standard sed (e.g., back-references use $1 instead of \1).
fix
Use JavaScript regex syntax: e.g., 's/(\w+)/$1/' — note the double escaping in string literal.
affects: >=1.0.0
gotchaFlags other than 'g' (global) are not supported (e.g., 'i' for case-insensitive, flags for multiple replacement with 'N' substitution). Attempting unknown flags may be ignored or cause unexpected behavior.
fix
To mimic 'i' flag, modify regex pattern manually: e.g., 's/pattern/replacement/i' in string but sed-lite does not interpret 'i'. Instead use native RegExp: str.replace(/pattern/i, 'replacement').
affects: >=1.0.0
deprecatedThe package exports a default function and named 'sed'. The default export may be deprecated in future; prefer named import.
fix
Use import { sed } from 'sed-lite' instead of import sed from 'sed-lite'.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Invalid regular expression: /s/(foo)/(bar)//: Nothing to repeat
Passing a sed command string with slashes without proper escaping or incorrect syntax.
fix
Ensure the sed string is correctly formatted: e.g., 's/foo/bar/' — use valid JavaScript RegExp patterns. If using custom delimiter, use a character not appearing in the pattern or replacement, e.g., 's#foo#bar#'.
TypeError: sed is not a function
Incorrect import: default import vs named import mismatch.
fix
Use import { sed } from 'sed-lite' (named) or import sed from 'sed-lite' (default), depending on how you want to call it.
sed(...) is not a function
sed() returns a function that takes a string argument. Using it directly as a replacement function (e.g., String.prototype.replace(sed(...))) is invalid.
fix
Call sed(expression)(input) or store the compiled function in a variable.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
sed-lite — npm install sed-lite · libregistry