1.0.1 • Published 9 years ago

script-equal v1.0.1

Weekly downloads
5
License
-
Repository
github
Last release
9 years ago

script-equal

Build Status Build status Coverage Status Dependency Status devDependency Status

Check if one JavaScript code is equivalent to another code, using UglifyJS

var scriptEqual = require('script-equal');

scriptEqual(
  'window.foo = {a: 0, b: 1};',
  'window["foo"]={\nb: 1,\rna: 0\n};'
); //=> true

scriptEqual(
  'var foo = 12',
  'var foo = 1 + 1 * 14 - 3;;;;;;;;;;;;;;;;;;;'
); //=> true

Installation

NPM version

Use npm.

npm install script-equal

API

var scriptEqual = require('script-equal');

scriptEqual(script0, script1 , options)

script0:String (JavaScript code)
script1:String (JavaScript code)
options: Object (UglifyJS options)
Return: Boolean

It compresses two JavaScript string with UglifyJS. If the results are the same string, it returns true. Otherwise it returns false.

You can use all UglifyJS options.

var scriptEqual = require('script-equal');

var foo = 'a = {}; a.b = 0;';
var bar = 'a = {}; a[\'b\'] = 0;';

scriptEqual(foo, bar); //=> true

scriptEqual(foo, bar, {
  compress: {properties: false}
}); //=> false

It throws an error when it fails to parse strings.

scriptEqual('a = 1', '1 = a'); // Error

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.