Comparing version 1.2.1 to 1.2.2
@@ -89,4 +89,2 @@ #!/usr/bin/env node | ||
else { | ||
@@ -93,0 +91,0 @@ process.stdin.pipe(concat((data) => { |
@@ -16,10 +16,2 @@ /* Copyright 2016 Myles Borins | ||
function reggae(code) { | ||
return code.replace(/^\s+/, '').replace(/[ \t]+$/, ''); | ||
} | ||
function isNotEmpty(code) { | ||
return !((code === '') || (code === ' ')); | ||
} | ||
function minify(code, cb) { | ||
@@ -34,12 +26,23 @@ if (typeof code !== 'string') { | ||
code = code.split('\n'); | ||
code = code.filter(isNotEmpty); | ||
// 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 whitespace at the begining and end of each line | ||
code = code.map(reggae); | ||
// remove extra spaces around / | ||
code = code.replace(/(\s+)?\/(\s+)?/g, '/'); | ||
code = code.join(' '); | ||
// remove extra spaces around = | ||
code = code.replace(/(\s+)?\=(\s+)?/g, '='); | ||
// remove any spaces after a semi colon | ||
code = code.replace(/;\s+/g, ';'); | ||
// remove spaces at the begining | ||
code = code.replace(/^\s+/, ''); | ||
} | ||
@@ -46,0 +49,0 @@ catch (e) { |
{ | ||
"name": "esmall", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Pretty Naive", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -5,5 +5,11 @@ # esmall | ||
## 📛 WARNING 📛 | ||
This is super jank, likely to break your code. | ||
For best results use semi colons! | ||
## How it works | ||
Does a little reggae | ||
Does a little [reggae](https://twitter.com/thealphanerd/status/764133752905883649) | ||
@@ -10,0 +16,0 @@ ## Using the cli |
@@ -23,6 +23,7 @@ /* Copyright 2016 Myles Borins | ||
var b = '456'; | ||
console.log('a + b'); | ||
var c = 123456; | ||
console.log('a + b * c / d'); | ||
`; | ||
var expected = 'var a = \'123\';var b = \'456\';console.log(\'a + b\');'; | ||
var expected = 'var a=\'123\';var b=\'456\';var c=123456;console.log(\'a+b*c/d\');'; | ||
@@ -47,3 +48,4 @@ var licensedCode = ` | ||
var b = '456'; // this comment should be removed | ||
console.log('a + b'); | ||
var c = 123456; | ||
console.log('a + b * c / d'); | ||
`; | ||
@@ -53,5 +55,14 @@ | ||
var a = '123'; var b = '456'; // this comment should be removed | ||
console.log('a + b'); | ||
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) => { | ||
@@ -73,2 +84,10 @@ t.plan(2); | ||
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) => { | ||
@@ -75,0 +94,0 @@ t.plan(2); |
94865
238
46