0.0.6 • Published 3 years ago

token-slice v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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!

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago