Comparing version 1.2.2 to 2.0.0
@@ -16,2 +16,4 @@ /* Copyright 2016 Myles Borins | ||
var babel = require('babel-core'); | ||
function minify(code, cb) { | ||
@@ -22,27 +24,6 @@ if (typeof code !== 'string') { | ||
} | ||
try { | ||
// remove comments | ||
code = code.replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm, ''); | ||
// remove any spaces after a semi colon | ||
code = code.replace(/;\s+/g, ';'); | ||
// remove extra spaces around + | ||
code = code.replace(/(\s+)?\+(\s+)?/g, '+'); | ||
// remove extra spaces around - | ||
code = code.replace(/(\s+)?\-(\s+)?/g, '-'); | ||
// remove extra spaces around * | ||
code = code.replace(/(\s+)?\*(\s+)?/g, '*'); | ||
// remove extra spaces around / | ||
code = code.replace(/(\s+)?\/(\s+)?/g, '/'); | ||
// remove extra spaces around = | ||
code = code.replace(/(\s+)?\=(\s+)?/g, '='); | ||
// remove spaces at the begining | ||
code = code.replace(/^\s+/, ''); | ||
} | ||
@@ -53,3 +34,8 @@ catch (e) { | ||
} | ||
cb(null, code); | ||
var result = babel.transform(code, { | ||
presets: ['babili'] | ||
}).code; | ||
cb(null, result); | ||
return true; | ||
@@ -56,0 +42,0 @@ } |
{ | ||
"name": "esmall", | ||
"version": "1.2.2", | ||
"version": "2.0.0", | ||
"description": "Pretty Naive", | ||
@@ -16,2 +16,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"babel-core": "^6.21.0", | ||
"babel-preset-babili": "0.0.9", | ||
"chalk": "^1.1.3", | ||
@@ -18,0 +20,0 @@ "concat-stream": "^1.5.2", |
@@ -5,11 +5,5 @@ # esmall | ||
## 📛 WARNING 📛 | ||
This is super jank, likely to break your code. | ||
For best results use semi colons! | ||
## How it works | ||
Does a little [reggae](https://twitter.com/thealphanerd/status/764133752905883649) | ||
Just a little wrapper around [babili][babili] with a little [reggae][reggae] to deal with comments | ||
@@ -47,2 +41,5 @@ ## Using the cli | ||
Apache v2.0 | ||
Apache v2.0 | ||
[babili][https://github.com/babel/babili] | ||
[reggae][https://twitter.com/thealphanerd/status/764133752905883649] |
@@ -21,9 +21,10 @@ /* Copyright 2016 Myles Borins | ||
var code = ` | ||
var a = '123'; | ||
var b = '456'; | ||
var a = 213; | ||
var b = 123; | ||
var c = 123456; | ||
console.log('a + b * c / d'); | ||
var d = 2134; | ||
console.log(a + b * c / d); | ||
`; | ||
var expected = 'var a=\'123\';var b=\'456\';var c=123456;console.log(\'a+b*c/d\');'; | ||
var expected = 'var a=213,b=123,c=123456,d=2134;console.log(a+b*c/d);'; | ||
@@ -46,22 +47,9 @@ var licensedCode = ` | ||
var a = '123'; | ||
var b = '456'; // this comment should be removed | ||
var c = 123456; | ||
console.log('a + b * c / d'); | ||
var a = 213; | ||
var b = 123; | ||
var c = 123456; | ||
var d = 2134 | ||
console.log(a + b * c / d); | ||
`; | ||
var multiSpaceSemiColon = ` | ||
var a = '123'; var b = '456'; // this comment should be removed | ||
var c = 123456; | ||
console.log('a +b * c / d'); | ||
`; | ||
var excessiveSpaces = ` | ||
var a = '123'; var b = '456'; // this comment should be removed | ||
var c = 123456; | ||
console.log('a + | ||
b * c / d'); | ||
`; | ||
test('basic test', (t) => { | ||
@@ -75,18 +63,2 @@ t.plan(2); | ||
test('more than one space after semi', (t) => { | ||
t.plan(2); | ||
esmall(multiSpaceSemiColon, (err, result) => { | ||
t.error(err); | ||
t.equals(result, expected, 'we should be minified'); | ||
}); | ||
}); | ||
test('no excessive spaces', (t) => { | ||
t.plan(2); | ||
esmall(excessiveSpaces, (err, result) => { | ||
t.error(err); | ||
t.equals(result, expected, 'we should be minified'); | ||
}); | ||
}); | ||
test('no license', (t) => { | ||
@@ -93,0 +65,0 @@ t.plan(2); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93744
5
205
43
+ Addedbabel-core@^6.21.0
+ Addedbabel-preset-babili@0.0.9
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-core@6.26.3(transitive)
+ Addedbabel-generator@6.26.1(transitive)
+ Addedbabel-helper-evaluate-path@0.0.3(transitive)
+ Addedbabel-helper-flip-expressions@0.0.1(transitive)
+ Addedbabel-helper-is-nodes-equiv@0.0.1(transitive)
+ Addedbabel-helper-is-void-0@0.0.1(transitive)
+ Addedbabel-helper-mark-eval-scopes@0.1.1(transitive)
+ Addedbabel-helper-remove-or-void@0.1.1(transitive)
+ Addedbabel-helper-to-multiple-sequence-expressions@0.0.2(transitive)
+ Addedbabel-helpers@6.24.1(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-plugin-minify-constant-folding@0.0.3(transitive)
+ Addedbabel-plugin-minify-dead-code-elimination@0.1.7(transitive)
+ Addedbabel-plugin-minify-flip-comparisons@0.0.1(transitive)
+ Addedbabel-plugin-minify-guarded-expressions@0.0.3(transitive)
+ Addedbabel-plugin-minify-infinity@0.0.3(transitive)
+ Addedbabel-plugin-minify-mangle-names@0.0.5(transitive)
+ Addedbabel-plugin-minify-numeric-literals@0.0.1(transitive)
+ Addedbabel-plugin-minify-replace@0.0.1(transitive)
+ Addedbabel-plugin-minify-simplify@0.0.5(transitive)
+ Addedbabel-plugin-minify-type-constructors@0.0.2(transitive)
+ Addedbabel-plugin-transform-member-expression-literals@6.9.4(transitive)
+ Addedbabel-plugin-transform-merge-sibling-variables@6.9.5(transitive)
+ Addedbabel-plugin-transform-minify-booleans@6.9.4(transitive)
+ Addedbabel-plugin-transform-property-literals@6.9.4(transitive)
+ Addedbabel-plugin-transform-regexp-constructors@0.0.3(transitive)
+ Addedbabel-plugin-transform-remove-undefined@0.0.3(transitive)
+ Addedbabel-plugin-transform-simplify-comparison-operators@6.9.4(transitive)
+ Addedbabel-plugin-transform-undefined-to-void@6.9.4(transitive)
+ Addedbabel-preset-babili@0.0.9(transitive)
+ Addedbabel-register@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddetect-indent@4.0.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedglobals@9.18.0(transitive)
+ Addedhome-or-tmp@2.0.0(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedjs-tokens@3.0.2(transitive)
+ Addedjsesc@1.3.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.some@4.6.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedms@2.0.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedslash@1.0.0(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-support@0.4.18(transitive)
+ Addedto-fast-properties@1.0.3(transitive)
+ Addedtrim-right@1.0.1(transitive)