syntax-tree / unist-util-find-all-before

Compare 230a309 ... +6 ... 961597f

Coverage Reach
index.js

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 12 files from the diff.
Other files ignored by Codecov

@@ -1,39 +1,63 @@
Loading
1 -
'use strict'
2 -
3 -
var convert = require('unist-util-is/convert')
4 -
5 -
module.exports = findAllBefore
6 -
7 -
function findAllBefore(parent, index, test) {
8 -
  var is = convert(test)
9 -
  var results = []
10 -
11 -
  if (!parent || !parent.type || !parent.children) {
12 -
    throw new Error('Expected parent node')
13 -
  }
14 -
15 -
  if (typeof index === 'number') {
16 -
    if (index < 0 || index === Infinity) {
17 -
      throw new Error('Expected positive finite number as index')
1 +
/**
2 +
 * @typedef {import('unist').Node} Node
3 +
 * @typedef {import('unist').Parent} Parent
4 +
 *
5 +
 * @typedef {import('unist-util-is').Type} Type
6 +
 * @typedef {import('unist-util-is').Props} Props
7 +
 * @typedef {import('unist-util-is').TestFunctionAnything} TestFunctionAnything
8 +
 */
9 +
10 +
import {convert} from 'unist-util-is'
11 +
12 +
export const findAllBefore =
13 +
  /**
14 +
   * @type {(
15 +
   *  (<T extends Node>(node: Parent, index: Node|number, test: T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>>) => Array.<T>) &
16 +
   *  ((node: Parent, index: Node|number, test?: null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>) => Array.<Node>)
17 +
   * )}
18 +
   */
19 +
  (
20 +
    /**
21 +
     * Utility to get all children of a parent after a node or index
22 +
     *
23 +
     * @param {Parent} parent Parent node
24 +
     * @param {Node|number} index Child of `parent`, or it’s index
25 +
     * @param {null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>} [test] is-compatible test (such as a type)
26 +
     * @returns {Array.<Node>}
27 +
     */
28 +
    function (parent, index, test) {
29 +
      var is = convert(test)
30 +
      /** @type {Array.<Node>} */
31 +
      var results = []
32 +
      var offset = -1
33 +
34 +
      if (!parent || !parent.type || !parent.children) {
35 +
        throw new Error('Expected parent node')
36 +
      }
37 +
38 +
      if (typeof index === 'number') {
39 +
        if (index < 0 || index === Number.POSITIVE_INFINITY) {
40 +
          throw new Error('Expected positive finite number as index')
41 +
        }
42 +
      } else {
43 +
        index = parent.children.indexOf(index)
44 +
45 +
        if (index < 0) {
46 +
          throw new Error('Expected child node or index')
47 +
        }
48 +
      }
49 +
50 +
      // Performance.
51 +
      if (index > parent.children.length) {
52 +
        index = parent.children.length
53 +
      }
54 +
55 +
      while (++offset < index) {
56 +
        if (is(parent.children[offset], offset, parent)) {
57 +
          results.push(parent.children[offset])
58 +
        }
59 +
      }
60 +
61 +
      return results
18 62
    }
19 -
  } else {
20 -
    index = parent.children.indexOf(index)
21 -
22 -
    if (index < 0) {
23 -
      throw new Error('Expected child node or index')
24 -
    }
25 -
  }
26 -
27 -
  // Performance.
28 -
  if (index > parent.children.length) {
29 -
    index = parent.children.length
30 -
  }
31 -
32 -
  while (index--) {
33 -
    if (is(parent.children[index], index, parent)) {
34 -
      results.push(parent.children[index])
35 -
    }
36 -
  }
37 -
38 -
  return results
39 -
}
63 +
  )

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
Loading