npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fsnjs/tokenize

v2.1.0

Published

An abstract tokenizer.

Downloads

28

Readme

@fsnjs/tokenize

@fsnjs/tokenize is a zero-dependency library that facilitates tokenization for applications such as parsers or interpreters where incoming data needs to be broken down into tokens for further processing.

The library's primary export is the abstract Tokenizer class that is designed to take in a sequence of values (e.g., characters, objects, etc.) and convert them into structured tokens that can later be processed by another part of the application.

An additional export added in v2.0.0 is StringTokenizer that provides various functions that are useful when parsing string inputs.

You can view detailed documentation here.

Usage Notes

To see Tokenizer in action, check out examples here.

Tokenizer Error

The Tokenizer Error class is an extension of SyntaxError that provides a format function. This format function provides you with an error string in the following format:

/path/to/my_script.ts:2:4 - error: This is a dumb function, isn't it.

1  function my_function() {
2      throw new Error(`This is a dumb function, isn't it.`);
       ^
3  }

The format function accepts an object that has the parameters:

| Parameter | Type | Default | Description | | --------------- | ---------------------- | ------- | --------------------------------------------------------- | | trimLength | number, undefined | null | The number of lines to precede and follow the error line. | | lineNumbers | boolean, undefined | true | Whether line numbers should be prepended to each line. | | showOnlyErrorLn | boolean, undefined | null | Whether only the error line and caret should be shown. |

registerColorFunctions

If you would like your error messages to be automatically colorized, you can register color functions from a library like Chalk with this method.

registerSyntaxHighlighter

If you would like the code in your error messages to be colorized, you can register a function that colorizes the output code with this method.

Changelog

v2.0.0

  • Introduces StringTokenizer, an extension of Tokenizer that provides useful string utilities.

  • The abstract R type in Tokenizer<T, R> no longer extends Token to provide more type flexibility in situations where a position is not necessary.

  • A peek method was added that returns the value from the top of vals without unshifting it from vals.

  • An options parameter was added to prettyPrint in TokenizerError that provides you with the ability to...

    • Return a chunk of the source with the caret pointer
    • Add line numbers to the left of each line

Breaking Changes

  • orphan_behavior was removed from the consume function. Orphaned tokens are unshifted onto vals.
  • next was renamed to shift, and the lookahead parameter was removed.