token-slice is a small library for extracting text wrapped with arbitrary tokens. Please do not use it for parsing HTML.
import { createTokenSlicer } from "token-slice";
const tok = createTokenSlicer({
tokens: [
{
name: "token1",
start: "a",
end: "c",
}
]
});
// provide an input string
const output = tok.tokenize("abc");
// output equals:
{
input: "abc",
config: { /* copy of the config object passed into createTokenSlicer */ },
result: [
{
definition: {name: "test_token", start: "a", end: "c"},
inner: {
content: "b",
startIndex: 1,
endIndex: 2,
},
outer: {
content: "abc",
startIndex: 0,
endIndex: 3,
},
}
]
}
This repo was set up based on the template outlined in Starting a TypeScript Project in 2021, recommend checking out the post!