Coverage

100%
23
23
0

lib/fine.js

100%
23
23
0
LineHitsSource
1/**
2 * Core dependencies.
3 */
4
51var fs = require('fs');
61var path = require('path');
7
8/**
9 * Find all files in given `location`.
10 *
11 * Features:
12 *
13 * - Recursive
14 * - Sync
15 * - Ignore list
16 *
17 * Options:
18 *
19 * - ext Extension
20 * - ignore Patterns to ignore
21 *
22 * @param {String} path
23 * @param {Object} options
24 * @returns {Array}
25 * @api public
26 */
27
28function fine(location, options) {
2942 options = options || {};
3042 location = path.normalize(location);
31
3242 var files = [];
3342 var ext = options.ext;
3442 var dir = isDirectory(location) ? fs.readdirSync(location) : [''];
3541 var ignore = options.ignore || [];
36
3741 if (!Array.isArray(ignore)) {
3816 ignore = [ignore];
39 }
40
4141 dir.forEach(function(file) {
4261 var full = path.join(location, file);
43
4461 if (isDirectory(location) === true) {
4535 files = files.concat(fine(full, options));
4635 return;
47 }
48
4926 if (ext && path.extname(full) != ext) {
504 return;
51 }
52
5322 for (var i = 0, len = ignore.length; i < len; i++) {
5425 if (new RegExp('^' + ignore[i]).test(full)) return;
55 }
56
5714 files.push(full);
58 });
59
6041 return files;
61}
62
63/**
64 * Check if `path` is a directory.
65 *
66 * @param {String} path
67 * @returns {Boolean}
68 * @api private
69 */
70
71function isDirectory(path) {
72103 return fs.statSync(path).isDirectory();
73}
74
75/**
76 * Primary export.
77 */
78
791module.exports = fine;
80