Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/script-equal
Check if one JavaScript code is equivalent to another code
https://github.com/shinnn/script-equal
Last synced: 27 days ago
JSON representation
Check if one JavaScript code is equivalent to another code
- Host: GitHub
- URL: https://github.com/shinnn/script-equal
- Owner: shinnn
- License: mit
- Created: 2014-11-21T06:24:22.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-21T09:59:27.000Z (almost 10 years ago)
- Last Synced: 2024-09-22T16:36:40.928Z (about 2 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# script-equal
[![Build Status](https://travis-ci.org/shinnn/script-equal.svg?branch=master)](https://travis-ci.org/shinnn/script-equal)
[![Build status](https://ci.appveyor.com/api/projects/status/6y21wd4dva7cu4rw?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/script-equal)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/script-equal.svg)](https://coveralls.io/r/shinnn/script-equal)
[![Dependency Status](https://david-dm.org/shinnn/script-equal.svg)](https://david-dm.org/shinnn/script-equal)
[![devDependency Status](https://david-dm.org/shinnn/script-equal/dev-status.svg)](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};'
); //=> truescriptEqual(
'var foo = 12',
'var foo = 1 + 1 * 14 - 3;;;;;;;;;;;;;;;;;;;'
); //=> true
```## Installation
[![NPM version](https://badge.fury.io/js/script-equal.svg)](https://www.npmjs.org/package/script-equal)
[Use npm.](https://www.npmjs.org/doc/cli/npm-install.html)
```
npm install script-equal
```## API
```javascript
var scriptEqual = require('script-equal');
```### scriptEqual(*script0*, *script1* [, *options*])
*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
```## License
Copyright (c) 2014 [Shinnosuke Watanabe](https://github.com/shinnn)
Licensed under [the MIT License](./LICENSE).
[UglifyJS]: https://github.com/mishoo/UglifyJS2
[options]: https://github.com/mishoo/UglifyJS2#api-reference