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

chiffon

v2.5.4

Published

A small ECMAScript parser, tokenizer and minifier written in JavaScript.

Downloads

73

Readme

Chiffon

Build Status

A small ECMAScript parser, tokenizer and minifier written in JavaScript.

Features

Installation

In Browser:

<script src="chiffon.js"></script>

or

<script src="chiffon.min.js"></script>

Object Chiffon will defined in the global scope.

In Node.js:

npm install chiffon
var Chiffon = require('chiffon');

bower:

bower install chiffon

Parse

Parse a string source.
The result will be an abstract syntax tree (JavaScript AST) object.
(JavaScript AST is specified by the ESTree spec.)

  • {Object} Chiffon.parse ( source [, options ] )
    @param {string} source Target source.
    @param {Object} [options] Parse options.
    @return {Object} Return an abstract syntax tree object.

Example:

var ast = Chiffon.parse('1 + 1');
console.log(ast);
/*
{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "BinaryExpression",
        "operator": "+",
        "left": {
          "type": "Literal",
          "value": 1,
          "raw": "1"
        },
        "right": {
          "type": "Literal",
          "value": 1,
          "raw": "1"
        }
      }
    }
  ]
}
*/

Parse Options

  • range : {boolean} default=false
    Include an index-based location range. (array)

  • loc : {boolean} default=false
    Include line number and column-based location info.

Full options are following.

var options = {
  range: Boolean,
  loc: Boolean
};

Tokenize

Tokenize a string source.

  • {Array} Chiffon.tokenize ( source [, options ] )
    @param {string} source Target source.
    @param {Object} [options] Tokenize options.
    @return {Array} Return an array of the parsed tokens.
var tokens = Chiffon.tokenize('var a = 1');
console.log(tokens);
/*
[ { type: 'Keyword',    value: 'var' },
  { type: 'Identifier', value: 'a' },
  { type: 'Punctuator', value: '=' },
  { type: 'Numeric',    value: '1' } ]
*/

Defined token type

  • Comment
  • WhiteSpace
  • LineTerminator
  • Template
  • String
  • Punctuator
  • RegularExpression
  • Numeric
  • Identifier
  • Null
  • Boolean
  • Keyword

Tokenize Options

  • comment : {boolean} default=false
    Keep comment tokens.

  • whiteSpace : {boolean} default=false
    Keep white space tokens.

  • lineTerminator : {boolean} default=false
    Keep line terminator tokens.

  • range : {boolean} default=false
    Include an index-based location range. (array)

  • loc : {boolean} default=false
    Include line number and column-based location info.

Full options are following.

var options = {
  comment: Boolean,
  whiteSpace: Boolean,
  lineTerminator: Boolean,
  range: Boolean,
  loc: Boolean
};

Untokenize

Concatenate to string from the parsed tokens.

  • {string} Chiffon.untokenize ( tokens )
    @param {Array} tokens An array of the parsed tokens.
    @param {Object} [options] Untokenize options.
    @return {string} Return a concatenated string.

Untokenize Options

  • unsafe : {boolean} (default=false)
    Untokenizer does not add a space between the identifier and identifier.

Tokens can return to the original string by using the untokenize with these options.

var source = 'var a = 1, b = 2; // comment';
var tokens = Chiffon.tokenize(source, {
  comment: true,
  whiteSpace: true,
  lineTerminator: true
});

var result = Chiffon.untokenize(tokens, { unsafe: true });
console.log(result === source); // true

Minify

Minify JavaScript source.

  • {string} Chiffon.minify ( source )
    @param {string} source Target source.
    @param {Object} [options] minify options.
    @return {string} Return a minified source.
var min = Chiffon.minify('var a = 1 + 1; // comment');
console.log(min); // 'var a=1+1;'

Minify Options

  • maxLineLen : {number} default=32000
    Limit the line length in symbols.

Demo

License

MIT