{"id":26375,"library":"sed-lite","title":"sed-lite","description":"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.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/kawanet/sed-lite","tags":["javascript","replace","sed","typescript"],"install":[{"cmd":"npm install sed-lite","lang":"bash","label":"npm"},{"cmd":"yarn add sed-lite","lang":"bash","label":"yarn"},{"cmd":"pnpm add sed-lite","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM module; require() may work in Node, but ESM import is preferred.","wrong":"const { sed } = require('sed-lite')","symbol":"sed","correct":"import { sed } from 'sed-lite'"},{"note":"sed-lite also exports a default function; both patterns work.","wrong":"import { sed } from 'sed-lite' // if default export is used","symbol":"default","correct":"import sed from 'sed-lite'"},{"note":"TypeScript type for compiled sed function. Not required at runtime.","wrong":null,"symbol":"SedExpression","correct":"import type { SedExpression } from 'sed-lite'"}],"quickstart":{"code":"import { sed } from 'sed-lite';\n\nconst transform = sed('s/world/JavaScript/');\nconst result = transform('Hello, world!');\nconsole.log(result); // Hello, JavaScript!\n\n// With global flag\nconst replaceAll = sed('s/\\d+/###/g');\nconsole.log(replaceAll('Item 1, Item 2, Item 3')); // Item ###, Item ###, Item ###\n\n// Custom delimiter\nconst changeFormat = sed('s#2024-01-01#01/01/2024#');\nconsole.log(changeFormat('Date: 2024-01-01')); // Date: 01/01/2024\n\n// Chain multiple expressions with semicolon\nconst multi = sed('s/foo/bar/; s/bar/baz/');\nconsole.log(multi('foo')); // baz","lang":"typescript","description":"Demonstrates basic usage: compile sed substitution, global flag, custom delimiter, and chaining expressions."},"warnings":[{"fix":"Use only 's' command. For extended functionality, consider other libraries like xregexp or manual RegExp.","message":"sed-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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use JavaScript regex syntax: e.g., 's/(\\w+)/$1/' — note the double escaping in string literal.","message":"Regular 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).","severity":"gotcha","affected_versions":">=1.0.0"},{"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').","message":"Flags 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use import { sed } from 'sed-lite' instead of import sed from 'sed-lite'.","message":"The package exports a default function and named 'sed'. The default export may be deprecated in future; prefer named import.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"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#'.","cause":"Passing a sed command string with slashes without proper escaping or incorrect syntax.","error":"SyntaxError: Invalid regular expression: /s/(foo)/(bar)//: Nothing to repeat"},{"fix":"Use import { sed } from 'sed-lite' (named) or import sed from 'sed-lite' (default), depending on how you want to call it.","cause":"Incorrect import: default import vs named import mismatch.","error":"TypeError: sed is not a function"},{"fix":"Call sed(expression)(input) or store the compiled function in a variable.","cause":"sed() returns a function that takes a string argument. Using it directly as a replacement function (e.g., String.prototype.replace(sed(...))) is invalid.","error":"sed(...) is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}