filehound 2.0.0-beta.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.md +39 -11
  2. package/dist/arrays.d.ts +1 -0
  3. package/dist/arrays.js +4 -0
  4. package/dist/file.d.ts +108 -0
  5. package/dist/file.js +184 -0
  6. package/dist/filehound.d.ts +356 -0
  7. package/dist/filehound.js +498 -0
  8. package/dist/files.d.ts +4 -0
  9. package/dist/files.js +37 -0
  10. package/dist/filetype.d.ts +10 -0
  11. package/dist/filetype.js +9 -0
  12. package/dist/index.d.ts +5 -0
  13. package/dist/index.js +6 -0
  14. package/dist/matchers.d.ts +324 -0
  15. package/dist/matchers.js +419 -0
  16. package/dist/walker/async.d.ts +4 -0
  17. package/dist/walker/async.js +237 -0
  18. package/dist/walker/heap.d.ts +7 -0
  19. package/dist/walker/heap.js +49 -0
  20. package/dist/walker/sync.d.ts +4 -0
  21. package/dist/walker/sync.js +66 -0
  22. package/dist/walker/walk.d.ts +33 -0
  23. package/dist/walker/walk.js +80 -0
  24. package/package.json +45 -48
  25. package/.github/stale.yml +0 -42
  26. package/.travis.yml +0 -8
  27. package/.vscode/launch.json +0 -21
  28. package/.vscode/settings.json +0 -3
  29. package/CONTRIBUTING.md +0 -8
  30. package/_config.yml +0 -1
  31. package/coverage/coverage.raw.json +0 -1
  32. package/coverage/lcov-report/arrays.ts.html +0 -98
  33. package/coverage/lcov-report/base.css +0 -212
  34. package/coverage/lcov-report/filehound.ts.html +0 -2078
  35. package/coverage/lcov-report/files.ts.html +0 -260
  36. package/coverage/lcov-report/functions.ts.html +0 -122
  37. package/coverage/lcov-report/index.html +0 -132
  38. package/coverage/lcov-report/prettify.css +0 -1
  39. package/coverage/lcov-report/prettify.js +0 -1
  40. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  41. package/coverage/lcov-report/sorter.js +0 -158
  42. package/coverage/lcov.info +0 -378
  43. package/dist/src/arrays.js +0 -15
  44. package/dist/src/arrays.js.map +0 -1
  45. package/dist/src/asyncWalker.js +0 -59
  46. package/dist/src/asyncWalker.js.map +0 -1
  47. package/dist/src/bind.js +0 -15
  48. package/dist/src/bind.js.map +0 -1
  49. package/dist/src/filehound.js +0 -597
  50. package/dist/src/filehound.js.map +0 -1
  51. package/dist/src/files.js +0 -60
  52. package/dist/src/files.js.map +0 -1
  53. package/dist/src/matcher.js +0 -51
  54. package/dist/src/matcher.js.map +0 -1
  55. package/dist/src/syncWalker.js +0 -47
  56. package/dist/src/syncWalker.js.map +0 -1
  57. package/dist/src/walkAsync.js +0 -33
  58. package/dist/src/walkAsync.js.map +0 -1
  59. package/dist/src/walkSync.js +0 -21
  60. package/dist/src/walkSync.js.map +0 -1
  61. package/dist/src/walker/walk.js +0 -68
  62. package/dist/src/walker/walk.js.map +0 -1
  63. package/dist/src/walker/walkAsync.js +0 -33
  64. package/dist/src/walker/walkAsync.js.map +0 -1
  65. package/dist/src/walker/walkSync.js +0 -21
  66. package/dist/src/walker/walkSync.js.map +0 -1
  67. package/dist/test/filehound.js +0 -872
  68. package/dist/test/filehound.js.map +0 -1
  69. package/dist/test/files.js +0 -29
  70. package/dist/test/files.js.map +0 -1
  71. package/docconfig/jsdoc.json +0 -26
  72. package/docconfig/template/LICENSE +0 -61
  73. package/docconfig/template/README.md +0 -86
  74. package/docconfig/template/package.json +0 -22
  75. package/docconfig/template/publish.js +0 -676
  76. package/docconfig/template/static/fonts/OpenSans-Bold-webfont.eot +0 -0
  77. package/docconfig/template/static/fonts/OpenSans-Bold-webfont.svg +0 -1830
  78. package/docconfig/template/static/fonts/OpenSans-Bold-webfont.woff +0 -0
  79. package/docconfig/template/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  80. package/docconfig/template/static/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  81. package/docconfig/template/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  82. package/docconfig/template/static/fonts/OpenSans-Italic-webfont.eot +0 -0
  83. package/docconfig/template/static/fonts/OpenSans-Italic-webfont.svg +0 -1830
  84. package/docconfig/template/static/fonts/OpenSans-Italic-webfont.woff +0 -0
  85. package/docconfig/template/static/fonts/OpenSans-Light-webfont.eot +0 -0
  86. package/docconfig/template/static/fonts/OpenSans-Light-webfont.svg +0 -1831
  87. package/docconfig/template/static/fonts/OpenSans-Light-webfont.woff +0 -0
  88. package/docconfig/template/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  89. package/docconfig/template/static/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  90. package/docconfig/template/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  91. package/docconfig/template/static/fonts/OpenSans-Regular-webfont.eot +0 -0
  92. package/docconfig/template/static/fonts/OpenSans-Regular-webfont.svg +0 -1831
  93. package/docconfig/template/static/fonts/OpenSans-Regular-webfont.woff +0 -0
  94. package/docconfig/template/static/fonts/OpenSans-Semibold-webfont.eot +0 -0
  95. package/docconfig/template/static/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  96. package/docconfig/template/static/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  97. package/docconfig/template/static/fonts/OpenSans-Semibold-webfont.woff +0 -0
  98. package/docconfig/template/static/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  99. package/docconfig/template/static/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  100. package/docconfig/template/static/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  101. package/docconfig/template/static/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  102. package/docconfig/template/static/scripts/linenumber.js +0 -25
  103. package/docconfig/template/static/scripts/prettify/Apache-License-2.0.txt +0 -202
  104. package/docconfig/template/static/scripts/prettify/lang-css.js +0 -2
  105. package/docconfig/template/static/scripts/prettify/prettify.js +0 -28
  106. package/docconfig/template/static/styles/jsdoc-default.css +0 -605
  107. package/docconfig/template/static/styles/prettify-jsdoc.css +0 -111
  108. package/docconfig/template/static/styles/prettify-tomorrow.css +0 -132
  109. package/docconfig/template/tmpl/augments.tmpl +0 -10
  110. package/docconfig/template/tmpl/container.tmpl +0 -183
  111. package/docconfig/template/tmpl/details.tmpl +0 -143
  112. package/docconfig/template/tmpl/example.tmpl +0 -2
  113. package/docconfig/template/tmpl/examples.tmpl +0 -13
  114. package/docconfig/template/tmpl/exceptions.tmpl +0 -32
  115. package/docconfig/template/tmpl/layout.tmpl +0 -47
  116. package/docconfig/template/tmpl/mainpage.tmpl +0 -10
  117. package/docconfig/template/tmpl/members.tmpl +0 -38
  118. package/docconfig/template/tmpl/method.tmpl +0 -105
  119. package/docconfig/template/tmpl/params.tmpl +0 -124
  120. package/docconfig/template/tmpl/properties.tmpl +0 -108
  121. package/docconfig/template/tmpl/returns.tmpl +0 -19
  122. package/docconfig/template/tmpl/source.tmpl +0 -8
  123. package/docconfig/template/tmpl/tutorial.tmpl +0 -19
  124. package/docconfig/template/tmpl/type.tmpl +0 -7
  125. package/docs/FileHound.html +0 -3079
  126. package/docs/FileHound_modified.html +0 -245
  127. package/docs/_config.yml +0 -1
  128. package/docs/filehound.js.html +0 -697
  129. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  130. package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
  131. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  132. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  133. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  134. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  135. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  136. package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
  137. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  138. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  139. package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
  140. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  141. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  142. package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  143. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  144. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  145. package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
  146. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  147. package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
  148. package/docs/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  149. package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  150. package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
  151. package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  152. package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  153. package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  154. package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  155. package/docs/global.html +0 -288
  156. package/docs/index.html +0 -154
  157. package/docs/scripts/linenumber.js +0 -25
  158. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  159. package/docs/scripts/prettify/lang-css.js +0 -2
  160. package/docs/scripts/prettify/prettify.js +0 -28
  161. package/docs/styles/jsdoc-default.css +0 -605
  162. package/docs/styles/prettify-jsdoc.css +0 -111
  163. package/docs/styles/prettify-tomorrow.css +0 -132
  164. package/docs.md +0 -164
  165. package/index.js +0 -1
  166. package/issue_template.md +0 -6
  167. package/test/filehound.ts +0 -1076
  168. package/test/files.ts +0 -29
  169. package/test/fixtures/custom/failed.txt +0 -0
  170. package/test/fixtures/custom/passed.txt +0 -0
  171. package/test/fixtures/deeplyNested/c.json +0 -0
  172. package/test/fixtures/deeplyNested/d.json +0 -0
  173. package/test/fixtures/deeplyNested/mydir/e.json +0 -0
  174. package/test/fixtures/deeplyNested/mydir/mydir2/f.json +0 -0
  175. package/test/fixtures/deeplyNested/mydir/mydir2/mydir3/mydir4/failed.json +0 -0
  176. package/test/fixtures/deeplyNested/mydir/mydir2/mydir3/z.json +0 -0
  177. package/test/fixtures/deeplyNested/mydir/mydir2/y.json +0 -0
  178. package/test/fixtures/deeplyNestedWithHiddenDir/c.json +0 -0
  179. package/test/fixtures/deeplyNestedWithHiddenDir/d.json +0 -0
  180. package/test/fixtures/deeplyNestedWithHiddenDir/mydir/e.json +0 -0
  181. package/test/fixtures/deeplyNestedWithHiddenDir/mydir/mydir2/f.json +0 -0
  182. package/test/fixtures/deeplyNestedWithHiddenDir/mydir/mydir2/mydir3/mydir4/.mydir5/.keep +0 -0
  183. package/test/fixtures/deeplyNestedWithHiddenDir/mydir/mydir2/mydir3/mydir4/failed.json +0 -0
  184. package/test/fixtures/deeplyNestedWithHiddenDir/mydir/mydir2/mydir3/z.json +0 -0
  185. package/test/fixtures/deeplyNestedWithHiddenDir/mydir/mydir2/y.json +0 -0
  186. package/test/fixtures/ext/Dummy.java +0 -0
  187. package/test/fixtures/ext/Dumpy.go +0 -0
  188. package/test/fixtures/ext/dummy.json +0 -0
  189. package/test/fixtures/ext/dummy.txt +0 -0
  190. package/test/fixtures/justFiles/a.json +0 -0
  191. package/test/fixtures/justFiles/b.json +0 -0
  192. package/test/fixtures/justFiles/dummy.txt +0 -0
  193. package/test/fixtures/mixed/a.json +0 -0
  194. package/test/fixtures/mixed/aabbcc.json +0 -0
  195. package/test/fixtures/mixed/ab.json +0 -0
  196. package/test/fixtures/mixed/z.json +0 -0
  197. package/test/fixtures/nested/.hidden1/bad.txt +0 -0
  198. package/test/fixtures/nested/c.json +0 -0
  199. package/test/fixtures/nested/d.json +0 -0
  200. package/test/fixtures/nested/mydir/e.json +0 -0
  201. package/test/fixtures/sizes/10b.txt +0 -0
  202. package/test/fixtures/sizes/1b.txt +0 -0
  203. package/test/fixtures/sizes/1k.txt +0 -0
  204. package/test/fixtures/sizes/2k.txt +0 -0
  205. package/test/fixtures/visibility/.hidden/.hidden.json +0 -0
  206. package/test/fixtures/visibility/.hidden/visible.json +0 -3
  207. package/test/fixtures/visibility/.hidden.json +0 -3
  208. package/test/fixtures/visibility/visible/.hidden.json +0 -3
  209. package/test/fixtures/visibility/visible.json +0 -3
  210. package/test/mocha.opts +0 -4
  211. package/tsconfig.json +0 -16
  212. package/tslint.json +0 -44
