Skip to content

Commit 3d0ac6e

Browse files
committed
Refactor code-style
1 parent 1994918 commit 3d0ac6e

File tree

5 files changed

+525
-978
lines changed

5 files changed

+525
-978
lines changed

.editorconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ root = true
22

33
[*]
44
indent_style = space
5-
indent_size = 4
5+
indent_size = 2
66
end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10-
11-
[*.{json,remarkrc,eslintrc,sh}]
12-
indent_size = 2
13-
14-
[*.md]
15-
trim_trailing_whitespace = false

index.js

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,35 @@
1-
/**
2-
* @author Titus Wormer
3-
* @copyright 2016 Titus Wormer
4-
* @license MIT
5-
* @module nlcst:normalize
6-
* @fileoverview Normalize a word for easier comparison.
7-
*/
8-
91
'use strict';
102

11-
/* eslint-env commonjs */
12-
13-
/*
14-
* Dependencies.
15-
*/
16-
173
var toString = require('nlcst-to-string');
184

19-
/*
20-
* Constants.
21-
*/
5+
module.exports = normalize;
226

237
var ALL = /[-']/g;
248
var DASH = /-/g;
259
var APOSTROPHE = //g;
2610
var QUOTE = '\'';
2711
var EMPTY = '';
2812

29-
/**
30-
* Normalize `value`.
31-
*
32-
* @param {string} value - Value to normalize.
33-
* @param {Object?} options - Control stripping
34-
* apostrophes and dashes.
35-
* @return {string} - Normalized `value`.
36-
*/
13+
/* Normalize `value`. */
3714
function normalize(value, options) {
38-
var settings = options || {};
39-
var allowApostrophes = settings.allowApostrophes;
40-
var allowDashes = settings.allowDashes;
41-
var result = (typeof value === 'string' ? value : toString(value))
42-
.toLowerCase()
43-
.replace(APOSTROPHE, QUOTE);
44-
45-
if (allowApostrophes && allowDashes) {
46-
return result;
47-
}
48-
49-
if (allowApostrophes) {
50-
return result.replace(DASH, EMPTY);
51-
}
52-
53-
if (allowDashes) {
54-
return result.replace(QUOTE, EMPTY);
55-
}
56-
57-
return result.replace(ALL, EMPTY);
15+
var settings = options || {};
16+
var allowApostrophes = settings.allowApostrophes;
17+
var allowDashes = settings.allowDashes;
18+
var result = (typeof value === 'string' ? value : toString(value))
19+
.toLowerCase()
20+
.replace(APOSTROPHE, QUOTE);
21+
22+
if (allowApostrophes && allowDashes) {
23+
return result;
24+
}
25+
26+
if (allowApostrophes) {
27+
return result.replace(DASH, EMPTY);
28+
}
29+
30+
if (allowDashes) {
31+
return result.replace(QUOTE, EMPTY);
32+
}
33+
34+
return result.replace(ALL, EMPTY);
5835
}
59-
60-
/*
61-
* Expose.
62-
*/
63-
64-
module.exports = normalize;

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,32 @@
2323
},
2424
"devDependencies": {
2525
"browserify": "^13.0.0",
26-
"eslint": "^1.0.0",
2726
"esmangle": "^1.0.0",
2827
"istanbul": "^0.4.0",
29-
"jscs": "^2.0.0",
30-
"jscs-jsdoc": "^1.0.0",
3128
"remark": "^3.0.0",
3229
"remark-comment-config": "^2.0.2",
3330
"remark-github": "^2.0.0",
3431
"remark-lint": "^2.0.2",
3532
"remark-slug": "^3.0.1",
3633
"remark-validate-links": "^2.0.2",
3734
"remark-yaml-config": "^2.0.0",
38-
"tape": "^4.0.0"
35+
"tape": "^4.0.0",
36+
"xo": "^0.17.1"
3937
},
4038
"scripts": {
4139
"build-md": "remark . --quiet --frail",
4240
"build-bundle": "browserify index.js --bare -s nlcstNormalize > nlcst-normalize.js",
4341
"build-mangle": "esmangle nlcst-normalize.js > nlcst-normalize.min.js",
4442
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
45-
"lint-api": "eslint .",
46-
"lint-style": "jscs --reporter inline .",
47-
"lint": "npm run lint-api && npm run lint-style",
43+
"lint": "xo",
4844
"test-api": "node test.js",
4945
"test-coverage": "istanbul cover test.js",
5046
"test": "npm run build && npm run lint && npm run test-coverage"
47+
},
48+
"xo": {
49+
"space": true,
50+
"ignore": [
51+
"nlcst-normalize.js"
52+
]
5153
}
5254
}

readme.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,19 @@ AMD, CommonJS, and globals module, [uncompressed and compressed][releases].
1818
```js
1919
var normalize = require('nlcst-normalize');
2020

21-
normalize('Don’t'); // 'dont'
22-
normalize('Don\'t'); // 'dont'
23-
normalize('Block-level'); // 'blocklevel'
24-
normalize('Don’t', true); // 'don\'t'
21+
normalize('Don’t'); //=> 'dont'
22+
normalize('Don\'t'); //=> 'dont'
23+
normalize('Block-level'); //=> 'blocklevel'
24+
normalize('Don’t', true); //=> 'don\'t'
2525

2626
normalize({
27-
'type': 'WordNode',
28-
'children': [
29-
{
30-
'type': 'TextNode',
31-
'value': 'Block'
32-
},
33-
{
34-
'type': 'PunctuationNode',
35-
'value': '-'
36-
},
37-
{
38-
'type': 'TextNode',
39-
'value': 'level'
40-
}
41-
]
42-
}); // 'blocklevel'
27+
type: 'WordNode',
28+
children: [
29+
{type: 'TextNode', value: 'Block'},
30+
{type: 'PunctuationNode', value: '-'},
31+
{type: 'TextNode', value: 'level'}
32+
]
33+
}); //=> 'blocklevel'
4334
```
4435

4536
## API

0 commit comments

Comments
 (0)