Skip to content

Commit c761844

Browse files
committed
Refactor code-style
1 parent cc9ffd5 commit c761844

File tree

5 files changed

+64
-60
lines changed

5 files changed

+64
-60
lines changed

.prettierignore

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

index.js

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

3-
var visit = require('unist-util-visit');
3+
var visit = require('unist-util-visit')
44

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

7-
var own = {}.hasOwnProperty;
7+
var own = {}.hasOwnProperty
88

99
/* Get a definition in `node` by `identifier`. */
1010
function getDefinitionFactory(node, options) {
11-
return getterFactory(gather(node, options));
11+
return getterFactory(gather(node, options))
1212
}
1313

1414
/* Gather all definitions in `node` */
1515
function gather(node, options) {
16-
var cache = {};
16+
var cache = {}
1717

1818
if (!node || !node.type) {
19-
throw new Error('mdast-util-definitions expected node');
19+
throw new Error('mdast-util-definitions expected node')
2020
}
2121

22-
visit(node, 'definition', options && options.commonmark ? commonmark : normal);
22+
visit(node, 'definition', options && options.commonmark ? commonmark : normal)
2323

24-
return cache;
24+
return cache
2525

2626
function commonmark(definition) {
27-
var id = normalise(definition.identifier);
27+
var id = normalise(definition.identifier)
2828
if (!own.call(cache, id)) {
29-
cache[id] = definition;
29+
cache[id] = definition
3030
}
3131
}
3232

3333
function normal(definition) {
34-
cache[normalise(definition.identifier)] = definition;
34+
cache[normalise(definition.identifier)] = definition
3535
}
3636
}
3737

3838
/* Factory to get a node from the given definition-cache. */
3939
function getterFactory(cache) {
40-
return getter;
40+
return getter
4141

4242
/* Get a node from the bound definition-cache. */
4343
function getter(identifier) {
44-
var id = identifier && normalise(identifier);
45-
return id && own.call(cache, id) ? cache[id] : null;
44+
var id = identifier && normalise(identifier)
45+
return id && own.call(cache, id) ? cache[id] : null
4646
}
4747
}
4848

4949
function normalise(identifier) {
50-
return identifier.toUpperCase();
50+
return identifier.toUpperCase()
5151
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"devDependencies": {
2828
"browserify": "^16.0.0",
2929
"nyc": "^12.0.0",
30+
"prettier": "^1.14.2",
3031
"remark": "^9.0.0",
3132
"remark-cli": "^5.0.0",
3233
"remark-preset-wooorm": "^4.0.0",
@@ -35,17 +36,24 @@
3536
"xo": "^0.22.0"
3637
},
3738
"scripts": {
38-
"build-md": "remark . --quiet --frail --output",
39+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3940
"build-bundle": "browserify . -s mdastUtilDefinitions > mdast-util-definitions.js",
4041
"build-mangle": "browserify . -s mdastUtilDefinitions -p tinyify > mdast-util-definitions.min.js",
41-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
42-
"lint": "xo",
43-
"test-api": "node test.js",
42+
"build": "npm run build-bundle && npm run build-mangle",
43+
"test-api": "node test",
4444
"test-coverage": "nyc --reporter lcov tape test.js",
45-
"test": "npm run build && npm run lint && npm run test-coverage"
45+
"test": "npm run format && npm run build && npm run test-coverage"
46+
},
47+
"prettier": {
48+
"tabWidth": 2,
49+
"useTabs": false,
50+
"singleQuote": true,
51+
"bracketSpacing": false,
52+
"semi": false,
53+
"trailingComma": "none"
4654
},
4755
"xo": {
48-
"space": true,
56+
"prettier": true,
4957
"esnext": false,
5058
"ignore": [
5159
"mdast-util-definitions.js"

readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ npm install mdast-util-definitions
1414
## Usage
1515

1616
```js
17-
var remark = require('remark');
18-
var definitions = require('mdast-util-definitions');
17+
var remark = require('remark')
18+
var definitions = require('mdast-util-definitions')
1919

20-
var ast = remark().parse('[example]: http://example.com "Example"');
20+
var ast = remark().parse('[example]: http://example.com "Example"')
2121

22-
var definition = definitions(ast);
22+
var definition = definitions(ast)
2323

24-
definition('example');
25-
// {type: 'definition', 'title': 'Example', ...}
24+
definition('example')
25+
// => {type: 'definition', 'title': 'Example', ...}
2626

27-
definition('foo');
28-
// null
27+
definition('foo')
28+
// => null
2929
```
3030

3131
## API

test.js

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

3-
var test = require('tape');
4-
var remark = require('remark');
5-
var definitions = require('.');
3+
var test = require('tape')
4+
var remark = require('remark')
5+
var definitions = require('.')
66

7-
test('mdast-util-definitions', function (t) {
8-
var getDefinition;
9-
var tree;
7+
test('mdast-util-definitions', function(t) {
8+
var getDefinition
9+
var tree
1010

1111
t.throws(
12-
function () {
13-
definitions();
12+
function() {
13+
definitions()
1414
},
1515
/mdast-util-definitions expected node/,
1616
'should fail without node'
17-
);
17+
)
1818

19-
tree = remark().parse('[example]: http://example.com "Example"');
20-
getDefinition = definitions(tree);
19+
tree = remark().parse('[example]: http://example.com "Example"')
20+
getDefinition = definitions(tree)
2121

2222
t.deepEqual(
2323
getDefinition('example'),
@@ -33,16 +33,12 @@ test('mdast-util-definitions', function (t) {
3333
}
3434
},
3535
'should return a definition'
36-
);
36+
)
3737

38-
t.equal(
39-
getDefinition('foo'),
40-
null,
41-
'should return null when not found'
42-
);
38+
t.equal(getDefinition('foo'), null, 'should return null when not found')
4339

44-
tree = remark().parse('[__proto__]: http://proto.com "Proto"');
45-
getDefinition = definitions(tree);
40+
tree = remark().parse('[__proto__]: http://proto.com "Proto"')
41+
getDefinition = definitions(tree)
4642

4743
t.deepEqual(
4844
getDefinition('__proto__'),
@@ -58,30 +54,27 @@ test('mdast-util-definitions', function (t) {
5854
}
5955
},
6056
'should work on weird identifiers'
61-
);
57+
)
6258

6359
t.deepEqual(
6460
getDefinition('toString'),
6561
null,
6662
'should work on weird identifiers when not found'
67-
);
63+
)
6864

69-
tree = remark().parse([
70-
'[example]: http://one.com',
71-
'[example]: http://two.com'
72-
].join('\n'));
65+
tree = remark().parse('[example]: http://one.com\n[example]: http://two.com')
7366

7467
t.deepEqual(
7568
definitions(tree)('example').url,
7669
'http://two.com',
7770
'should prefer the last of duplicate definitions by default'
78-
);
71+
)
7972

8073
t.deepEqual(
8174
definitions(tree, {commonmark: true})('example').url,
8275
'http://one.com',
8376
'should prefer the first of duplicate definitions in commonmark mode'
84-
);
77+
)
8578

86-
t.end();
87-
});
79+
t.end()
80+
})

0 commit comments

Comments
 (0)