@@ -1,697 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <title>filehound.js - Documentation</title>
7
-
8
- <script src="scripts/prettify/prettify.js"></script>
9
- <script src="scripts/prettify/lang-css.js"></script>
10
- <!--[if lt IE 9]>
11
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
12
- <![endif]-->
13
- <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
14
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
15
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
16
- </head>
17
- <body>
18
-
19
- <input type="checkbox" id="nav-trigger" class="nav-trigger" />
20
- <label for="nav-trigger" class="navicon-button x">
21
- <div class="navicon"></div>
22
- </label>
23
-
24
- <label for="nav-trigger" class="overlay"></label>
25
-
26
- <nav>
27
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FileHound.html">FileHound</a><ul class='methods'><li data-type='method'><a href="FileHound.html#.accessed">accessed</a></li><li data-type='method'><a href="FileHound.html#.any">any</a></li><li data-type='method'><a href="FileHound.html#.create">create</a></li><li data-type='method'><a href="FileHound.html#.modified">modified</a></li><li data-type='method'><a href="FileHound.html#addFilter">addFilter</a></li><li data-type='method'><a href="FileHound.html#changed">changed</a></li><li data-type='method'><a href="FileHound.html#depth">depth</a></li><li data-type='method'><a href="FileHound.html#directory">directory</a></li><li data-type='method'><a href="FileHound.html#discard">discard</a></li><li data-type='method'><a href="FileHound.html#ext">ext</a></li><li data-type='method'><a href="FileHound.html#find">find</a></li><li data-type='method'><a href="FileHound.html#findSync">findSync</a></li><li data-type='method'><a href="FileHound.html#glob">glob</a></li><li data-type='method'><a href="FileHound.html#ignoreHiddenDirectories">ignoreHiddenDirectories</a></li><li data-type='method'><a href="FileHound.html#ignoreHiddenFiles">ignoreHiddenFiles</a></li><li data-type='method'><a href="FileHound.html#isEmpty">isEmpty</a></li><li data-type='method'><a href="FileHound.html#match">match</a></li><li data-type='method'><a href="FileHound.html#not">not</a></li><li data-type='method'><a href="FileHound.html#path">path</a></li><li data-type='method'><a href="FileHound.html#paths">paths</a></li><li data-type='method'><a href="FileHound.html#size">size</a></li><li data-type='method'><a href="FileHound.html#socket">socket</a></li></ul></li></ul>
28
- </nav>
29
-
30
- <div id="main">
31
-
32
- <h1 class="page-title">filehound.js</h1>
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
- <section>
41
- <article>
42
- <pre class="prettyprint source linenums"><code>"use strict";
43
- var __awaiter = (this &amp;&amp; this.__awaiter) || function (thisArg, _arguments, P, generator) {
44
- return new (P || (P = Promise))(function (resolve, reject) {
45
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
46
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
47
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
48
- step((generator = generator.apply(thisArg, _arguments || [])).next());
49
- });
50
- };
51
- Object.defineProperty(exports, "__esModule", { value: true });
52
- const _ = require("lodash");
53
- const bluebird = require("bluebird");
54
- const path = require("path");
55
- const File = require("file-js");
56
- const functions_1 = require("./functions");
57
- const files_1 = require("./files");
58
- const arrays_1 = require("./arrays");
59
- const unit_compare_1 = require("unit-compare");
60
- const events_1 = require("events");
61
- const bind_1 = require("./bind");
62
- function isDefined(value) {
63
- return value !== undefined;
64
- }
65
- function flatten(a, b) {
66
- return a.concat(b);
67
- }
68
- function toFilename(file) {
69
- return file.getName();
70
- }
71
- function isRegExpMatch(pattern) {
72
- return (file) => {
73
- return new RegExp(pattern).test(file.getName());
74
- };
75
- }
76
- function cleanExtension(ext) {
77
- if (_.startsWith(ext, '.')) {
78
- return ext.slice(1);
79
- }
80
- return ext;
81
- }
82
- /** @class */
83
- class FileHound extends events_1.EventEmitter {
84
- constructor() {
85
- super();
86
- this.filters = [];
87
- this.searchPaths = [];
88
- this.searchPaths.push(process.cwd());
89
- this.ignoreDirs = false;
90
- this.isMatch = _.noop;
91
- this.sync = false;
92
- this.directoriesOnly = false;
93
- bind_1.default(this);
94
- }
95
- // tslint:disable-next-line:valid-jsdoc
96
- /**
97
- * Static factory method to create an instance of FileHound
98
- *
99
- * @static
100
- * @memberOf FileHound
101
- * @method
102
- * create
103
- * @return FileHound instance
104
- * @example
105
- * import FileHound from 'filehound';
106
- *
107
- * const filehound = FileHound.create();
108
- */
109
- static create() {
110
- return new FileHound();
111
- }
112
- // tslint:disable-next-line:valid-jsdoc
113
- /**
114
- * Returns all matches from one of more FileHound instances
115
- *
116
- * @static
117
- * @memberOf FileHound
118
- * @method
119
- * any
120
- * @return a promise containing all matches. If the Promise fulfils,
121
- * the fulfilment value is an array of all matching files.
122
- * @example
123
- * import FileHound from 'filehound';
124
- *
125
- * const filehound = FileHound.any(fh1, fh2);
126
- */
127
- static any(...args) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- const pending = args.map(fh => fh.find());
130
- const files = yield Promise.all(pending);
131
- return files.reduce(flatten, []);
132
- });
133
- }
134
- // tslint:disable-next-line:valid-jsdoc
135
- /**
136
- * Filters by modifiction time
137
- *
138
- * @memberOf FileHound
139
- * @method
140
- * modified
141
- * @param {string} dateExpression - date expression
142
- * @return a FileHound instance
143
- * @example
144
- * import FileHound from 'filehound';
145
- *
146
- * const filehound = FileHound.create();
147
- * filehound
148
- * .modified("&lt; 2 days")
149
- * .find()
150
- * .each(console.log);
151
- */
152
- modified(pattern) {
153
- return this.addFilter((file) => {
154
- const modified = file.lastModifiedSync();
155
- return unit_compare_1.isDate(modified).assert(pattern);
156
- });
157
- }
158
- // tslint:disable-next-line:valid-jsdoc
159
- /**
160
- * Filters by file access time
161
- *
162
- * @memberOf FileHound
163
- * @method
164
- * accessed
165
- * @param {string} dateExpression - date expression
166
- * @return a FileHound instance
167
- * @example
168
- * import FileHound from 'filehound';
169
- *
170
- * const filehound = FileHound.create();
171
- * filehound
172
- * .accessed("&lt; 10 minutes")
173
- * .find()
174
- * .each(console.log);
175
- */
176
- accessed(pattern) {
177
- return this.addFilter((file) => {
178
- const accessed = file.lastAccessedSync();
179
- return unit_compare_1.isDate(accessed).assert(pattern);
180
- });
181
- }
182
- // tslint:disable-next-line:valid-jsdoc
183
- /**
184
- * Filters change time
185
- *
186
- * @memberOf FileHound
187
- * @instance
188
- * @method
189
- * changed
190
- * @param {string} dateExpression - date expression
191
- * @return a FileHound instance
192
- * @example
193
- * import FileHound from 'filehound';
194
- *
195
- * const filehound = FileHound.create();
196
- * filehound
197
- * .changed("&lt; 10 minutes")
198
- * .find()
199
- * .each(console.log);
200
- */
201
- changed(pattern) {
202
- return this.addFilter((file) => {
203
- const changed = file.lastChangedSync();
204
- return unit_compare_1.isDate(changed).assert(pattern);
205
- });
206
- }
207
- // tslint:disable-next-line:valid-jsdoc
208
- /**
209
- *
210
- * @memberOf FileHound
211
- * @instance
212
- * @method
213
- * addFilter
214
- * @param {function} function - custom filter function
215
- * @return a FileHound instance
216
- * @example
217
- * import FileHound from 'filehound';
218
- *
219
- * const filehound = FileHound.create();
220
- * filehound
221
- * .addFilter(customFilter)
222
- * .find()
223
- * .each(consoe.log);
224
- */
225
- addFilter(filter) {
226
- this.filters.push(filter);
227
- return this;
228
- }
229
- // tslint:disable-next-line:valid-jsdoc
230
- /**
231
- * Defines the search paths
232
- *
233
- * @memberOf FileHound
234
- * @instance
235
- * @method
236
- * paths
237
- * @param {array} path - array of paths
238
- * @return a FileHound instance
239
- * @example
240
- * import FileHound from 'filehound';
241
- *
242
- * const filehound = FileHound.create();
243
- * filehound
244
- * .paths("/tmp", "/etc") // or ["/tmp", "/etc"]
245
- * .find()
246
- * .each(console.log);
247
- */
248
- paths(...args) {
249
- this.searchPaths = _.uniq(arrays_1.from(args)).map(path.normalize);
250
- return this;
251
- }
252
- // tslint:disable-next-line:valid-jsdoc
253
- /**
254
- * Define the search path
255
- *
256
- * @memberOf FileHound
257
- * @instance
258
- * @method
259
- * path
260
- * @param {string} path - path
261
- * @return a FileHound instance
262
- * @example
263
- * import FileHound from 'filehound';
264
- *
265
- * const filehound = FileHound.create();
266
- * filehound
267
- * .path("/tmp")
268
- * .find()
269
- * .each(console.log);
270
- */
271
- path(path) {
272
- return this.paths(path);
273
- }
274
- // tslint:disable-next-line:valid-jsdoc
275
- /**
276
- * Ignores files or sub-directories matching pattern
277
- *
278
- * @memberOf FileHound
279
- * @instance
280
- * @method
281
- * discard
282
- * @param {string|array} regex - regex or array of regex
283
- * @return a FileHound instance
284
- * @example
285
- * import FileHound from 'filehound';
286
- *
287
- * const filehound = FileHound.create();
288
- * filehound
289
- * .discard("*.tmp*")
290
- * .find()
291
- * .each(console.log);
292
- */
293
- discard(...args) {
294
- const patterns = arrays_1.from(args);
295
- patterns.forEach((pattern) => {
296
- this.addFilter(functions_1.negate(isRegExpMatch(pattern)));
297
- });
298
- return this;
299
- }
300
- // tslint:disable-next-line:valid-jsdoc
301
- /**
302
- * Filter on file extension
303
- *
304
- * @memberOf FileHound
305
- * @instance
306
- * @method
307
- * ext
308
- * @param {string|array} extensions - extension or an array of extensions
309
- * @return a FileHound instance
310
- * @example
311
- * import FileHound from 'filehound';
312
- *
313
- * let filehound = FileHound.create();
314
- * filehound
315
- * .ext(".json")
316
- * .find()
317
- * .each(console.log);
318
- *
319
- * // array of extensions to filter by
320
- * filehound = FileHound.create();
321
- * filehound
322
- * .ext([".json", ".txt"])
323
- * .find()
324
- * .each(console.log);
325
- *
326
- * // supports var args
327
- * filehound = FileHound.create();
328
- * filehound
329
- * .ext(".json", ".txt")
330
- * .find()
331
- * .each(console.log);
332
- */
333
- ext(...args) {
334
- const extensions = arrays_1.from(args).map(cleanExtension);
335
- return this.addFilter(file => _.includes(extensions, file.getPathExtension()));
336
- }
337
- // tslint:disable-next-line:valid-jsdoc
338
- /**
339
- * Filter by file size
340
- *
341
- * @memberOf FileHound
342
- * @instance
343
- * @method
344
- * size
345
- * @param {string} sizeExpression - a size expression
346
- * @return a FileHound instance
347
- * @example
348
- * import FileHound from 'filehound';
349
- *
350
- * const filehound = FileHound.create();
351
- * filehound
352
- * .size("&lt;10kb")
353
- * .find()
354
- * .each(console.log);
355
- */
356
- size(sizeExpression) {
357
- return this.addFilter((file) => {
358
- const size = file.sizeSync();
359
- return unit_compare_1.isNumber(size).assert(sizeExpression);
360
- });
361
- }
362
- // tslint:disable-next-line:valid-jsdoc
363
- /**
364
- * Filter by zero length files
365
- *
366
- * @memberOf FileHound
367
- * @instance
368
- * @method
369
- * isEmpty
370
- * @param {string} path - path
371
- * @return a FileHound instance
372
- * @example
373
- * import FileHound from 'filehound';
374
- *
375
- * const filehound = FileHound.create();
376
- * filehound
377
- * .size("&lt;10kb")
378
- * .find()
379
- * .each(console.log);
380
- */
381
- isEmpty() {
382
- return this.size(0);
383
- }
384
- // tslint:disable-next-line:valid-jsdoc
385
- /**
386
- * Filter by a file glob
387
- *
388
- * @memberOf FileHound
389
- * @instance
390
- * @method
391
- * glob
392
- * @param {string} glob - file glob
393
- * @return a FileHound instance
394
- * @example
395
- * import FileHound from 'filehound';
396
- *
397
- * const filehound = FileHound.create();
398
- * filehound
399
- * .glob("*tmp*")
400
- * .find()
401
- * .each(console.log); // array of files names all containing 'tmp'
402
- */
403
- glob(globPattern) {
404
- return this.match(globPattern);
405
- }
406
- // tslint:disable-next-line:valid-jsdoc
407
- /**
408
- * Same as glob
409
- * @see glob
410
- */
411
- match(globPattern) {
412
- return this.addFilter(file => file.isMatch(globPattern));
413
- }
414
- // tslint:disable-next-line:valid-jsdoc
415
- /**
416
- * Negates filters
417
- *
418
- * @memberOf FileHound
419
- * @instance
420
- * @method
421
- * not
422
- * @param {string} glob - file glob
423
- * @return a FileHound instance
424
- * @example
425
- * import FileHound from 'filehound';
426
- *
427
- * const filehound = FileHound.create();
428
- * filehound
429
- * .not()
430
- * .glob("*tmp*")
431
- * .find()
432
- * .each(console.log); // array of files names NOT containing 'tmp'
433
- */
434
- not() {
435
- this.negateFilters = true;
436
- return this;
437
- }
438
- // tslint:disable-next-line:valid-jsdoc
439
- /**
440
- * Filter to ignore hidden files
441
- *
442
- * @memberOf FileHound
443
- * @instance
444
- * @method
445
- * ignoreHiddenFiles
446
- * @return a FileHound instance
447
- * @example
448
- * import FileHound from 'filehound';
449
- *
450
- * const filehound = FileHound.create();
451
- * filehound
452
- * .ignoreHiddenFiles()
453
- * .find()
454
- * .each(console.log); // array of files names that are not hidden files
455
- */
456
- ignoreHiddenFiles() {
457
- return this.addFilter(file => !file.isHiddenSync());
458
- }
459
- // tslint:disable-next-line:valid-jsdoc
460
- /**
461
- * Ignore hidden directories
462
- *
463
- * @memberOf FileHound
464
- * @instance
465
- * @method
466
- * ignoreHiddenDirectories
467
- * @return a FileHound instance
468
- * @example
469
- * import FileHound from 'filehound';
470
- *
471
- * const filehound = FileHound.create();
472
- * filehound
473
- * .ignoreHiddenDirectories()
474
- * .find()
475
- * .each(console.log); // array of files names that are not hidden directories
476
- */
477
- ignoreHiddenDirectories() {
478
- this.ignoreDirs = true;
479
- return this;
480
- }
481
- // tslint:disable-next-line:valid-jsdoc
482
- /**
483
- * Find sub-directories
484
- *
485
- * @memberOf FileHound
486
- * @instance
487
- * @method
488
- * directory
489
- * @return a FileHound instance
490
- * @example
491
- * import FileHound from 'filehound';
492
- *
493
- * const filehound = FileHound.create();
494
- * filehound
495
- * .directory()
496
- * .find()
497
- * .each(console.log); // array of matching sub-directories
498
- */
499
- directory() {
500
- this.directoriesOnly = true;
501
- return this;
502
- }
503
- // tslint:disable-next-line:valid-jsdoc
504
- /**
505
- * Find sockets
506
- *
507
- * @memberOf FileHound
508
- * @instance
509
- * @method
510
- * socket
511
- * @return a FileHound instance
512
- * @example
513
- * import FileHound from 'filehound';
514
- *
515
- * const filehound = FileHound.create();
516
- * filehound
517
- * .socket()
518
- * .find()
519
- * .each(console.log); // array of matching sockets
520
- */
521
- socket() {
522
- return this.addFilter(file => file.isSocket());
523
- }
524
- // tslint:disable-next-line:valid-jsdoc
525
- /**
526
- * Specify the directory search depth. If set to zero, recursive searching
527
- * will be disabled
528
- *
529
- * @memberOf FileHound
530
- * @instance
531
- * @method
532
- * depth
533
- * @return a FileHound instance
534
- * @example
535
- * import FileHound from 'filehound';
536
- *
537
- * const filehound = FileHound.create();
538
- * filehound
539
- * .depth(0)
540
- * .find()
541
- * .each(console.log); // array of files names only in the current directory
542
- */
543
- depth(depth) {
544
- this.maxDepth = depth;
545
- return this;
546
- }
547
- // tslint:disable-next-line:valid-jsdoc
548
- /**
549
- * Asynchronously executes a file search.
550
- *
551
- * @memberOf FileHound
552
- * @instance
553
- * @method
554
- * find
555
- * @param {function} function - Optionally accepts a callback function
556
- * @return Returns a Promise of all matches. If the Promise fulfils,
557
- * the fulfilment value is an array of all matching files
558
- * @example
559
- * import FileHound from 'filehound';
560
- *
561
- * const filehound = FileHound.create();
562
- * filehound
563
- * .find()
564
- * .each(console.log);
565
- *
566
- * // using a callback
567
- * filehound
568
- * .find((err, files) => {
569
- * if (err) return console.error(err);
570
- *
571
- * console.log(files);
572
- * });
573
- */
574
- find() {
575
- this.initFilters();
576
- const paths = this.getSearchPaths();
577
- const searches = bluebird.map(paths, this.searchAsync);
578
- const results = bluebird.all(searches)
579
- .reduce(flatten)
580
- .map(toFilename)
581
- .catch((e) => {
582
- this.emit('error', e);
583
- throw e;
584
- })
585
- .finally(() => this.emit('end'));
586
- return Promise.resolve(results);
587
- }
588
- // tslint:disable-next-line:valid-jsdoc
589
- /**
590
- * Synchronously executes a file search.
591
- *
592
- * @memberOf FileHound
593
- * @instance
594
- * @method
595
- * findSync
596
- * @return Returns an array of all matching files
597
- * @example
598
- * import FileHound from 'filehound';
599
- *
600
- * const filehound = FileHound.create();
601
- * const files = filehound.findSync();
602
- * console.log(files);
603
- *
604
- */
605
- findSync() {
606
- this.initFilters();
607
- return this.getSearchPaths()
608
- .map(this.searchSync)
609
- .reduce(flatten)
610
- .map(toFilename);
611
- }
612
- getSearchPaths() {
613
- const paths = isDefined(this.maxDepth)
614
- ? this.searchPaths
615
- : files_1.reducePaths(this.searchPaths);
616
- return arrays_1.copy(paths);
617
- }
618
- atMaxDepth(root, dir) {
619
- const depth = dir.getDepthSync() - root.getDepthSync();
620
- return isDefined(this.maxDepth) &amp;&amp; depth > this.maxDepth;
621
- }
622
- shouldFilterDirectory(root, dir) {
623
- return (this.atMaxDepth(root, dir) || (this.ignoreDirs &amp;&amp; dir.isHiddenSync()));
624
- }
625
- newMatcher() {
626
- const isMatch = functions_1.compose(this.filters);
627
- if (this.negateFilters) {
628
- return functions_1.negate(isMatch);
629
- }
630
- return isMatch;
631
- }
632
- initFilters() {
633
- this.isMatch = this.newMatcher();
634
- }
635
- searchSync(dir) {
636
- this.sync = true;
637
- const root = File.create(dir);
638
- const trackedPaths = [];
639
- const files = this.search(root, root, trackedPaths);
640
- return this.directoriesOnly ? trackedPaths.filter(this.isMatch) : files;
641
- }
642
- searchAsync(dir) {
643
- return __awaiter(this, void 0, void 0, function* () {
644
- const root = File.create(dir);
645
- const trackedPaths = [];
646
- const pending = this.search(root, root, trackedPaths);
647
- const files = yield pending;
648
- if (this.directoriesOnly) {
649
- return trackedPaths.filter(this.isMatch);
650
- }
651
- files.forEach((file) => {
652
- this.emit('match', file.getName());
653
- });
654
- return files;
655
- });
656
- }
657
- search(root, path, trackedPaths) {
658
- if (this.shouldFilterDirectory(root, path)) {
659
- return Promise.resolve([]);
660
- }
661
- const getFiles = this.sync
662
- ? path.getFilesSync.bind(path)
663
- : path.getFiles.bind(path);
664
- return getFiles()
665
- .map((file) => {
666
- if (file.isDirectorySync()) {
667
- if (!this.shouldFilterDirectory(root, file)) {
668
- trackedPaths.push(file);
669
- }
670
- return this.search(root, file, trackedPaths);
671
- }
672
- return file;
673
- })
674
- .reduce(flatten, [])
675
- .filter(this.isMatch);
676
- }
677
- }
678
- exports.default = FileHound;
679
- //# sourceMappingURL=filehound.js.map</code></pre>
680
- </article>
681
- </section>
682
-
683
-
684
-
685
-
686
- </div>
687
-
688
- <br class="clear">
689
-
690
- <footer>
691
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Jan 05 2018 11:12:21 GMT+0000 (GMT) using the Minami theme.
692
- </footer>
693
-
694
- <script>prettyPrint();</script>
695
- <script src="scripts/linenumber.js"></script>
696
- </body>
697
- </html>