vfile / vfile-find-down
Showing 1 of 2 files from the diff.
Other files ignored by Codecov
package.json has changed.

@@ -4,22 +4,12 @@
Loading
4 4
var path = require('path')
5 5
var vfile = require('to-vfile')
6 6
7 -
var INCLUDE = 1
8 -
var SKIP = 4
9 -
var BREAK = 8
10 -
11 -
exports.INCLUDE = INCLUDE
12 -
exports.SKIP = SKIP
13 -
exports.BREAK = BREAK
7 +
exports.INCLUDE = 1
8 +
exports.SKIP = 4
9 +
exports.BREAK = 8
14 10
exports.all = all
15 11
exports.one = one
16 12
17 -
var own = {}.hasOwnProperty
18 -
var readdir = fs.readdir
19 -
var stat = fs.stat
20 -
var resolve = path.resolve
21 -
var join = path.join
22 -
23 13
// Find a file or a directory downwards.
24 14
function one(test, paths, callback) {
25 15
  return find(test, paths, callback, true)
@@ -32,11 +22,7 @@
Loading
32 22
33 23
// Find applicable files.
34 24
function find(test, paths, callback, one) {
35 -
  var state = {
36 -
    broken: false,
37 -
    checked: [],
38 -
    test: augment(test)
39 -
  }
25 +
  var state = {checked: [], test: augment(test)}
40 26
41 27
  if (!callback) {
42 28
    callback = paths
@@ -54,31 +40,28 @@
Loading
54 40
55 41
// Find files in `filePath`.
56 42
function visit(state, filePath, one, done) {
57 -
  var file
58 -
59 43
  // Don’t walk into places multiple times.
60 -
  if (own.call(state.checked, filePath)) {
44 +
  if (state.checked.indexOf(filePath) > -1) {
61 45
    done([])
62 46
    return
63 47
  }
64 48
65 -
  state.checked[filePath] = true
66 -
67 -
  file = vfile(filePath)
68 -
69 -
  stat(resolve(filePath), onstat)
49 +
  state.checked.push(filePath)
50 +
  fs.stat(path.resolve(filePath), onstat)
70 51
71 52
  function onstat(error, stats) {
72 53
    var real = Boolean(stats)
73 54
    var results = []
55 +
    var file
74 56
    var result
75 57
76 58
    if (state.broken || !real) {
77 59
      done([])
78 60
    } else {
61 +
      file = vfile(filePath)
79 62
      result = state.test(file, stats)
80 63
81 -
      if (mask(result, INCLUDE)) {
64 +
      if ((result & 1) === 1 /* Include. */) {
82 65
        results.push(file)
83 66
84 67
        if (one) {
@@ -87,15 +70,19 @@
Loading
87 70
        }
88 71
      }
89 72
90 -
      if (mask(result, BREAK)) {
73 +
      if ((result & 8) === 8 /* Break. */) {
91 74
        state.broken = true
92 75
      }
93 76
94 -
      if (state.broken || !stats.isDirectory() || mask(result, SKIP)) {
77 +
      if (
78 +
        state.broken ||
79 +
        !stats.isDirectory() ||
80 +
        (result & 4) === 4 /* Skip. */
81 +
      ) {
95 82
        return done(results)
96 83
      }
97 84
98 -
      readdir(filePath, onread)
85 +
      fs.readdir(filePath, onread)
99 86
    }
100 87
101 88
    function onread(error, entries) {
@@ -111,7 +98,6 @@
Loading
111 98
// Find files in `paths`.  Returns a list of applicable files.
112 99
// eslint-disable-next-line max-params
113 100
function visitAll(state, paths, cwd, one, done) {
114 -
  var expected = paths.length
115 101
  var actual = -1
116 102
  var result = []
117 103
@@ -120,7 +106,7 @@
Loading
120 106
  next()
121 107
122 108
  function each(filePath) {
123 -
    visit(state, join(cwd || '', filePath), one, onvisit)
109 +
    visit(state, path.join(cwd || '', filePath), one, onvisit)
124 110
  }
125 111
126 112
  function onvisit(files) {
@@ -129,9 +115,7 @@
Loading
129 115
  }
130 116
131 117
  function next() {
132 -
    actual++
133 -
134 -
    if (actual === expected) {
118 +
    if (++actual === paths.length) {
135 119
      done(result)
136 120
    }
137 121
  }
@@ -140,51 +124,44 @@
Loading
140 124
// Augment `test` from several supported values to a function returning a
141 125
// boolean.
142 126
function augment(test) {
143 -
  if (typeof test === 'function') {
144 -
    return test
145 -
  }
146 -
147 -
  return typeof test === 'string' ? testString(test) : multiple(test)
127 +
  return typeof test === 'function'
128 +
    ? test
129 +
    : typeof test === 'string'
130 +
    ? testString(test)
131 +
    : multiple(test)
148 132
}
149 133
150 134
// Wrap a string given as a test.
151 -
// A normal string checks for equality to both the filename and extension.
152 -
// A string starting with a `.` checks for that equality too, and also to just
153 -
// the extension.
154 135
function testString(test) {
155 136
  return check
156 137
157 138
  // Check whether the given `file` matches the bound value.
158 139
  function check(file) {
159 -
    var basename = file.basename
160 -
161 -
    if (test === basename || test === file.extname) {
140 +
    if (test === file.basename || test === file.extname) {
162 141
      return true
163 142
    }
164 143
165 -
    if (basename.charAt(0) === '.' || basename === 'node_modules') {
166 -
      return SKIP
144 +
    if (file.basename.charAt(0) === '.' || file.basename === 'node_modules') {
145 +
      return 4
167 146
    }
168 147
  }
169 148
}
170 149
171 150
function multiple(test) {
172 -
  var length = test.length
173 -
  var index = -1
174 151
  var tests = []
152 +
  var index = -1
175 153
176 -
  while (++index < length) {
154 +
  while (++index < test.length) {
177 155
    tests[index] = augment(test[index])
178 156
  }
179 157
180 158
  return check
181 159
182 160
  function check(file) {
161 +
    var index = -1
183 162
    var result
184 163
185 -
    index = -1
186 -
187 -
    while (++index < length) {
164 +
    while (++index < tests.length) {
188 165
      result = tests[index](file)
189 166
190 167
      if (result) {
@@ -195,7 +172,3 @@
Loading
195 172
    return false
196 173
  }
197 174
}
198 -
199 -
function mask(value, bitmask) {
200 -
  return (value & bitmask) === bitmask
201 -
}
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