Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 34fea6d

Browse files
committed
Refactor code-style
1 parent 3d6b4e8 commit 34fea6d

File tree

5 files changed

+77
-68
lines changed

5 files changed

+77
-68
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-menu-state.js
3+
hast-util-menu-state.min.js

index.js

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

3-
var is = require('hast-util-is-element');
3+
var is = require('hast-util-is-element')
44

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

77
/* Check the state of the menu `node`. */
88
function menuState(nodes) {
9-
var index;
10-
var node;
11-
var type;
9+
var index
10+
var node
11+
var type
1212

1313
if (!nodes || typeof nodes !== 'object' || nodes.length === 0) {
14-
return null;
14+
return null
1515
}
1616

17-
index = nodes.length - 1;
18-
node = nodes[index];
17+
index = nodes.length - 1
18+
node = nodes[index]
1919

2020
if (!is(node, 'menu')) {
21-
return null;
21+
return null
2222
}
2323

2424
while (node) {
2525
/* Stop at `template` elements and non-elements. */
2626
if (!is(node) || is(node, 'template')) {
27-
break;
27+
break
2828
}
2929

3030
if (is(node, 'menu')) {
31-
type = node.properties && node.properties.type;
31+
type = node.properties && node.properties.type
3232

3333
if (type === 'context' || type === 'toolbar') {
34-
return type;
34+
return type
3535
}
3636
}
3737

38-
node = nodes[--index];
38+
node = nodes[--index]
3939
}
4040

41-
return 'toolbar';
41+
return 'toolbar'
4242
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,31 @@
2828
"browserify": "^16.0.0",
2929
"esmangle": "^1.0.1",
3030
"nyc": "^12.0.0",
31+
"prettier": "^1.13.5",
3132
"remark-cli": "^5.0.0",
3233
"remark-preset-wooorm": "^4.0.0",
3334
"tape": "^4.4.0",
3435
"xo": "^0.21.0"
3536
},
3637
"scripts": {
37-
"build-md": "remark . --quiet --frail --output",
38+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3839
"build-bundle": "browserify index.js --bare -s hastUtilMenuState > hast-util-menu-state.js",
3940
"build-mangle": "esmangle hast-util-menu-state.js > hast-util-menu-state.min.js",
40-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
41-
"lint": "xo",
42-
"test-api": "node test.js",
41+
"build": "npm run build-bundle && npm run build-mangle",
42+
"test-api": "node test",
4343
"test-coverage": "nyc --reporter lcov tape test.js",
44-
"test": "npm run build && npm run lint && npm run test-coverage"
44+
"test": "npm run format && npm run build && npm run test-coverage"
45+
},
46+
"prettier": {
47+
"tabWidth": 2,
48+
"useTabs": false,
49+
"singleQuote": true,
50+
"bracketSpacing": false,
51+
"semi": false,
52+
"trailingComma": "none"
4553
},
4654
"xo": {
47-
"space": true,
55+
"prettier": true,
4856
"esnext": false,
4957
"ignores": [
5058
"hast-util-menu-state.js"

readme.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,21 @@ npm install hast-util-menu-state
1313
## Usage
1414

1515
```javascript
16-
var menuState = require('hast-util-menu-state');
16+
var menuState = require('hast-util-menu-state')
1717

1818
// If there’s no last element or that node is not a `menu`:
19-
menuState([{type: 'element', tagName: 'a'}]); //=> null
19+
menuState([{type: 'element', tagName: 'a'}]) // => null
2020

2121
// If the last node is a `menu` without `type`:
22-
menuState([{type: 'element', tagName: 'menu'}]); //=> 'toolbar'
22+
menuState([{type: 'element', tagName: 'menu'}]) // => 'toolbar'
2323

2424
// If the last node is a `menu` with a `type`, or that node has
2525
// a parent `menu` with a type:
2626
menuState([
27-
{
28-
type: 'element',
29-
tagName: 'menu',
30-
properties: {type: 'context'}
31-
},
32-
{
33-
type: 'element',
34-
tagName: 'li'
35-
},
36-
{
37-
type: 'element',
38-
tagName: 'menu'
39-
}
40-
]); //=> 'context'
27+
{type: 'element', tagName: 'menu', properties: {type: 'context'}},
28+
{type: 'element', tagName: 'li'},
29+
{type: 'element', tagName: 'menu'}
30+
]) // => 'context'
4131
```
4232

4333
## API

test.js

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,59 @@
1-
'use strict';
1+
'use strict'
22

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

6-
test('menuState', function (t) {
7-
t.equal(menuState(), null, 'should return `null` without nodes');
8-
t.equal(menuState(null), null, 'should return `null` with `null`');
9-
t.equal(menuState([]), null, 'should return `null` with empty `nodes`');
10-
t.equal(menuState(['foo']), null, 'should return `null` without `node` as last `node`');
6+
test('menuState', function(t) {
7+
t.equal(menuState(), null, 'should return `null` without nodes')
8+
t.equal(menuState(null), null, 'should return `null` with `null`')
9+
t.equal(menuState([]), null, 'should return `null` with empty `nodes`')
10+
t.equal(
11+
menuState(['foo']),
12+
null,
13+
'should return `null` without `node` as last `node`'
14+
)
1115

1216
t.equal(
1317
menuState([{type: 'text', value: 'alpha'}]),
1418
null,
1519
'should return `null` without `element` as last `node`'
16-
);
20+
)
1721

1822
t.equal(
1923
menuState([{type: 'element', tagName: 'div'}]),
2024
null,
2125
'should return `null` without `menu` as last `node`'
22-
);
26+
)
2327

2428
t.equal(
2529
menuState([{type: 'element', tagName: 'menu'}]),
2630
'toolbar',
2731
'should return `toolbar` without `type` on last `menu`'
28-
);
32+
)
2933

3034
t.equal(
31-
menuState([{
32-
type: 'element',
33-
tagName: 'menu',
34-
properties: {type: 'toolbar'}
35-
}]),
35+
menuState([
36+
{
37+
type: 'element',
38+
tagName: 'menu',
39+
properties: {type: 'toolbar'}
40+
}
41+
]),
3642
'toolbar',
3743
'should return `toolbar` with `type` set to `toolbar` on last `menu`'
38-
);
44+
)
3945

4046
t.equal(
41-
menuState([{
42-
type: 'element',
43-
tagName: 'menu',
44-
properties: {type: 'context'}
45-
}]),
47+
menuState([
48+
{
49+
type: 'element',
50+
tagName: 'menu',
51+
properties: {type: 'context'}
52+
}
53+
]),
4654
'context',
4755
'should return `context` with `type` set to `context` on last `menu`'
48-
);
56+
)
4957

5058
t.equal(
5159
menuState([
@@ -58,7 +66,7 @@ test('menuState', function (t) {
5866
]),
5967
'context',
6068
'should return the `type` of a parent `menu`, if available'
61-
);
69+
)
6270

6371
t.equal(
6472
menuState([
@@ -67,7 +75,7 @@ test('menuState', function (t) {
6775
]),
6876
'toolbar',
6977
'should return the `toolbar` of no parent `menu` is available'
70-
);
78+
)
7179

7280
t.equal(
7381
menuState([
@@ -81,7 +89,7 @@ test('menuState', function (t) {
8189
]),
8290
'toolbar',
8391
'should not walk higher than `template` elements'
84-
);
92+
)
8593

8694
t.equal(
8795
menuState([
@@ -95,7 +103,7 @@ test('menuState', function (t) {
95103
]),
96104
'toolbar',
97105
'should not walk higher than non-elements'
98-
);
106+
)
99107

100108
t.equal(
101109
menuState([
@@ -109,7 +117,7 @@ test('menuState', function (t) {
109117
]),
110118
'context',
111119
'should not walk higher than other elements'
112-
);
120+
)
113121

114-
t.end();
115-
});
122+
t.end()
123+
})

0 commit comments

Comments
 (0)