Skip to content

Commit 6e8f3dc

Browse files
committed
Refactor code-style
1 parent e662c13 commit 6e8f3dc

File tree

5 files changed

+220
-192
lines changed

5 files changed

+220
-192
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
nlcst-normalize.js
3+
nlcst-normalize.min.js

index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
'use strict';
1+
'use strict'
22

3-
var toString = require('nlcst-to-string');
3+
var toString = require('nlcst-to-string')
44

5-
module.exports = normalize;
5+
module.exports = normalize
66

7-
var ALL = /[-']/g;
8-
var DASH = /-/g;
9-
var APOSTROPHE = //g;
10-
var QUOTE = '\'';
11-
var EMPTY = '';
7+
var ALL = /[-']/g
8+
var DASH = /-/g
9+
var APOSTROPHE = //g
10+
var QUOTE = "'"
11+
var EMPTY = ''
1212

1313
/* Normalize `value`. */
1414
function normalize(value, options) {
15-
var settings = options || {};
16-
var allowApostrophes = settings.allowApostrophes;
17-
var allowDashes = settings.allowDashes;
15+
var settings = options || {}
16+
var allowApostrophes = settings.allowApostrophes
17+
var allowDashes = settings.allowDashes
1818
var result = (typeof value === 'string' ? value : toString(value))
1919
.toLowerCase()
20-
.replace(APOSTROPHE, QUOTE);
20+
.replace(APOSTROPHE, QUOTE)
2121

2222
if (allowApostrophes && allowDashes) {
23-
return result;
23+
return result
2424
}
2525

2626
if (allowApostrophes) {
27-
return result.replace(DASH, EMPTY);
27+
return result.replace(DASH, EMPTY)
2828
}
2929

3030
if (allowDashes) {
31-
return result.replace(QUOTE, EMPTY);
31+
return result.replace(QUOTE, EMPTY)
3232
}
3333

34-
return result.replace(ALL, EMPTY);
34+
return result.replace(ALL, EMPTY)
3535
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,37 @@
2222
"browserify": "^16.0.0",
2323
"esmangle": "^1.0.0",
2424
"nyc": "^11.0.0",
25+
"prettier": "^1.12.1",
2526
"remark-cli": "^5.0.0",
2627
"remark-preset-wooorm": "^4.0.0",
2728
"tape": "^4.0.0",
2829
"xo": "^0.20.0"
2930
},
3031
"scripts": {
31-
"build-md": "remark . --quiet --frail --output",
32+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3233
"build-bundle": "browserify index.js --bare -s nlcstNormalize > nlcst-normalize.js",
3334
"build-mangle": "esmangle nlcst-normalize.js > nlcst-normalize.min.js",
34-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
35-
"lint": "xo",
36-
"test-api": "node test.js",
35+
"build": "npm run build-bundle && npm run build-mangle",
36+
"test-api": "node test",
3737
"test-coverage": "nyc --reporter lcov tape test.js",
38-
"test": "npm run build && npm run lint && npm run test-coverage"
38+
"test": "npm run format && npm run build && npm run test-coverage"
3939
},
4040
"nyc": {
4141
"check-coverage": true,
4242
"lines": 100,
4343
"functions": 100,
4444
"branches": 100
4545
},
46+
"prettier": {
47+
"tabWidth": 2,
48+
"useTabs": false,
49+
"singleQuote": true,
50+
"bracketSpacing": false,
51+
"semi": false,
52+
"trailingComma": "none"
53+
},
4654
"xo": {
47-
"space": true,
55+
"prettier": true,
4856
"esnext": false,
4957
"rules": {
5058
"guard-for-in": "off",

readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ npm install nlcst-normalize
1313
## Usage
1414

1515
```js
16-
var normalize = require('nlcst-normalize');
16+
var normalize = require('nlcst-normalize')
1717

18-
normalize('Don\'t'); //=> 'dont'
19-
normalize('Don’t'); //=> 'dont'
20-
normalize('Don’t', {allowApostrophes: true}); //=> 'don\'t'
21-
normalize('Block-level'); //=> 'blocklevel'
22-
normalize('Block-level', {allowDashes: true}); //=> 'block-level'
18+
normalize("Don't") // => 'dont'
19+
normalize('Don’t') // => 'dont'
20+
normalize('Don’t', {allowApostrophes: true}) // => 'don\'t'
21+
normalize('Block-level') // => 'blocklevel'
22+
normalize('Block-level', {allowDashes: true}) // => 'block-level'
2323

2424
normalize({
2525
type: 'WordNode',
@@ -28,7 +28,7 @@ normalize({
2828
{type: 'PunctuationNode', value: '-'},
2929
{type: 'TextNode', value: 'level'}
3030
]
31-
}); //=> 'blocklevel'
31+
}) // => 'blocklevel'
3232
```
3333

3434
## API

0 commit comments

Comments
 (0)