Code Monkey home page Code Monkey logo

node-jsmin2's Introduction

node-jsmin2 Build status Donate on Gittip

Another port of JSMin -- this time outputting a coordinate map

Getting Started

Install the module with: npm install node-jsmin2

Documentation

JSMin is a function that minifies a single set of JavaScript and outputs an object with a code and codeMap.

/**
 * jsmin - Refer to LICENSE in base directory
 * @param {String} input JavaScript to minifiy
 * @return {Object} retObj
 * @return {String} retObj.code Minified JavaScript
 * @return {Object} retObj.codeMap Point to point map from source JavaScript to minified JavaScript
 */

Example

// Load in jsmin and jQuery
var jsmin = require('node-jsmin2'),
    jquerySrc = fs.readFileSync('jquery.js', 'utf8');

// Process the jquery source via jsmin
var jqueryMinObj = jsmin(jquerySrc);

// Minified code is available at
// jqueryMinObj.code;

// Coordinate map of source code to minified code is available at
// jqueryMinObj.codeMap;

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint your code via grunt and test via npm test.

License

Copyright (c) 2012 Todd Wolfson The Software shall be used for Good, not Evil. (see LICENSE)

node-jsmin2's People

Contributors

twolfson avatar tlbtlbtlb avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

vooor tlbtlbtlb

node-jsmin2's Issues

Move to better index tracking model

Instead of tracking exclusively index via theAIndex and gang, track both char and index inside of an object. This will not remove the functionality of theA itself just yet but function along side as it does currently.

This will allow for the fallback of stdout to console.log to still be able to function without knowing what the initial input looked like.

Automate index setting

Currently, all of the indicies tracking was implemented by hand. Any place you see a non-indented line in lib/jsmin.c..index.js is something that needs to be moved into macro/convert.js.

theAIndex = getIndex;

One edge case to be aware of is switch (get()) which may require a larger than normal rewrite of jsmin.c.

Move to pointer model for theA, theB, etc

First, complete #2 -- it will be too annoying to directly to this step.

However, the gist of it is that any comparison where we normally do theA >= 'A' would be replaced with theA.char >= A. There are a lot of edge cases that must be covered here -- namely that get will now be returning objects instead of strings which causes a ton of complications for things like switch(get()).

isAlphanum broken

Changes to isAlphanum in commit 6c82b27 make it crash on most inputs. As a simple example:

> var jsmin = require('jsmin2');
> jsmin('{\n}\n')
TypeError: c.charCodeAt is not a function
    at isAlphanum (/usr/lib/node_modules/jsmin2/lib/jsmin.c.index.js:103:15)
    at jsmin (/usr/lib/node_modules/jsmin2/lib/jsmin.c.index.js:320:25)
    at main (/usr/lib/node_modules/jsmin2/lib/jsmin.c.index.js:373:9)
    at jsminFn (/usr/lib/node_modules/jsmin2/lib/jsmin.c.index.js:378:12)
    at jsmin (/usr/lib/node_modules/jsmin2/lib/jsmin.js:82:3)
    at repl:1:1
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)

The thing being passed to isAlphanum which is not a string and so doesn't have the charCodeAt method is the number -1, the EOF marker. I think this is normal behavior of the original C code. isAlphanum should first check for -1 and return false.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.