Skip to content

Commit 4bb6c5d

Browse files
committed
Refactor code-style
1 parent 8132587 commit 4bb6c5d

File tree

5 files changed

+57
-46
lines changed

5 files changed

+57
-46
lines changed

.prettierignore

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

index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
/* Dependencies. */
2-
var is = require('hast-util-is-element');
3-
var has = require('hast-util-has-property');
4-
var embedded = require('hast-util-embedded');
5-
var bodyOKLink = require('hast-util-is-body-ok-link');
1+
var is = require('hast-util-is-element')
2+
var has = require('hast-util-has-property')
3+
var embedded = require('hast-util-embedded')
4+
var bodyOKLink = require('hast-util-is-body-ok-link')
65

7-
/* Expose. */
8-
module.exports = phrasing;
6+
module.exports = phrasing
97

10-
/* Constants. */
118
var list = [
129
'a',
1310
'abbr',
@@ -57,13 +54,14 @@ var list = [
5754
'u',
5855
'var',
5956
'wbr'
60-
];
57+
]
6158

62-
/* Check if `node` is phrasing content. */
6359
function phrasing(node) {
64-
return node.type === 'text' ||
60+
return (
61+
node.type === 'text' ||
6562
is(node, list) ||
6663
embedded(node) ||
6764
bodyOKLink(node) ||
68-
(is(node, 'meta') && has(node, 'itemProp'));
65+
(is(node, 'meta') && has(node, 'itemProp'))
66+
)
6967
}

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,38 @@
3131
"esmangle": "^1.0.0",
3232
"hastscript": "^3.0.1",
3333
"nyc": "^12.0.0",
34+
"prettier": "^1.13.5",
3435
"remark-cli": "^5.0.0",
3536
"remark-preset-wooorm": "^4.0.0",
3637
"tape": "^4.4.0",
3738
"unist-builder": "^1.0.2",
3839
"xo": "^0.21.0"
3940
},
4041
"scripts": {
41-
"build-md": "remark . -qfo",
42+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
4243
"build-bundle": "browserify index.js -s hastUtilPhrasing > hast-util-phrasing.js",
4344
"build-mangle": "esmangle hast-util-phrasing.js > hast-util-phrasing.min.js",
44-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
45-
"lint": "xo",
45+
"build": "npm run build-bundle && npm run build-mangle",
4646
"test-api": "node test",
4747
"test-coverage": "nyc --reporter lcov tape test.js",
48-
"test": "npm run build && npm run lint && npm run test-coverage"
48+
"test": "npm run format && npm run build && npm run test-coverage"
4949
},
5050
"nyc": {
5151
"check-coverage": true,
5252
"lines": 100,
5353
"functions": 100,
5454
"branches": 100
5555
},
56+
"prettier": {
57+
"tabWidth": 2,
58+
"useTabs": false,
59+
"singleQuote": true,
60+
"bracketSpacing": false,
61+
"semi": false,
62+
"trailingComma": "none"
63+
},
5664
"xo": {
57-
"space": true,
65+
"prettier": true,
5866
"esnext": false,
5967
"ignores": [
6068
"hast-util-phrasing.js"

readme.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,37 @@ npm install hast-util-phrasing
1313
## Usage
1414

1515
```javascript
16-
// Dependencies:
17-
var phrasing = require('hast-util-phrasing');
16+
var phrasing = require('.')
1817

1918
// Given flow content:
2019
phrasing({
2120
type: 'element',
2221
tagName: 'div',
2322
children: [{type: 'text', value: 'Alpha'}]
24-
});
25-
//=> false
23+
})
24+
// => false
2625

2726
// Given a phrasing element:
2827
phrasing({
2928
type: 'element',
3029
tagName: 'meta',
3130
properties: {itemProp: 'bravo'},
3231
children: []
33-
});
34-
//=> true
32+
})
33+
// => true
3534

3635
// Given a non-phrasing element:
3736
phrasing({
3837
type: 'element',
3938
tagName: 'meta',
4039
properties: {charSet: 'utf8'},
4140
children: []
42-
});
43-
//=> false
41+
})
42+
// => false
4443

4544
// Given text:
46-
phrasing({type: 'text', value: 'Delta'});
47-
//=> true
45+
phrasing({type: 'text', value: 'Delta'})
46+
// => true
4847
```
4948

5049
## API
@@ -55,7 +54,7 @@ Check if the given value is a [**phrasing**][spec] content.
5554

5655
###### Parameters
5756

58-
`node` (`*`) — Value to check.
57+
* `node` (`*`) — Value to check.
5958

6059
###### Returns
6160

test.js

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

3-
var test = require('tape');
4-
var u = require('unist-builder');
5-
var h = require('hastscript');
6-
var phrasing = require('.');
3+
var test = require('tape')
4+
var u = require('unist-builder')
5+
var h = require('hastscript')
6+
var phrasing = require('.')
77

8-
test('phrasing()', function (t) {
9-
t.notOk(phrasing(h('div', 'Alpha')), 'flow');
10-
t.ok(phrasing(h('meta', {itemProp: 'bravo'})), 'meta w/ itemProp');
11-
t.notOk(phrasing(h('meta', {charSet: 'utf8'})), 'meta w/o itemProp');
12-
t.ok(phrasing(u('text', 'charlie')), 'text');
13-
t.ok(phrasing(u('text', '\n\t')), 'inter-element white-space');
14-
t.ok(phrasing(h('a', {href: '/'}, 'Delta')), 'listed elements (a)');
15-
t.ok(phrasing(h('b', {id: 'echo'}, 'Foxtrott')), 'listed elements (b)');
16-
t.ok(phrasing(h('wbr')), 'listed elements (wbr)');
17-
t.ok(phrasing(h('svg')), 'embedded content');
18-
t.ok(phrasing(h('link', {rel: ['stylesheet'], href: 'index.css'})), 'body-ok links');
8+
test('phrasing()', function(t) {
9+
t.notOk(phrasing(h('div', 'Alpha')), 'flow')
10+
t.ok(phrasing(h('meta', {itemProp: 'bravo'})), 'meta w/ itemProp')
11+
t.notOk(phrasing(h('meta', {charSet: 'utf8'})), 'meta w/o itemProp')
12+
t.ok(phrasing(u('text', 'charlie')), 'text')
13+
t.ok(phrasing(u('text', '\n\t')), 'inter-element white-space')
14+
t.ok(phrasing(h('a', {href: '/'}, 'Delta')), 'listed elements (a)')
15+
t.ok(phrasing(h('b', {id: 'echo'}, 'Foxtrott')), 'listed elements (b)')
16+
t.ok(phrasing(h('wbr')), 'listed elements (wbr)')
17+
t.ok(phrasing(h('svg')), 'embedded content')
18+
t.ok(
19+
phrasing(h('link', {rel: ['stylesheet'], href: 'index.css'})),
20+
'body-ok links'
21+
)
1922

20-
t.end();
21-
});
23+
t.end()
24+
})

0 commit comments

Comments
 (0)