js-tokens
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
js-tokens is a tiny, highly efficient JavaScript tokenizer. It uses regular expressions for its operations and is almost fully compliant with the JavaScript specification. This tokenizer never fails, thus ensuring uninterrupted performance in your development process. It is specifically designed to decode JavaScript strings into individual tokens.
The use of js-tokens is quite straightforward and easy to incorporate into your JavaScript code. Firstly, you need to require the js-tokens module in your file using Node.js style require function. After that, you pass your JavaScript string to the function exported by js-tokens module. This function will return an iterable object with all tokens from the string. Here is an example:
const jsTokens = require("js-tokens");
const jsString = 'JSON.stringify({k:3.14**2}, null /*replacer*/, "\\t")';
Array.from(jsTokens(jsString), (token) => token.value).join("|");
// Outputs: JSON|.|stringify|(|{|k|:|3.14|**|2|}|,| |null| |/*replacer*/|,| |"\t"|)
What this code does is to tokenize a JavaScript method string, and then it uses the Array.from method transform the iterable object into an array and manipulate each token.
The complete documentation for js-tokens can be found on their GitHub page. You can easily access detailed instructions, usage examples, API reference, and more on this page.