syntax-tree / mdast-util-definitions
Showing 1 of 2 files from the diff.
Other files ignored by Codecov
test.js has changed.

@@ -2,17 +2,12 @@
Loading
2 2
3 3
var visit = require('unist-util-visit')
4 4
5 -
module.exports = getDefinitionFactory
5 +
module.exports = createGetDefinition
6 6
7 7
var own = {}.hasOwnProperty
8 8
9 9
// Get a definition in `node` by `identifier`.
10 -
function getDefinitionFactory(node, options) {
11 -
  return getterFactory(gather(node, options))
12 -
}
13 -
14 -
// Gather all definitions in `node`
15 -
function gather(node) {
10 +
function createGetDefinition(node) {
16 11
  var cache = {}
17 12
18 13
  if (!node || !node.type) {
@@ -21,27 +16,22 @@
Loading
21 16
22 17
  visit(node, 'definition', ondefinition)
23 18
24 -
  return cache
19 +
  return getDefinition
25 20
26 21
  function ondefinition(definition) {
27 -
    var id = normalise(definition.identifier)
28 -
    if (!own.call(cache, id)) {
22 +
    var id = clean(definition.identifier)
23 +
    if (id && !own.call(cache, id)) {
29 24
      cache[id] = definition
30 25
    }
31 26
  }
32 -
}
33 -
34 -
// Factory to get a node from the given definition-cache.
35 -
function getterFactory(cache) {
36 -
  return getter
37 27
38 28
  // Get a node from the bound definition-cache.
39 -
  function getter(identifier) {
40 -
    var id = identifier && normalise(identifier)
29 +
  function getDefinition(identifier) {
30 +
    var id = clean(identifier)
41 31
    return id && own.call(cache, id) ? cache[id] : null
42 32
  }
43 33
}
44 34
45 -
function normalise(identifier) {
46 -
  return identifier.toUpperCase()
35 +
function clean(value) {
36 +
  return String(value || '').toUpperCase()
47 37
}
Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
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