Skip to content

Commit 2de2cbf

Browse files
committed
Refactor code-style
1 parent ee1182f commit 2de2cbf

File tree

5 files changed

+81
-131
lines changed

5 files changed

+81
-131
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: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,23 @@
1-
/**
2-
* @author Titus Wormer
3-
* @copyright 2016 Titus Wormer
4-
* @license MIT
5-
* @module hast:util:whitespace
6-
* @fileoverview Check whether a node is inter-element
7-
* whitespace.
8-
*/
9-
101
'use strict';
112

12-
/* eslint-env commonjs */
13-
14-
/*
15-
* HTML white-space expression.
16-
*
17-
* See <https://html.spec.whatwg.org/#space-character>.
18-
*/
3+
/* Expose. */
4+
module.exports = interElementWhiteSpace;
195

20-
var EXPRESSION = /[\ \t\n\f\r]/g;
6+
/* HTML white-space expression.
7+
* See <https://html.spec.whatwg.org/#space-character>. */
8+
var re = /[ \t\n\f\r]/g;
219

22-
/**
23-
* Check if `node` is a inter-element white-space.
24-
*
25-
* @param {Node|string} node - Value to check, or Node
26-
* whose value to check.
27-
* @return {boolean} - Whether `node` is inter-element
28-
* white-space.
29-
*/
10+
/* Check if `node` is a inter-element white-space. */
3011
function interElementWhiteSpace(node) {
31-
var value;
12+
var value;
3213

33-
if (node && typeof node === 'object' && node.type === 'text') {
34-
value = node.value || ''
35-
} else if (typeof node === 'string') {
36-
value = node;
37-
} else {
38-
return false;
39-
}
14+
if (node && typeof node === 'object' && node.type === 'text') {
15+
value = node.value || '';
16+
} else if (typeof node === 'string') {
17+
value = node;
18+
} else {
19+
return false;
20+
}
4021

41-
return value.replace(EXPRESSION, '') === '';
22+
return value.replace(re, '') === '';
4223
}
43-
44-
/*
45-
* Expose.
46-
*/
47-
48-
module.exports = interElementWhiteSpace;

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,31 @@
2727
],
2828
"devDependencies": {
2929
"browserify": "^13.0.0",
30-
"eslint": "^2.0.0",
3130
"esmangle": "^1.0.1",
3231
"istanbul": "^0.4.0",
33-
"jscs": "^3.0.0",
34-
"jscs-jsdoc": "^2.0.0",
3532
"remark": "^4.0.0",
3633
"remark-comment-config": "^3.0.0",
3734
"remark-github": "^4.0.1",
3835
"remark-lint": "^3.0.0",
3936
"remark-usage": "^3.0.0",
4037
"remark-validate-links": "^3.0.0",
41-
"tape": "^4.4.0"
38+
"tape": "^4.4.0",
39+
"xo": "^0.17.0"
4240
},
4341
"scripts": {
4442
"build-md": "remark . --quiet --frail",
4543
"build-bundle": "browserify index.js --bare -s hastUtilWhitespace > hast-util-whitespace.js",
4644
"build-mangle": "esmangle hast-util-whitespace.js > hast-util-whitespace.min.js",
4745
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
48-
"lint-api": "eslint .",
49-
"lint-style": "jscs --reporter inline .",
50-
"lint": "npm run lint-api && npm run lint-style",
46+
"lint": "xo",
5147
"test-api": "node test.js",
5248
"test-coverage": "istanbul cover test.js",
5349
"test": "npm run build && npm run lint && npm run test-coverage"
50+
},
51+
"xo": {
52+
"space": true,
53+
"ignores": [
54+
"hast-util-is-element.js"
55+
]
5456
}
5557
}

readme.md

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,22 @@ Dependencies:
2020

2121
```javascript
2222
var whitespace = require('hast-util-whitespace');
23-
```
24-
25-
Checks:
26-
27-
```javascript
28-
var a = whitespace({
29-
'type': 'element',
30-
'tagName': 'div',
31-
'children': []
32-
});
33-
var b = whitespace({
34-
'type': 'text',
35-
'value': '\t \n'
36-
});
37-
var c = whitespace({
38-
'type': 'text',
39-
'value': ' text\f'
40-
});
41-
```
42-
43-
Yields:
4423

45-
```txt
46-
a: false
47-
b: true
48-
c: false
24+
whitespace({
25+
type: 'element',
26+
tagName: 'div',
27+
children: []
28+
}); //=> false
29+
30+
whitespace({
31+
type: 'text',
32+
value: '\t \n'
33+
}); //=> true
34+
35+
whitespace({
36+
type: 'text',
37+
value: ' text\f'
38+
}); //=> false
4939
```
5040

5141
## API

test.js

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,48 @@
1-
/**
2-
* @author Titus Wormer
3-
* @copyright 2016 Titus Wormer
4-
* @license MIT
5-
* @module hast:util:whitespace
6-
* @fileoverview Test suite for `whitespace`.
7-
*/
8-
91
'use strict';
102

11-
/* eslint-env node */
12-
13-
/*
14-
* Module dependencies.
15-
*/
16-
3+
/* Dependencies. */
174
var test = require('tape');
185
var whitespace = require('./index.js');
196

20-
/*
21-
* Tests.
22-
*/
23-
7+
/* Tests. */
248
test('whitespace', function (t) {
25-
t.equal(whitespace(), false, 'should return `false` without node');
26-
27-
t.equal(whitespace({
28-
'type': 'element',
29-
'tagName': 'div'
30-
}), false, 'should return `false` without text');
31-
32-
t.equal(whitespace({
33-
'type': 'text',
34-
'value': '\v'
35-
}), false, 'should return `false` for other white-space');
36-
37-
t.equal(whitespace({
38-
'type': 'text',
39-
'value': ' \t\r\n\f'
40-
}), true, 'should return `true` for inter-element white-space');
41-
42-
t.equal(whitespace({
43-
'type': 'text'
44-
}), true, 'should return `true` for `text` without value');
45-
46-
t.equal(
47-
whitespace(' \v'),
48-
false,
49-
'should return `false` for a `string` of text'
50-
);
51-
52-
t.equal(
53-
whitespace(' \t\r\n\f'),
54-
true,
55-
'should return `true` for a `string` of inter-element white-space'
56-
);
57-
58-
t.end();
9+
t.equal(whitespace(), false, 'should return `false` without node');
10+
11+
t.equal(
12+
whitespace({type: 'element', tagName: 'div'}),
13+
false,
14+
'should return `false` without text'
15+
);
16+
17+
t.equal(
18+
whitespace({type: 'text', value: '\v'}),
19+
false,
20+
'should return `false` for other white-space'
21+
);
22+
23+
t.equal(
24+
whitespace({type: 'text', value: ' \t\r\n\f'}),
25+
true,
26+
'should return `true` for inter-element white-space'
27+
);
28+
29+
t.equal(
30+
whitespace({type: 'text'}),
31+
true,
32+
'should return `true` for `text` without value'
33+
);
34+
35+
t.equal(
36+
whitespace(' \v'),
37+
false,
38+
'should return `false` for a `string` of text'
39+
);
40+
41+
t.equal(
42+
whitespace(' \t\r\n\f'),
43+
true,
44+
'should return `true` for a `string` of inter-element white-space'
45+
);
46+
47+
t.end();
5948
});

0 commit comments

Comments
 (0)