@uppercod/str-fragment
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

str-replace

Capture text fragments based on regular expressions that are executed for each line of the text.

Install

npm install @uppercod/str-fragment

Example

import { getFragments, replaceFragments } from "@uppercod/str-fragment";

let str = `
/**
 * old comment
 */
let s = "";
`;

/**@type {import("str-fragment/internal").captures}*/
let fragments = getFragment(str, {
    open: /\/\*\*/,
    end: /\*\//,
    equal: false, // if fragments share capture equality set equal to true
});

replaceFragments(str, fragments, () => `/** new comment */`);
// /** new comment */
// let s = "";

more expressions

template-string

let blocks = getFragments(code, {
    open: /css`/,
    end: /`/,
});

frontmatter

let blocks = getFragments(code, {
    open: /^---/m,
    end: /^---/m,
    equal: true,
});

Api

replaceFragments

Replace the fragments with a new text, if null returns no replacement of the evaluated fragment is generated

walkFragments

Walk on the shards generate changes

Readme

Keywords

none

Package Sidebar

Install

npm i @uppercod/str-fragment

Weekly Downloads

0

Version

1.3.3

License

ISC

Unpacked Size

11.7 kB

Total Files

9

Last publish

Collaborators

  • uppercod