Skip to content

Commit 4a38f2c

Browse files
committed
Refactor code-style
1 parent afa3356 commit 4a38f2c

File tree

5 files changed

+76
-53
lines changed

5 files changed

+76
-53
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-has-property.js
3+
hast-util-has-property.min.js

index.js

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

3-
var own = {}.hasOwnProperty;
3+
var own = {}.hasOwnProperty
44

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

77
/* Check if `node` has a set `name` property. */
88
function hasProperty(node, name) {
9-
var props;
10-
var value;
9+
var props
10+
var value
1111

1212
if (!node || !name || typeof node !== 'object' || node.type !== 'element') {
13-
return false;
13+
return false
1414
}
1515

16-
props = node.properties;
17-
value = props && own.call(props, name) && props[name];
16+
props = node.properties
17+
value = props && own.call(props, name) && props[name]
1818

19-
return value !== null && value !== undefined && value !== false;
19+
return value !== null && value !== undefined && value !== false
2020
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,31 @@
2323
"browserify": "^16.0.0",
2424
"esmangle": "^1.0.1",
2525
"nyc": "^12.0.0",
26+
"prettier": "^1.13.5",
2627
"remark-cli": "^5.0.0",
2728
"remark-preset-wooorm": "^4.0.0",
2829
"tape": "^4.4.0",
2930
"xo": "^0.21.0"
3031
},
3132
"scripts": {
32-
"build-md": "remark . --quiet --frail --output",
33+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3334
"build-bundle": "browserify index.js --bare -s hastUtilHasProperty > hast-util-has-property.js",
3435
"build-mangle": "esmangle hast-util-has-property.js > hast-util-has-property.min.js",
35-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
36-
"lint": "xo",
37-
"test-api": "node test.js",
36+
"build": "npm run build-bundle && npm run build-mangle",
37+
"test-api": "node test",
3838
"test-coverage": "nyc --reporter lcov tape test.js",
39-
"test": "npm run build && npm run lint && npm run test-coverage"
39+
"test": "npm run format && npm run build && npm run test-coverage"
40+
},
41+
"prettier": {
42+
"tabWidth": 2,
43+
"useTabs": false,
44+
"singleQuote": true,
45+
"bracketSpacing": false,
46+
"semi": false,
47+
"trailingComma": "none"
4048
},
4149
"xo": {
42-
"space": true,
50+
"prettier": true,
4351
"esnext": false,
4452
"ignores": [
4553
"hast-util-has-property.js"

readme.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,29 @@ npm install hast-util-has-property
1313
## Usage
1414

1515
```javascript
16-
var has = require('hast-util-has-property');
17-
18-
has({type: 'text', value: 'alpha'}, 'bravo'); //=> false
19-
20-
has({
21-
type: 'element',
22-
tagName: 'div',
23-
properties: {id: 'bravo'},
24-
children: []
25-
}, 'className'); //=> false
26-
27-
has({
28-
type: 'element',
29-
tagName: 'div',
30-
properties: {id: 'charlie'},
31-
children: []
32-
}, 'id'); // => true
16+
var has = require('hast-util-has-property')
17+
18+
has({type: 'text', value: 'alpha'}, 'bravo') // => false
19+
20+
has(
21+
{
22+
type: 'element',
23+
tagName: 'div',
24+
properties: {id: 'bravo'},
25+
children: []
26+
},
27+
'className'
28+
) // => false
29+
30+
has(
31+
{
32+
type: 'element',
33+
tagName: 'div',
34+
properties: {id: 'charlie'},
35+
children: []
36+
},
37+
'id'
38+
) // => true
3339
```
3440

3541
## API

test.js

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

3-
var test = require('tape');
4-
var hasProperty = require('.');
3+
var test = require('tape')
4+
var hasProperty = require('.')
55

6-
test('hasProperty', function (t) {
6+
test('hasProperty', function(t) {
77
t.equal(
88
hasProperty(null, 'alpha'),
99
false,
1010
'should return `false` without node'
11-
);
11+
)
1212

1313
t.equal(
1414
hasProperty({type: 'text', value: 'alpha'}, 'bravo'),
1515
false,
1616
'should return `false` without `element`'
17-
);
17+
)
1818

1919
t.equal(
2020
hasProperty({type: 'element'}, 'charlie'),
2121
false,
2222
'should return `false` without properties'
23-
);
23+
)
2424

2525
t.equal(
2626
hasProperty({type: 'element', properties: {}}, 'toString'),
2727
false,
2828
'should return `false` for prototypal properties'
29-
);
29+
)
3030

3131
t.equal(
32-
hasProperty({
33-
type: 'element',
34-
properties: {id: 'delta'}
35-
}, 'echo'),
32+
hasProperty(
33+
{
34+
type: 'element',
35+
properties: {id: 'delta'}
36+
},
37+
'echo'
38+
),
3639
false,
3740
'should return `false` if the property does not exist'
38-
);
41+
)
3942

4043
t.equal(
4144
hasProperty({
@@ -44,16 +47,19 @@ test('hasProperty', function (t) {
4447
}),
4548
false,
4649
'should return `false` if without `name`'
47-
);
50+
)
4851

4952
t.equal(
50-
hasProperty({
51-
type: 'element',
52-
properties: {id: 'delta'}
53-
}, 'id'),
53+
hasProperty(
54+
{
55+
type: 'element',
56+
properties: {id: 'delta'}
57+
},
58+
'id'
59+
),
5460
true,
5561
'should return `true` if the property does exist'
56-
);
62+
)
5763

58-
t.end();
59-
});
64+
t.end()
65+
})

0 commit comments

Comments
 (0)