token-slice
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

token-slice

Build and test status

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,
      },
    }
  ]
}

References

This repo was set up based on the template outlined in Starting a TypeScript Project in 2021, recommend checking out the post!

Readme

Keywords

none

Package Sidebar

Install

npm i token-slice

Weekly Downloads

66

Version

0.0.6

License

MIT

Unpacked Size

34.3 kB

Total Files

20

Last publish

Collaborators

  • mwcz