Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4c1c17e

Browse files
committedNov 8, 2018
Update build process
1 parent dbbae7c commit 4c1c17e

24 files changed

+998
-864
lines changed
 

‎.dir-locals.el

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

‎.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
/node_modules/
1+
.DS_Store
2+
*.log
3+
.nyc_output/
4+
coverage/
5+
node_modules/
6+
yarn.lock

‎.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage/

‎.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
3-
- 4
4-
- 8
3+
- lts/boron
4+
- node
5+
after_script: bash <(curl -s https://codecov.io/bash)

‎README.md

Lines changed: 0 additions & 108 deletions
This file was deleted.

‎index.js

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

3-
var parseSelector = require('./lib/selector'),
4-
matchSelector = require('./lib/select');
3+
var debug = require('debug')('unist-util-select')
4+
var parseSelector = require('./lib/selector')
5+
var matchSelector = require('./lib/select')
56

6-
var debug = require('debug')('unist-util-select');
7+
module.exports = select
78

9+
select.one = selectOne
810

9-
var select = function select (ast, selector) {
10-
if (arguments.length == 1) {
11-
return select.bind(this, ast);
11+
function select(ast, selector) {
12+
if (arguments.length === 1) {
13+
return select.bind(this, ast)
1214
}
1315

14-
debug('Selector: %j', selector);
15-
selector = parseSelector(selector);
16-
debug('AST: %s',
17-
JSON.stringify(selector, null, 2).replace(/(^|\n)/g, '\n '));
18-
return selector ? matchSelector[selector.type](selector, ast) : [];
19-
};
20-
21-
22-
select.one = function selectOne (ast, selector) {
23-
if (arguments.length == 1) {
24-
return selectOne.bind(this, ast);
16+
debug('Selector: %j', selector)
17+
selector = parseSelector(selector)
18+
debug(
19+
'AST: %s',
20+
JSON.stringify(selector, null, 2).replace(/(^|\n)/g, '\n ')
21+
)
22+
return selector ? matchSelector[selector.type](selector, ast) : []
23+
}
24+
25+
function selectOne(ast, selector) {
26+
if (arguments.length === 1) {
27+
return selectOne.bind(this, ast)
2528
}
2629

27-
var nodes = select(ast, selector);
30+
var nodes = select(ast, selector)
2831

29-
if (!nodes.length) {
30-
throw Error('Node not found by ' + JSON.stringify(selector));
32+
if (nodes.length === 0) {
33+
throw new Error('Node not found by ' + JSON.stringify(selector))
3134
}
35+
3236
if (nodes.length > 1) {
33-
throw Error('Node matched by ' + JSON.stringify(selector) + ' is not unique');
37+
throw new Error(
38+
'Node matched by ' + JSON.stringify(selector) + ' is not unique'
39+
)
3440
}
3541

36-
return nodes[0];
37-
};
38-
39-
40-
module.exports = select;
42+
return nodes[0]
43+
}

‎lib/ast-walkers.js

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

3-
var TypeIndex = require('./type-index');
4-
5-
var walkers = exports;
3+
var TypeIndex = require('./type-index')
64

5+
var walkers = exports
76

87
// All walkers accept `opts` arguments (occasionally referred to as
98
// `searchOpts`) which is an object with the following fields:
@@ -20,131 +19,126 @@ var walkers = exports;
2019
// is equal to number of siblings sharing the same type with this node
2120
//
2221

23-
24-
walkers.topScan = function (node, nodeIndex, parent, opts) {
22+
walkers.topScan = function(node, nodeIndex, parent, opts) {
23+
/* istanbul ignore if - Shouldn’t happen! */
2524
if (parent) {
2625
// We would like to avoid spinning an extra loop through the starting
2726
// node's siblings just to count its typeIndex.
28-
throw Error('topScan is supposed to be called from the root node');
27+
throw new Error('topScan is supposed to be called from the root node')
2928
}
3029

3130
if (!opts.typeIndex && !opts.typeCount) {
32-
opts.iterator(node, nodeIndex, parent);
31+
opts.iterator(node, nodeIndex, parent)
3332
}
34-
walkers.descendant.apply(this, arguments);
35-
};
36-
37-
38-
walkers.descendant = function (node, nodeIndex, parent, opts) {
39-
var iterator = opts.iterator;
33+
walkers.descendant.apply(this, arguments)
34+
}
4035

41-
opts.iterator = function (node, nodeIndex, parent) {
42-
iterator.apply(this, arguments);
43-
walkers.child(node, nodeIndex, node, opts);
44-
};
36+
walkers.descendant = function(node, nodeIndex, parent, opts) {
37+
var iterator = opts.iterator
4538

46-
return walkers.child(node, nodeIndex, parent, opts);
47-
};
39+
opts.iterator = function(node, nodeIndex) {
40+
iterator.apply(this, arguments)
41+
walkers.child(node, nodeIndex, node, opts)
42+
}
4843

44+
return walkers.child(node, nodeIndex, parent, opts)
45+
}
4946

50-
walkers.child = function (node, nodeIndex, parent, opts) {
51-
if (!node.children || !node.children.length) {
52-
return;
47+
walkers.child = function(node, nodeIndex, parent, opts) {
48+
if (!node.children || node.children.length === 0) {
49+
return
5350
}
5451

5552
walkIterator(node, opts)
5653
.each()
57-
.finally();
58-
};
59-
54+
.done()
55+
}
6056

61-
walkers.adjacentSibling = function (node, nodeIndex, parent, opts) {
57+
walkers.adjacentSibling = function(node, nodeIndex, parent, opts) {
58+
/* istanbul ignore if - Shouldn’t happen! */
6259
if (!parent) {
63-
return;
60+
return
6461
}
6562

6663
walkIterator(parent, opts)
6764
.prefillTypeIndex(0, ++nodeIndex)
6865
.each(nodeIndex, ++nodeIndex)
6966
.prefillTypeIndex(nodeIndex)
70-
.finally();
71-
};
72-
67+
.done()
68+
}
7369

74-
walkers.generalSibling = function (node, nodeIndex, parent, opts) {
70+
walkers.generalSibling = function(node, nodeIndex, parent, opts) {
7571
if (!parent) {
76-
return;
72+
return
7773
}
7874

7975
walkIterator(parent, opts)
8076
.prefillTypeIndex(0, ++nodeIndex)
8177
.each(nodeIndex)
82-
.finally();
83-
};
84-
78+
.done()
79+
}
8580

8681
// Handles typeIndex and typeCount properties for every walker.
87-
function walkIterator (parent, opts) {
88-
var hasTypeIndex = opts.typeIndex || opts.typeCount;
89-
var typeIndex = hasTypeIndex ? TypeIndex() : Function.prototype;
90-
var nodeThunks = [];
91-
92-
var rangeDefaults = function (iter) {
93-
return function (start, end) {
94-
if (start == null || start < 0) {
95-
start = 0;
82+
function walkIterator(parent, opts) {
83+
var hasTypeIndex = opts.typeIndex || opts.typeCount
84+
var typeIndex = hasTypeIndex ? new TypeIndex() : Function.prototype
85+
var nodeThunks = []
86+
87+
var rangeDefaults = function(iter) {
88+
return function(start, end) {
89+
if (start === undefined || start < 0) {
90+
start = 0
9691
}
97-
if (end == null || end > parent.children.length) {
98-
end = parent.children.length;
92+
if (end === undefined || end > parent.children.length) {
93+
end = parent.children.length
9994
}
100-
return iter.call(this, start, end);
101-
};
102-
};
95+
return iter.call(this, start, end)
96+
}
97+
}
10398

10499
return {
105-
prefillTypeIndex: rangeDefaults(function (start, end) {
100+
prefillTypeIndex: rangeDefaults(function(start, end) {
106101
if (hasTypeIndex) {
107102
for (var nodeIndex = start; nodeIndex < end; ++nodeIndex) {
108-
typeIndex(parent.children[nodeIndex]);
103+
typeIndex(parent.children[nodeIndex])
109104
}
110105
}
111-
return this;
106+
return this
112107
}),
113108

114-
each: rangeDefaults(function each (start, end) {
109+
each: rangeDefaults(function each(start, end) {
115110
if (start >= end) {
116-
return this;
111+
return this
117112
}
118113

119-
var nodeIndex = start;
120-
var node = parent.children[nodeIndex];
121-
var props = {};
122-
var nodeTypeIndex = typeIndex(node);
114+
var nodeIndex = start
115+
var node = parent.children[nodeIndex]
116+
var props = {}
117+
var nodeTypeIndex = typeIndex(node)
123118

124119
if (opts.typeIndex) {
125-
props.typeIndex = nodeTypeIndex;
120+
props.typeIndex = nodeTypeIndex
126121
}
127122

128123
if (opts.typeCount) {
129-
nodeThunks.push(function () {
130-
props.typeCount = typeIndex.count(node);
131-
pushNode();
132-
});
133-
}
134-
else {
135-
pushNode();
124+
nodeThunks.push(function() {
125+
props.typeCount = typeIndex.count(node)
126+
pushNode()
127+
})
128+
} else {
129+
pushNode()
136130
}
137131

138-
return each.call(this, start + 1, end);
132+
return each.call(this, start + 1, end)
139133

140-
function pushNode () {
141-
opts.iterator(node, nodeIndex, parent, props);
134+
function pushNode() {
135+
opts.iterator(node, nodeIndex, parent, props)
142136
}
143137
}),
144138

145-
finally: function () {
146-
nodeThunks.forEach(Function.call.bind(Function.call));
147-
return this;
139+
done: function() {
140+
nodeThunks.forEach(Function.call.bind(Function.call))
141+
return this
148142
}
149-
};
143+
}
150144
}

‎lib/collector.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
'use strict';
2-
1+
'use strict'
32

43
// @example
54
// var collect = Collector();
@@ -8,25 +7,26 @@
87
// collect.result
98
// //=> ['foo', 'bar', 'baz']
109
//
11-
module.exports = function Collector () {
12-
var result = [];
10+
module.exports = Collector
11+
12+
function Collector() {
13+
var result = []
1314

1415
// Append elements to array, filtering out duplicates.
15-
function collect (source) {
16+
function collect(source) {
1617
if (Array.isArray(source)) {
17-
source.forEach(collectOne);
18-
}
19-
else {
20-
collectOne(source);
18+
source.forEach(collectOne)
19+
} else {
20+
collectOne(source)
2121
}
2222

23-
function collectOne (element) {
23+
function collectOne(element) {
2424
if (result.indexOf(element) < 0) {
25-
result.push(element);
25+
result.push(element)
2626
}
2727
}
2828
}
2929

30-
collect.result = result;
31-
return collect;
32-
};
30+
collect.result = result
31+
return collect
32+
}

‎lib/match-node.js

Lines changed: 88 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,120 @@
1-
'use strict';
1+
'use strict'
22

3-
module.exports = matchNode;
3+
/* eslint-disable max-params */
44

5+
module.exports = matchNode
56

67
// Match node against a simple selector.
7-
function matchNode (rule, node, nodeIndex, parent, props) {
8-
return matchType(rule, node) &&
8+
function matchNode(rule, node, nodeIndex, parent, props) {
9+
return (
10+
matchType(rule, node) &&
911
matchAttrs(rule, node) &&
10-
matchPseudos(rule, node, nodeIndex, parent, props);
12+
matchPseudos(rule, node, nodeIndex, parent, props)
13+
)
1114
}
1215

13-
14-
function matchType (rule, node) {
15-
return !rule.tagName || rule.tagName == '*' || rule.tagName == node.type;
16+
function matchType(rule, node) {
17+
return !rule.tagName || rule.tagName === '*' || rule.tagName === node.type
1618
}
1719

20+
function matchAttrs(rule, node) {
21+
return !rule.attrs || rule.attrs.every(match)
1822

19-
function matchAttrs (rule, node) {
20-
return !rule.attrs || rule.attrs.every(function (attr) {
21-
switch (attr.operator) {
22-
case undefined:
23-
return attr.name in node;
24-
25-
case '=':
26-
// First, check for special values.
27-
switch (attr.value) {
28-
case 'null':
29-
if (attr.name in node && node[attr.name] == null) return true;
30-
break;
31-
32-
case 'true':
33-
if (node[attr.name] === true) return true;
34-
break;
35-
36-
case 'false':
37-
if (node[attr.name] === false) return true;
38-
break;
39-
}
40-
return node[attr.name] == attr.value;
23+
function match(attr) {
24+
if (attr.operator === undefined) {
25+
return attr.name in node
26+
}
4127

42-
case '^=':
43-
return typeof node[attr.name] == 'string' &&
44-
node[attr.name].slice(0, attr.value.length) == attr.value;
28+
if (attr.operator === '=') {
29+
return String(node[attr.name]) === attr.value
30+
}
4531

46-
case '*=':
47-
return typeof node[attr.name] == 'string' &&
48-
node[attr.name].indexOf(attr.value) >= 0;
32+
if (attr.operator === '^=') {
33+
return (
34+
typeof node[attr.name] === 'string' &&
35+
node[attr.name].slice(0, attr.value.length) === attr.value
36+
)
37+
}
4938

50-
case '$=':
51-
return typeof node[attr.name] == 'string' &&
52-
node[attr.name].slice(-attr.value.length) == attr.value;
39+
if (attr.operator === '*=') {
40+
return (
41+
typeof node[attr.name] === 'string' &&
42+
node[attr.name].indexOf(attr.value) >= 0
43+
)
44+
}
5345

54-
default:
55-
throw Error('Undefined attribute operator: ' + attr.operator);
46+
/* istanbul ignore else - shouldn’t happen */
47+
if (attr.operator === '$=') {
48+
return (
49+
typeof node[attr.name] === 'string' &&
50+
node[attr.name].slice(-attr.value.length) === attr.value
51+
)
5652
}
57-
});
58-
}
5953

54+
/* istanbul ignore next */
55+
throw new Error('Undefined attribute operator: ' + attr.operator)
56+
}
57+
}
6058

61-
function matchPseudos (rule, node, nodeIndex, parent, props) {
62-
return !rule.pseudos || rule.pseudos.every(function (pseudo) {
63-
switch (pseudo.name) {
64-
case 'root':
65-
return parent == null;
59+
function matchPseudos(rule, node, nodeIndex, parent, props) {
60+
return !rule.pseudos || rule.pseudos.every(match)
6661

67-
case 'nth-child':
68-
return parent && pseudo.value(nodeIndex);
62+
/* eslint-disable complexity */
63+
function match(pseudo) {
64+
if (pseudo.name === 'root') {
65+
return parent === null
66+
}
6967

70-
case 'nth-last-child':
71-
return parent && pseudo.value(parent.children.length - 1 - nodeIndex);
68+
if (pseudo.name === 'nth-child') {
69+
return parent && pseudo.value(nodeIndex)
70+
}
7271

73-
case 'nth-of-type':
74-
return parent && pseudo.value(props.typeIndex);
72+
if (pseudo.name === 'nth-last-child') {
73+
return parent && pseudo.value(parent.children.length - 1 - nodeIndex)
74+
}
7575

76-
case 'nth-last-of-type':
77-
return parent && pseudo.value(props.typeCount - 1 - props.typeIndex);
76+
if (pseudo.name === 'nth-of-type') {
77+
return parent && pseudo.value(props.typeIndex)
78+
}
7879

79-
case 'first-child':
80-
return parent && nodeIndex == 0;
80+
if (pseudo.name === 'nth-last-of-type') {
81+
return parent && pseudo.value(props.typeCount - 1 - props.typeIndex)
82+
}
8183

82-
case 'last-child':
83-
return parent && nodeIndex == parent.children.length - 1;
84+
if (pseudo.name === 'first-child') {
85+
return parent && nodeIndex === 0
86+
}
8487

85-
case 'first-of-type':
86-
return parent && props.typeIndex == 0;
88+
if (pseudo.name === 'last-child') {
89+
return parent && nodeIndex === parent.children.length - 1
90+
}
8791

88-
case 'last-of-type':
89-
return parent && props.typeIndex == props.typeCount - 1;
92+
if (pseudo.name === 'first-of-type') {
93+
return parent && props.typeIndex === 0
94+
}
9095

91-
case 'only-child':
92-
return parent && parent.children.length == 1;
96+
if (pseudo.name === 'last-of-type') {
97+
return parent && props.typeIndex === props.typeCount - 1
98+
}
9399

94-
case 'only-of-type':
95-
return parent && props.typeCount == 1;
100+
if (pseudo.name === 'only-child') {
101+
return parent && parent.children.length === 1
102+
}
96103

97-
case 'empty':
98-
return node.children && !node.children.length;
104+
if (pseudo.name === 'only-of-type') {
105+
return parent && props.typeCount === 1
106+
}
99107

100-
case 'not':
101-
return !matchNode(pseudo.value.rule, node, nodeIndex, parent, props);
108+
if (pseudo.name === 'empty') {
109+
return node.children && !node.children.length
110+
}
102111

103-
default:
104-
throw Error('Undefined pseudo-class: ' + pseudo.name);
112+
/* istanbul ignore else - shouldn’t happen */
113+
if (pseudo.name === 'not') {
114+
return !matchNode(pseudo.value.rule, node, nodeIndex, parent, props)
105115
}
106-
});
116+
117+
/* istanbul ignore next */
118+
throw new Error('Undefined pseudo-class: ' + pseudo.name)
119+
}
107120
}

‎lib/select.js

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,78 @@
1-
'use strict';
1+
'use strict'
22

3-
var walkers = require('./ast-walkers'),
4-
matchNode = require('./match-node'),
5-
Collector = require('./collector');
3+
/* eslint-disable max-params */
64

7-
var select = exports;
5+
var walkers = require('./ast-walkers')
86

7+
var matchNode = require('./match-node')
98

10-
select.selectors = function (selectors, ast) {
11-
var collect = Collector();
12-
selectors.selectors.forEach(function (ruleSet) {
13-
collect(select.ruleSet(ruleSet, ast));
14-
});
15-
return collect.result;
16-
};
9+
var Collector = require('./collector')
1710

11+
var select = exports
1812

19-
select.ruleSet = function (ruleSet, ast) {
20-
return select.rule(ruleSet.rule, ast);
21-
};
13+
select.selectors = function(selectors, ast) {
14+
var collect = new Collector()
15+
selectors.selectors.forEach(function(ruleSet) {
16+
collect(select.ruleSet(ruleSet, ast))
17+
})
18+
return collect.result
19+
}
2220

21+
select.ruleSet = function(ruleSet, ast) {
22+
return select.rule(ruleSet.rule, ast)
23+
}
2324

24-
select.rule = function (rule, ast) {
25-
var collect = Collector();
26-
search(rule, ast, 0, null);
27-
return collect.result;
25+
select.rule = function(rule, ast) {
26+
var collect = new Collector()
27+
search(rule, ast, 0, null)
28+
return collect.result
2829

29-
function search (rule, node, nodeIndex, parent) {
30-
({
30+
function search(rule, node, nodeIndex, parent) {
31+
;({
3132
// `undefined` is the operator on the top rule selector.
3233
undefined: walkers.topScan,
3334
// `null` stands for the descendant combinator.
3435
null: walkers.descendant,
3536
'>': walkers.child,
3637
'+': walkers.adjacentSibling,
3738
'~': walkers.generalSibling
38-
})[rule.nestingOperator](
39+
}[rule.nestingOperator](
3940
node,
4041
nodeIndex,
4142
parent,
42-
searchOpts({ iterator: match.bind(null, rule) }, rule)
43-
);
43+
searchOpts({iterator: match.bind(null, rule)}, rule)
44+
))
4445
}
4546

46-
function match (rule, node, nodeIndex, parent, props) {
47+
function match(rule, node, nodeIndex, parent) {
4748
if (matchNode.apply(this, arguments)) {
4849
if (rule.rule) {
49-
search(rule.rule, node, nodeIndex, parent);
50-
}
51-
else {
52-
collect(node);
50+
search(rule.rule, node, nodeIndex, parent)
51+
} else {
52+
collect(node)
5353
}
5454
}
5555
}
56-
};
57-
58-
59-
function searchOpts (opts, rule) {
60-
rule.pseudos && rule.pseudos.forEach(function (pseudo) {
61-
switch (pseudo.name) {
62-
case 'nth-last-of-type':
63-
case 'last-of-type':
64-
case 'only-of-type':
65-
opts.typeCount = true;
56+
}
6657

67-
case 'nth-of-type':
68-
case 'first-of-type':
69-
opts.typeIndex = true;
70-
}
71-
});
58+
function searchOpts(opts, rule) {
59+
if (rule.pseudos) {
60+
rule.pseudos.forEach(function(pseudo) {
61+
if (
62+
pseudo.name === 'nth-last-of-type' ||
63+
pseudo.name === 'last-of-type' ||
64+
pseudo.name === 'only-of-type'
65+
) {
66+
opts.typeIndex = true
67+
opts.typeCount = true
68+
} else if (
69+
pseudo.name === 'nth-of-type' ||
70+
pseudo.name === 'first-of-type'
71+
) {
72+
opts.typeIndex = true
73+
}
74+
})
75+
}
7276

73-
return opts;
77+
return opts
7478
}

‎lib/selector.js

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

3-
var Parser = require('css-selector-parser').CssSelectorParser,
4-
nthCheck = require('nth-check');
3+
var Parser = require('css-selector-parser').CssSelectorParser
54

5+
var nthCheck = require('nth-check')
66

7-
module.exports = function parseSelector (selector) {
8-
var parser = new Parser;
9-
parser.registerNestingOperators('>', '+', '~');
10-
parser.registerAttrEqualityMods('^', '*', '$');
11-
parser.registerSelectorPseudos('not');
12-
return compileNthChecks(parser.parse(selector));
13-
};
7+
module.exports = parseSelector
148

9+
function parseSelector(selector) {
10+
var parser = new Parser()
11+
parser.registerNestingOperators('>', '+', '~')
12+
parser.registerAttrEqualityMods('^', '*', '$')
13+
parser.registerSelectorPseudos('not')
14+
return compileNthChecks(parser.parse(selector))
15+
}
1516

16-
function compileNthChecks (ast) {
17-
if (ast == null) {
18-
return ast;
17+
function compileNthChecks(ast) {
18+
if (ast === null || ast === undefined) {
19+
return ast
1920
}
2021

21-
switch (ast.type) {
22-
case 'selectors':
23-
ast.selectors.forEach(compileNthChecks);
24-
break;
25-
26-
case 'ruleSet':
27-
compileNthChecks(ast.rule);
28-
break;
29-
30-
case 'rule':
31-
if (ast.pseudos) {
32-
ast.pseudos.forEach(function (pseudo) {
33-
if (pseudo.name == 'nth-child' ||
34-
pseudo.name == 'nth-last-child' ||
35-
pseudo.name == 'nth-of-type' ||
36-
pseudo.name == 'nth-last-of-type') {
37-
pseudo.value = nthCheck(pseudo.value);
38-
pseudo.valueType = 'function';
39-
}
40-
});
41-
}
42-
if (ast.rule) {
43-
compileNthChecks(ast.rule);
44-
}
45-
break;
46-
47-
default:
48-
throw Error('Undefined AST node: ' + ast.type);
22+
/* istanbul ignore else - shouldn’t happen */
23+
if (ast.type === 'selectors') {
24+
ast.selectors.forEach(compileNthChecks)
25+
} else if (ast.type === 'ruleSet') {
26+
compileNthChecks(ast.rule)
27+
} else if (ast.type === 'rule') {
28+
if (ast.pseudos) {
29+
ast.pseudos.forEach(function(pseudo) {
30+
if (
31+
pseudo.name === 'nth-child' ||
32+
pseudo.name === 'nth-last-child' ||
33+
pseudo.name === 'nth-of-type' ||
34+
pseudo.name === 'nth-last-of-type'
35+
) {
36+
pseudo.value = nthCheck(pseudo.value)
37+
pseudo.valueType = 'function'
38+
}
39+
})
40+
}
41+
42+
if (ast.rule) {
43+
compileNthChecks(ast.rule)
44+
}
45+
} else {
46+
throw new Error('Undefined AST node: ' + ast.type)
4947
}
5048

51-
return ast;
49+
return ast
5250
}

‎lib/type-index.js

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

3+
module.exports = TypeIndex
34

4-
module.exports = function TypeIndex () {
5-
var typeLists = Object.create(null);
5+
function TypeIndex() {
6+
var typeLists = Object.create(null)
67

7-
var index = function (node) {
8-
var type = node.type;
8+
var index = function(node) {
9+
var type = node.type
910

1011
if (!typeLists[type]) {
11-
typeLists[type] = [];
12+
typeLists[type] = []
1213
}
1314

14-
return typeLists[type].push(node) - 1;
15-
};
15+
return typeLists[type].push(node) - 1
16+
}
1617

17-
index.count = function (node) {
18-
var typeList = typeLists[node.type];
19-
return typeList ? typeList.length : 0;
20-
};
18+
index.count = function(node) {
19+
var typeList = typeLists[node.type]
20+
return typeList ? typeList.length : 0
21+
}
2122

22-
return index;
23-
};
23+
return index
24+
}

‎LICENSE renamed to ‎license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2017 Eugene Sharygin
3+
Copyright (c) 2015 Eugene Sharygin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎package.json

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@
22
"name": "unist-util-select",
33
"version": "1.5.0",
44
"description": "Select unist nodes using css-like selectors",
5-
"author": "Eugene Sharygin <eush77@gmail.com>",
65
"license": "MIT",
7-
"scripts": {
8-
"test": "tape test/*.js"
9-
},
10-
"files": [
11-
"index.js",
12-
"lib/"
13-
],
14-
"homepage": "https://github.com/eush77/unist-util-select",
15-
"repository": "eush77/unist-util-select",
16-
"bugs": {
17-
"url": "https://github.com/eush77/unist-util-select/issues"
18-
},
196
"keywords": [
207
"child",
218
"descendant",
@@ -39,13 +26,58 @@
3926
"visit",
4027
"walk"
4128
],
29+
"repository": "syntax-tree/unist-util-select",
30+
"bugs": "https://github.com/syntax-tree/unist-util-select/issues",
31+
"author": "Eugene Sharygin <eush77@gmail.com>",
32+
"contributors": [
33+
"Eugene Sharygin <eush77@gmail.com>",
34+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
35+
],
36+
"files": [
37+
"index.js",
38+
"lib/"
39+
],
4240
"dependencies": {
4341
"css-selector-parser": "^1.1.0",
4442
"debug": "^3.1.0",
4543
"nth-check": "^1.0.1"
4644
},
4745
"devDependencies": {
46+
"nyc": "^13.1.0",
47+
"prettier": "^1.15.1",
48+
"remark-cli": "^6.0.0",
49+
"remark-preset-wooorm": "^4.0.0",
4850
"tape": "^4.2.0",
49-
"unist-builder": "^1.0.1"
51+
"unist-builder": "^1.0.1",
52+
"xo": "^0.23.0"
53+
},
54+
"scripts": {
55+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
56+
"test-api": "node test",
57+
"test-coverage": "nyc --reporter lcov tape test/index.js",
58+
"test": "npm run format && npm run test-coverage"
59+
},
60+
"nyc": {
61+
"check-coverage": true,
62+
"lines": 100,
63+
"functions": 100,
64+
"branches": 100
65+
},
66+
"prettier": {
67+
"tabWidth": 2,
68+
"useTabs": false,
69+
"singleQuote": true,
70+
"bracketSpacing": false,
71+
"semi": false,
72+
"trailingComma": "none"
73+
},
74+
"xo": {
75+
"prettier": true,
76+
"esnext": false
77+
},
78+
"remarkConfig": {
79+
"plugins": [
80+
"preset-wooorm"
81+
]
5082
}
5183
}

‎readme.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# unist-util-select [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] [![Downloads][downloads-badge]][downloads] [![Chat][chat-badge]][chat]
2+
3+
Select [unist][] nodes with CSS-like selectors.
4+
5+
[View the list of supported selectors »][support]
6+
7+
## Installation
8+
9+
[npm][]:
10+
11+
```bash
12+
npm install unist-util-select
13+
```
14+
15+
## API
16+
17+
### `select.one(tree, selector)`
18+
19+
### `select.one(tree)(selector)`
20+
21+
Select the first node matching `selector` in the given `tree` (could be the
22+
tree itself).
23+
Returns the found [node][], if any.
24+
Throws an error if node is not found or not unique.
25+
26+
##### Usage
27+
28+
Say we have the following file, `example.md`:
29+
30+
```markdown
31+
1. Step 1.
32+
2. TODO Step 2.
33+
3. Step 3.
34+
35+
1. TODO Step 3.1.
36+
2. Step 3.2.
37+
3. TODO Step 3.3.
38+
```
39+
40+
And our script, `example.js`, looks as follows:
41+
42+
```javascript
43+
var fs = require('fs')
44+
var remark = require('remark')
45+
var select = require('unist-util-select')
46+
47+
var tree = remark().parse(fs.readFileSync('example.md'))
48+
49+
var step = select.one(tree, 'list text[value*=3.2]')
50+
51+
console.log(step)
52+
```
53+
54+
Now, running `node example` yields:
55+
56+
```javascript
57+
{ type: 'text', value: 'Step 3.2.' }
58+
```
59+
60+
### `select(tree, selector)`
61+
62+
### `select(tree)(selector)`
63+
64+
Select all nodes matching `selector` in the given `tree` (could include the
65+
tree itself).
66+
Returns the found [node][]s, if any.
67+
68+
##### Usage
69+
70+
Say we have the following file, `example.md`:
71+
72+
```markdown
73+
1. Step 1.
74+
2. TODO Step 2.
75+
3. Step 3.
76+
77+
1. TODO Step 3.1.
78+
2. Step 3.2.
79+
3. TODO Step 3.3.
80+
```
81+
82+
And our script, `example.js`, looks as follows:
83+
84+
```javascript
85+
var fs = require('fs')
86+
var remark = require('remark')
87+
var select = require('unist-util-select')
88+
89+
var tree = remark().parse(fs.readFileSync('example.md'))
90+
91+
var todos = select(tree, 'list text[value*=TODO]')
92+
93+
console.log(todos)
94+
```
95+
96+
Now, running `node example` yields:
97+
98+
```javascript
99+
[ { type: 'text',
100+
value: 'TODO Step 2.' },
101+
{ type: 'text',
102+
value: 'TODO Step 3.1.' },
103+
{ type: 'text',
104+
value: 'TODO Step 3.3.' } ]
105+
```
106+
107+
## Support
108+
109+
## Contribute
110+
111+
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get
112+
started.
113+
114+
This organisation has a [Code of Conduct][coc]. By interacting with this
115+
repository, organisation, or community you agree to abide by its terms.
116+
117+
## License
118+
119+
[MIT][license] © Eugene Sharygin
120+
121+
<!-- Definitions -->
122+
123+
[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-select.svg
124+
125+
[build]: https://travis-ci.org/syntax-tree/unist-util-select
126+
127+
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-select.svg
128+
129+
[coverage]: https://codecov.io/github/syntax-tree/unist-util-select
130+
131+
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-select.svg
132+
133+
[downloads]: https://www.npmjs.com/package/unist-util-select
134+
135+
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
136+
137+
[chat]: https://spectrum.chat/unified/syntax-tree
138+
139+
[npm]: https://docs.npmjs.com/cli/install
140+
141+
[license]: license
142+
143+
[unist]: https://github.com/syntax-tree/unist
144+
145+
[node]: https://github.com/syntax-tree/unist#node
146+
147+
[support]: #support
148+
149+
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md
150+
151+
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md

‎test/collector.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
'use strict';
2-
3-
var Collector = require('../lib/collector');
4-
5-
var test = require('tape');
6-
7-
8-
test('Collector', function (t) {
9-
var collect = Collector();
10-
collect('foo');
11-
collect(['foo', 'bar', 'baz', 'bar']);
12-
collect('foo');
13-
t.deepEqual(collect.result, ['foo', 'bar', 'baz']);
14-
t.end();
15-
});
1+
'use strict'
2+
3+
var test = require('tape')
4+
var Collector = require('../lib/collector')
5+
6+
test('Collector', function(t) {
7+
var collect = new Collector()
8+
collect('foo')
9+
collect(['foo', 'bar', 'baz', 'bar'])
10+
collect('foo')
11+
t.deepEqual(collect.result, ['foo', 'bar', 'baz'])
12+
t.end()
13+
})

‎test/curried.js

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

3-
var select = require('..'),
4-
ast = require('./lib/ast')();
3+
var test = require('tape')
4+
var ast = require('./lib/ast')()
5+
var select = require('..')
56

6-
var test = require('tape');
7-
8-
9-
test('curried forms', function (t) {
10-
t.deepEqual(select(ast)('paragraph'), select(ast, 'paragraph'));
11-
t.equal(select.one(ast)('table'), select.one(ast, 'table'));
12-
t.end();
13-
});
7+
test('curried forms', function(t) {
8+
t.deepEqual(select(ast)('paragraph'), select(ast, 'paragraph'))
9+
t.equal(select.one(ast)('table'), select.one(ast, 'table'))
10+
t.end()
11+
})

‎test/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
/* eslint-disable import/no-unassigned-import */
4+
5+
require('./collector')
6+
require('./curried')
7+
require('./select-one')
8+
require('./select')
9+
require('./type-index')

‎test/lib/ast.js

Lines changed: 168 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,164 @@
1-
'use strict';
1+
'use strict'
22

3-
var u = require('unist-builder');
3+
var u = require('unist-builder')
44

5-
6-
module.exports = function () {
5+
module.exports = function() {
76
return u('root', [
8-
u('heading', { depth: 1 }, [
9-
u('text', 'Risus pretium quam!')
10-
]),
11-
u('heading', { depth: 2 }, [
12-
u('text', 'Vitae')
13-
]),
7+
u('heading', {depth: 1}, [u('text', 'Risus pretium quam!')]),
8+
u('heading', {depth: 2}, [u('text', 'Vitae')]),
149
u('blockquote', [
1510
u('paragraph', [
1611
u('text', 'Dignissim '),
17-
u('emphasis', [
18-
u('text', 'cras')
19-
]),
12+
u('emphasis', [u('text', 'cras')]),
2013
u('text', ' tincidunt lobortis feugiat vivamus at augue eget arcu.')
2114
])
2215
]),
2316
u('paragraph', [
2417
u('text', 'At '),
2518
u('emphasis', [
2619
u('text', 'risus '),
27-
u('linkReference', {
28-
identifier: 'viverra',
29-
referenceType: 'shortcut'
30-
}, [
31-
u('text', 'viverra')
32-
])
20+
u(
21+
'linkReference',
22+
{
23+
identifier: 'viverra',
24+
referenceType: 'shortcut'
25+
},
26+
[u('text', 'viverra')]
27+
)
3328
]),
3429
u('text', ':')
3530
]),
36-
u('list', {
37-
ordered: false,
38-
start: null,
39-
loose: false
40-
}, [
41-
u('listItem', {
42-
loose: false,
43-
checked: null
44-
}, [
45-
u('paragraph', [
46-
u('text', 'adipiscing at in tellus '),
47-
u('inlineCode', 'integer'),
48-
u('text', ';')
49-
])
50-
]),
51-
u('listItem', {
52-
loose: false,
53-
checked: null
54-
}, [
55-
u('paragraph', [
56-
u('text', 'feugiat scelerisque varius morbi;')
57-
]),
58-
u('list', {
59-
ordered: false,
60-
start: null,
61-
loose: false
62-
}, [
63-
u('listItem', {
31+
u(
32+
'list',
33+
{
34+
ordered: false,
35+
start: null,
36+
loose: false
37+
},
38+
[
39+
u(
40+
'listItem',
41+
{
6442
loose: false,
6543
checked: null
66-
}, [
44+
},
45+
[
6746
u('paragraph', [
68-
u('text', 'enim nunc?')
69-
]),
70-
u('list', {
71-
ordered: false,
72-
start: null,
73-
loose: false
74-
}, [
75-
u('listItem', {
76-
loose: false,
77-
checked: null
78-
}, [
79-
u('paragraph', [
80-
u('text', 'yeah, whatever')
81-
])
82-
])
47+
u('text', 'adipiscing at in tellus '),
48+
u('inlineCode', 'integer'),
49+
u('text', ';')
8350
])
84-
]),
85-
u('listItem', {
51+
]
52+
),
53+
u(
54+
'listItem',
55+
{
56+
loose: false,
57+
checked: null
58+
},
59+
[
60+
u('paragraph', [u('text', 'feugiat scelerisque varius morbi;')]),
61+
u(
62+
'list',
63+
{
64+
ordered: false,
65+
start: null,
66+
loose: false
67+
},
68+
[
69+
u(
70+
'listItem',
71+
{
72+
loose: false,
73+
checked: null
74+
},
75+
[
76+
u('paragraph', [u('text', 'enim nunc?')]),
77+
u(
78+
'list',
79+
{
80+
ordered: false,
81+
start: null,
82+
loose: false
83+
},
84+
[
85+
u(
86+
'listItem',
87+
{
88+
loose: false,
89+
checked: null
90+
},
91+
[u('paragraph', [u('text', 'yeah, whatever')])]
92+
)
93+
]
94+
)
95+
]
96+
),
97+
u(
98+
'listItem',
99+
{
100+
loose: false,
101+
checked: null
102+
},
103+
[
104+
u('paragraph', [
105+
u('strong', [
106+
u('text', 'Diam '),
107+
u('emphasis', [u('text', 'ut')]),
108+
u('text', ' venenatis!')
109+
])
110+
])
111+
]
112+
)
113+
]
114+
)
115+
]
116+
)
117+
]
118+
),
119+
u('paragraph', [u('text', 'Tellus in metus:')]),
120+
u(
121+
'list',
122+
{
123+
ordered: true,
124+
start: 1,
125+
loose: false
126+
},
127+
[
128+
u(
129+
'listItem',
130+
{
131+
loose: false,
132+
checked: null
133+
},
134+
[u('paragraph', [u('text', 'Vulputate eu scelerisque.')])]
135+
),
136+
u(
137+
'listItem',
138+
{
86139
loose: false,
87140
checked: null
88-
}, [
141+
},
142+
[
89143
u('paragraph', [
90-
u('strong', [
91-
u('text', 'Diam '),
92-
u('emphasis', [
93-
u('text', 'ut')
94-
]),
95-
u('text', ' venenatis!')
96-
])
144+
u('text', 'Felis imperdiet '),
145+
u('inlineCode', 'proin'),
146+
u('text', ', fermentum leo vel orci.')
97147
])
98-
])
99-
])
100-
])
101-
]),
102-
u('paragraph', [
103-
u('text', 'Tellus in metus:')
104-
]),
105-
u('list', {
106-
ordered: true,
107-
start: 1,
108-
loose: false
109-
}, [
110-
u('listItem', {
111-
loose: false,
112-
checked: null
113-
}, [
114-
u('paragraph', [
115-
u('text', 'Vulputate eu scelerisque.')
116-
])
117-
]),
118-
u('listItem', {
119-
loose: false,
120-
checked: null
121-
}, [
122-
u('paragraph', [
123-
u('text', 'Felis imperdiet '),
124-
u('inlineCode', 'proin'),
125-
u('text', ', fermentum leo vel orci.')
126-
])
127-
])
128-
]),
129-
u('heading', { depth: 3 }, [
148+
]
149+
)
150+
]
151+
),
152+
u('heading', {depth: 3}, [
130153
u('text', 'Et pharetra '),
131-
u('linkReference', {
132-
identifier: 'pharetra massa',
133-
referenceType: 'shortcut'
134-
}, [
135-
u('text', 'pharetra massa')
136-
])
154+
u(
155+
'linkReference',
156+
{
157+
identifier: 'pharetra massa',
158+
referenceType: 'shortcut'
159+
},
160+
[u('text', 'pharetra massa')]
161+
)
137162
]),
138163
u('paragraph', [
139164
u('image', {
@@ -142,60 +167,50 @@ module.exports = function () {
142167
alt: 'funny gif'
143168
})
144169
]),
145-
u('code', { lang: 'js' },
146-
'const truth = [...Array(15).keys()].reduce((x, y) => x + y);'),
147-
u('table', { align: ['center', 'left', null] }, [
170+
u(
171+
'code',
172+
{lang: 'js'},
173+
'const truth = [...Array(15).keys()].reduce((x, y) => x + y);'
174+
),
175+
u('table', {align: ['center', 'left', null]}, [
148176
u('tableHeader', [
149-
u('tableCell', [
150-
u('text', 'massa')
151-
]),
152-
u('tableCell', [
153-
u('text', 'ultricies')
154-
]),
155-
u('tableCell', [
156-
u('text', 'mi')
157-
])
177+
u('tableCell', [u('text', 'massa')]),
178+
u('tableCell', [u('text', 'ultricies')]),
179+
u('tableCell', [u('text', 'mi')])
158180
]),
159181
u('tableRow', [
160-
u('tableCell', [
161-
u('text', 'quis hendrerit')
162-
]),
182+
u('tableCell', [u('text', 'quis hendrerit')]),
163183
u('tableCell', [
164184
u('inlineCode', 'sin'),
165185
u('text', ', '),
166186
u('inlineCode', 'cos'),
167187
u('text', ', '),
168188
u('inlineCode', 'tan')
169189
]),
170-
u('tableCell', [
171-
u('text', 'dolor')
172-
])
190+
u('tableCell', [u('text', 'dolor')])
173191
]),
174192
u('tableRow', [
175-
u('tableCell', [
176-
u('text', 'magna eget est')
177-
]),
178-
u('tableCell', [
179-
u('text', 'lorem ipsum!')
180-
]),
181-
u('tableCell', [
182-
u('text', '15000')
183-
])
193+
u('tableCell', [u('text', 'magna eget est')]),
194+
u('tableCell', [u('text', 'lorem ipsum!')]),
195+
u('tableCell', [u('text', '15000')])
184196
])
185197
]),
186198
u('paragraph', [
187199
u('text', 'Consequat '),
188-
u('linkReference', {
189-
identifier: 'interdum',
190-
referenceType: 'shortcut'
191-
}, [
192-
u('text', 'interdum')
193-
]),
194-
u('text', ' varius sit amet, mattis vulputate enim nulla aliquet porttitor lacus, luctus accumsan tortor?..')
195-
]),
196-
u('heading', { depth: 2 }, [
197-
u('text', 'References')
200+
u(
201+
'linkReference',
202+
{
203+
identifier: 'interdum',
204+
referenceType: 'shortcut'
205+
},
206+
[u('text', 'interdum')]
207+
),
208+
u(
209+
'text',
210+
' varius sit amet, mattis vulputate enim nulla aliquet porttitor lacus, luctus accumsan tortor?..'
211+
)
198212
]),
213+
u('heading', {depth: 2}, [u('text', 'References')]),
199214
u('definition', {
200215
identifier: 'viverra',
201216
title: null,
@@ -211,14 +226,8 @@ module.exports = function () {
211226
title: null,
212227
link: 'http://lmgtfy.com/?q=interdum'
213228
}),
214-
u('heading', { depth: 2 }, [
215-
u('text', 'License')
216-
]),
217-
u('paragraph', [
218-
u('text', 'MIT')
219-
]),
220-
u('div', [
221-
u('div', [])
222-
])
223-
]);
224-
};
229+
u('heading', {depth: 2}, [u('text', 'License')]),
230+
u('paragraph', [u('text', 'MIT')]),
231+
u('div', [u('div', [])])
232+
])
233+
}

‎test/lib/path.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
'use strict';
1+
'use strict'
22

3-
4-
module.exports = function walk (node, path) {
5-
return path.length
6-
? walk(node.children[path[0]], path.slice(1))
7-
: node;
8-
};
3+
module.exports = function walk(node, path) {
4+
return path.length === 0 ? node : walk(node.children[path[0]], path.slice(1))
5+
}

‎test/select-one.js

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

3-
var select = require('..'),
4-
select1 = select.one,
5-
ast = require('./lib/ast')();
3+
var test = require('tape')
4+
var ast = require('./lib/ast')()
5+
var select = require('..')
66

7-
var test = require('tape');
7+
var one = select.one
88

9-
10-
test('select.one', function (t) {
11-
t.equal(select1(ast, 'root'), ast);
12-
t.equal(select1(ast, 'blockquote'), select(ast, 'blockquote')[0]);
13-
t.equal(select1(ast, 'table'), select(ast, 'table')[0]);
14-
t.throws(select1.bind(null, ast, 'math'), 'throws when node is not found');
15-
t.throws(select1.bind(null, ast, 'text'), 'throws when node is not unique');
16-
t.end();
17-
});
9+
test('select.one', function(t) {
10+
t.equal(one(ast, 'root'), ast)
11+
t.equal(one(ast, 'blockquote'), select(ast, 'blockquote')[0])
12+
t.equal(one(ast, 'table'), select(ast, 'table')[0])
13+
t.throws(one.bind(null, ast, 'math'), 'throws when node is not found')
14+
t.throws(one.bind(null, ast, 'text'), 'throws when node is not unique')
15+
t.end()
16+
})

‎test/select.js

Lines changed: 241 additions & 218 deletions
Large diffs are not rendered by default.

‎test/type-index.js

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

3-
var TypeIndex = require('../lib/type-index');
3+
var test = require('tape')
4+
var TypeIndex = require('../lib/type-index')
45

5-
var test = require('tape');
6+
test('TypeIndex', function(t) {
7+
var typeIndex = new TypeIndex()
68

9+
t.equal(typeIndex.count({type: 'foo'}), 0)
10+
t.equal(typeIndex({type: 'foo'}), 0)
11+
t.equal(typeIndex.count({type: 'foo'}), 1)
12+
t.equal(typeIndex({type: 'bar'}), 0)
13+
t.equal(typeIndex({type: 'foo'}), 1)
14+
t.equal(typeIndex({type: 'foo'}), 2)
15+
t.equal(typeIndex({type: 'bar'}), 1)
16+
t.equal(typeIndex({type: 'baz'}), 0)
17+
t.equal(typeIndex.count({type: 'foo'}), 3)
718

8-
test('TypeIndex', function (t) {
9-
var typeIndex = TypeIndex();
19+
typeIndex = new TypeIndex()
20+
t.equal(typeIndex.count({type: 'foo'}), 0)
21+
t.equal(typeIndex({type: 'foo'}), 0)
22+
t.equal(typeIndex.count({type: 'foo'}), 1)
1023

11-
t.equal(typeIndex.count({ type: 'foo' }), 0);
12-
t.equal(typeIndex({ type: 'foo' }), 0);
13-
t.equal(typeIndex.count({ type: 'foo' }), 1);
14-
t.equal(typeIndex({ type: 'bar' }), 0);
15-
t.equal(typeIndex({ type: 'foo' }), 1);
16-
t.equal(typeIndex({ type: 'foo' }), 2);
17-
t.equal(typeIndex({ type: 'bar' }), 1);
18-
t.equal(typeIndex({ type: 'baz' }), 0);
19-
t.equal(typeIndex.count({ type: 'foo' }), 3);
20-
21-
typeIndex = TypeIndex();
22-
t.equal(typeIndex.count({ type: 'foo' }), 0);
23-
t.equal(typeIndex({ type: 'foo' }), 0);
24-
t.equal(typeIndex.count({ type: 'foo' }), 1);
25-
26-
t.end();
27-
});
24+
t.end()
25+
})

0 commit comments

Comments
 (0)
Please sign in to comment.