Showing 2 of 5 files from the diff.
Newly tracked file
convert.js created.
Other files ignored by Codecov
package.json has changed.
test.js has changed.
readme.md has changed.

@@ -0,0 +1,82 @@
Loading
1 +
'use strict'
2 +
3 +
module.exports = convert
4 +
5 +
function convert(test) {
6 +
  if (typeof test === 'string') {
7 +
    return tagNameFactory(test)
8 +
  }
9 +
10 +
  if (test === null || test === undefined) {
11 +
    return element
12 +
  }
13 +
14 +
  if (typeof test === 'object') {
15 +
    return any(test)
16 +
  }
17 +
18 +
  if (typeof test === 'function') {
19 +
    return callFactory(test)
20 +
  }
21 +
22 +
  throw new Error('Expected function, string, or array as test')
23 +
}
24 +
25 +
function convertAll(tests) {
26 +
  var length = tests.length
27 +
  var index = -1
28 +
  var results = []
29 +
30 +
  while (++index < length) {
31 +
    results[index] = convert(tests[index])
32 +
  }
33 +
34 +
  return results
35 +
}
36 +
37 +
function any(tests) {
38 +
  var checks = convertAll(tests)
39 +
  var length = checks.length
40 +
41 +
  return matches
42 +
43 +
  function matches() {
44 +
    var index = -1
45 +
46 +
    while (++index < length) {
47 +
      if (checks[index].apply(this, arguments)) {
48 +
        return true
49 +
      }
50 +
    }
51 +
52 +
    return false
53 +
  }
54 +
}
55 +
56 +
// Utility to convert a string a tag name check.
57 +
function tagNameFactory(test) {
58 +
  return tagName
59 +
60 +
  function tagName(node) {
61 +
    return element(node) && node.tagName === test
62 +
  }
63 +
}
64 +
65 +
// Utility to convert a function check.
66 +
function callFactory(test) {
67 +
  return call
68 +
69 +
  function call(node) {
70 +
    return element(node) && Boolean(test.apply(this, arguments))
71 +
  }
72 +
}
73 +
74 +
// Utility to return true if this is an element.
75 +
function element(node) {
76 +
  return (
77 +
    node &&
78 +
    typeof node === 'object' &&
79 +
    node.type === 'element' &&
80 +
    typeof node.tagName === 'string'
81 +
  )
82 +
}

@@ -1,45 +1,35 @@
Loading
1 1
'use strict'
2 2
3 +
var convert = require('./convert')
4 +
3 5
module.exports = isElement
4 6
5 -
// Check if if `node` is an `element` and, if `tagNames` is given, `node`
6 -
// matches them `tagNames`.
7 -
function isElement(node, tagNames) {
8 -
  var name
7 +
isElement.convert = convert
9 8
10 -
  if (
11 -
    !(
12 -
      tagNames === null ||
13 -
      tagNames === undefined ||
14 -
      typeof tagNames === 'string' ||
15 -
      (typeof tagNames === 'object' && tagNames.length !== 0)
16 -
    )
17 -
  ) {
18 -
    throw new Error(
19 -
      'Expected `string` or `Array.<string>` for `tagNames`, not `' +
20 -
        tagNames +
21 -
        '`'
22 -
    )
23 -
  }
9 +
// Check if if `node` is an `element` and whether it passes the given test.
10 +
function isElement(node, test, index, parent, context) {
11 +
  var hasParent = parent !== null && parent !== undefined
12 +
  var hasIndex = index !== null && index !== undefined
13 +
  var check = convert(test)
24 14
25 15
  if (
26 -
    !node ||
27 -
    typeof node !== 'object' ||
28 -
    node.type !== 'element' ||
29 -
    typeof node.tagName !== 'string'
16 +
    hasIndex &&
17 +
    (typeof index !== 'number' || index < 0 || index === Infinity)
30 18
  ) {
31 -
    return false
19 +
    throw new Error('Expected positive finite index for child node')
32 20
  }
33 21
34 -
  if (tagNames === null || tagNames === undefined) {
35 -
    return true
22 +
  if (hasParent && (!parent.type || !parent.children)) {
23 +
    throw new Error('Expected parent node')
36 24
  }
37 25
38 -
  name = node.tagName
26 +
  if (!node || !node.type || typeof node.type !== 'string') {
27 +
    return false
28 +
  }
39 29
40 -
  if (typeof tagNames === 'string') {
41 -
    return name === tagNames
30 +
  if (hasParent !== hasIndex) {
31 +
    throw new Error('Expected both parent and index')
42 32
  }
43 33
44 -
  return tagNames.indexOf(name) !== -1
34 +
  return check.call(context, node, index, parent)
45 35
}
Files Coverage
convert.js 100.00%
index.js 100.00%
Project Totals (2 files) 100.00%
29.2
node=
TRAVIS_OS_NAME=linux
29.1
lts/dubnium=/dubnium
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading