Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 14, 2018
1 parent f8ed47e commit c29751f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
collapse-white-space.js
collapse-white-space.min.js
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
'use strict'

module.exports = collapse;
module.exports = collapse

/* collapse(' \t\nbar \nbaz\t'); // ' bar baz ' */
function collapse(value) {
return String(value).replace(/\s+/g, ' ');
return String(value).replace(/\s+/g, ' ')
}
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@
"xo": "^0.20.0"
},
"scripts": {
"build-md": "remark . -qfo",
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify index.js --bare -s collapseWhiteSpace > collapse-white-space.js",
"build-mangle": "esmangle collapse-white-space.js > collapse-white-space.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
"test": "npm run format && npm run build && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,
"rules": {
"capitalized-comments": "off",
Expand All @@ -53,5 +60,11 @@
"plugins": [
"preset-wooorm"
]
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
}
}
20 changes: 10 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';
'use strict'

var test = require('tape');
var collapse = require('.');
var test = require('tape')
var collapse = require('.')

test('collapseWhiteSpace(value)', function (t) {
t.equal(collapse(true), 'true', 'should coerce to string');
test('collapseWhiteSpace(value)', function(t) {
t.equal(collapse(true), 'true', 'should coerce to string')

t.equal(collapse(' \t\nbar \nbaz\t'), ' bar baz ');
t.equal(collapse(' bar\t\t\tbaz\n\n\n'), ' bar baz ');
t.equal(collapse(' \n bar\t\n\tbaz\r\n'), ' bar baz ');
t.equal(collapse(' \t\nbar \nbaz\t'), ' bar baz ')
t.equal(collapse(' bar\t\t\tbaz\n\n\n'), ' bar baz ')
t.equal(collapse(' \n bar\t\n\tbaz\r\n'), ' bar baz ')

t.end();
});
t.end()
})

0 comments on commit c29751f

Please sign in to comment.