script-equal
Version:
Check if one JavaScript code is equivalent to another code
79 lines (53 loc) • 2.26 kB
Markdown
[](https://travis-ci.org/shinnn/script-equal)
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/script-equal)
[](https://coveralls.io/r/shinnn/script-equal)
[](https://david-dm.org/shinnn/script-equal)
[](https://david-dm.org/shinnn/script-equal#info=devDependencies)
Check if one JavaScript code is equivalent to another code, using [UglifyJS]
```javascript
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
```
[](https://www.npmjs.org/package/script-equal)
[](https://www.npmjs.org/doc/cli/npm-install.html)
```
npm install script-equal
```
```javascript
var scriptEqual = require('script-equal');
```
*script0*:`String` (JavaScript code)
*script1*:`String` (JavaScript code)
*options*: `Object` ([UglifyJS][options] 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] options.
```javascript
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.
```javascript
scriptEqual('a = 1', '1 = a'); // Error
```
Copyright (c) 2014 [Shinnosuke Watanabe](https://github.com/shinnn)
Licensed under [the MIT License](./LICENSE).
[]: https://github.com/mishoo/UglifyJS2
[]: https://github.com/mishoo/UglifyJS2#api-reference