77
88# glob-cache [ ![ npm version] [ npmv-img ]] [ npmv-url ] [ ![ License] [ license-img ]] [ license-url ] [ ![ Libera Manifesto] [ libera-manifesto-img ]] [ libera-manifesto-url ]
99
10- > Best and fastest file globbing solution for Node.js - can use ** any** glob library like ` glob ` , ` globby ` or ` fast-glob ` ! Streaming, Promise and Hook APIs, with built in caching layer using ` cacache ` . Makes you Instant Fast™.
10+ > Best and fastest file globbing solution for Node.js - can use ** any** glob
11+ > library like ` glob ` , ` globby ` or ` fast-glob ` ! Streaming, Promise and Hook
12+ > APIs, with built in caching layer using ` cacache ` . Makes you Instant Fast™.
1113
1214Please consider following this project's author,
1315[ Charlike Mike Reagent] ( https://github.com/tunnckoCore ) , and :star : the project
@@ -67,31 +69,31 @@ from [GitHub Actions](https://github.com/features/actions) with
6769
6870- [ Install] ( #install )
6971- [ API] ( #api )
70- * [ globCache] ( #globcache )
71- + [ Signature] ( #signature )
72- + [ Params] ( #params )
73- + [ Examples] ( #examples )
74- * [ globCache.stream] ( #globcachestream )
75- + [ Signature] ( #signature-1 )
76- + [ Params] ( #params-1 )
77- + [ Examples] ( #examples-1 )
78- * [ globCache.promise] ( #globcachepromise )
79- + [ Signature] ( #signature-2 )
80- + [ Params] ( #params-2 )
81- + [ Examples] ( #examples-2 )
72+ - [ globCache] ( #globcache )
73+ - [ Signature] ( #signature )
74+ - [ Params] ( #params )
75+ - [ Examples] ( #examples )
76+ - [ globCache.stream] ( #globcachestream )
77+ - [ Signature] ( #signature-1 )
78+ - [ Params] ( #params-1 )
79+ - [ Examples] ( #examples-1 )
80+ - [ globCache.promise] ( #globcachepromise )
81+ - [ Signature] ( #signature-2 )
82+ - [ Params] ( #params-2 )
83+ - [ Examples] ( #examples-2 )
8284- [ Context and how it works] ( #context-and-how-it-works )
8385- [ Contributing] ( #contributing )
84- * [ Guides and Community] ( #guides-and-community )
85- * [ Support the project] ( #support-the-project )
86+ - [ Guides and Community] ( #guides-and-community )
87+ - [ Support the project] ( #support-the-project )
8688- [ Contributors] ( #contributors )
8789- [ License] ( #license )
8890
89- _ (TOC generated by [ verb] ( https://github.com/verbose/verb ) using [ markdown-toc] ( https://github.com/jonschlinkert/markdown-toc ) )_
91+ _ (TOC generated by [ verb] ( https://github.com/verbose/verb ) using
92+ [ markdown-toc] ( https://github.com/jonschlinkert/markdown-toc ) )_
9093
9194## Install
9295
93- This project requires [ ** Node.js** ] ( https://nodejs.org ) ** >=10.18**
94- _ (see
96+ This project requires [ ** Node.js** ] ( https://nodejs.org ) ** >=10.18** _ (see
9597[ Support & Release Policy] ( https://github.com/tunnckoCoreLabs/support-release-policy ) )_ .
9698Install it using [ ** yarn** ] ( https://yarnpkg.com ) or
9799[ ** npm** ] ( https://npmjs.com ) .<br > _ We highly recommend to use Yarn when you
@@ -109,9 +111,9 @@ _Generated using [jest-runner-docs](https://ghub.now.sh/jest-runner-docs)._
109111
110112### [ globCache] ( ./src/index.js#L40 )
111113
112- A mirror of ` globCache.stream ` and so an "async generator" function,
113- returning an AsyncIterable. This mirror exists because it's
114- a common practice to have a ` (globPatterns, options) ` signature.
114+ A mirror of ` globCache.stream ` and so an "async generator" function, returning
115+ an AsyncIterable. This mirror exists because it's a common practice to have a
116+ ` (globPatterns, options) ` signature.
115117
116118<span id =" globcache-signature " ></span >
117119
@@ -136,24 +138,25 @@ function(patterns, options)
136138const globCache = require('glob-cache');
137139
138140const iterable = globCache(['src/*.js', 'test/*.{js,ts}'], {
139- cwd: './foo/bar'
141+ cwd: './foo/bar',
140142});
141143
142144// equivalent to
143145
144146const iter = globCache.stream({
145147 include: ['src/*.js', 'test/*.{js,ts}'],
146- cwd: './foo/bar'
148+ cwd: './foo/bar',
147149});
148150` ` `
149151
150152### [globCache .stream ](./ src / index .js #L84 )
151153
152- Match files and folders with glob patterns , by default using [fast - glob ' s `.stream()`](https://ghub.now.sh/fast-glob).
153- This function is [async generator](https : // javascript.info/async-iterators-generators)
154- and returns " async iterable" , so you can use the ` for await ... of ` loop. Note that this loop
155- should be used inside an ` async function ` .
156- Each item is a [Context ](#context -and -how -it -works ) object, which is also passed to each hook.
154+ Match files and folders with glob patterns , by default using
155+ [fast - glob ' s `.stream()`](https://ghub.now.sh/fast-glob). This function is
156+ [async generator ](https :// javascript.info/async-iterators-generators) and
157+ returns " async iterable" , so you can use the ` for await ... of ` loop . Note that
158+ this loop should be used inside an ` async function ` . Each item is a
159+ [Context ](#context - and - how - it - works ) object , which is also passed to each hook .
157160
158161< span id = " globcache.stream-signature" > </span >
159162
@@ -170,17 +173,25 @@ function(options)
170173- ` options.cwd ` ** {string }** - working directory , defaults to ` process.cwd() `
171174- ` options.include ` ** {string|Array }** - string or array of string glob patterns
172175- ` options.patterns ` ** {string|Array }** - alias of ` options.include `
173- - ` options.exclude ` ** {string|Array }** - ignore glob patterns , passed to ` options.globOptions.ignore `
176+ - ` options.exclude ` ** {string|Array }** - ignore glob patterns , passed to
177+ ` options.globOptions.ignore `
174178- ` options.ignore ` ** {string|Array }** - alias of ` options.exclude `
175- - ` options.hooks ` ** {object }** - an object with hooks functions , each hook passed with [Context ](#context - and - how - it - works )
179+ - ` options.hooks ` ** {object }** - an object with hooks functions , each hook
180+ passed with [Context ](#context - and - how - it - works )
176181- ` options.hooks.found ` ** {Function }** - called when a cache for a file is found
177- - ` options.hooks.notFound ` ** {Function }** - called when file is not found in cache (usually the first hit )
178- - ` options.hooks.changed ` ** {Function }** - called always when source file differs the cache file
179- - ` options.hooks.notChanged ` ** {Function }** - called when both source file and cache file are " the same"
182+ - ` options.hooks.notFound ` ** {Function }** - called when file is not found in
183+ cache (usually the first hit )
184+ - ` options.hooks.changed ` ** {Function }** - called always when source file
185+ differs the cache file
186+ - ` options.hooks.notChanged ` ** {Function }** - called when both source file and
187+ cache file are " the same"
180188- ` options.hooks.always ` ** {Function }** - called always , no matter of the state
181- - ` options.glob ` ** {Function }** - a function `(patterns , options ) => {}` or globbing library like [glob][], [globby][], [fast-glob][]
182- - ` options .globOptions ` **{object}** - options passed to the ` options .glob ` library
183- - ` options .cacheLocation ` **{string}** - a filepath location of the cache, defaults to ` .cache /glob -cache ` in ` options .cwd `
189+ - ` options.glob ` ** {Function }** - a function `(patterns , options ) => {}` or
190+ globbing library like [glob][], [globby][], [fast-glob][]
191+ - ` options .globOptions ` **{object}** - options passed to the ` options .glob `
192+ library
193+ - ` options .cacheLocation ` **{string}** - a filepath location of the cache,
194+ defaults to ` .cache /glob -cache ` in ` options .cwd `
184195- ` returns ` **{AsyncIterable}**
185196
186197<span id="globcache.stream-examples"></span>
@@ -194,7 +205,7 @@ const globCache = require('glob-cache');
194205 // Using the Stream API
195206 const iterable = globCache .stream ({
196207 include: ' src/*.js' ,
197- cacheLocation: ' ./foo-cache'
208+ cacheLocation: ' ./foo-cache' ,
198209 });
199210
200211 for await (const ctx of iterable ) {
@@ -205,8 +216,8 @@ const globCache = require('glob-cache');
205216
206217### [globCache.promise](./src/index.js#L243)
207218
208- Using the Promise API allows you to use the Hooks API, and it's actually
209- the recommended way of using the hooks api. By default, if the returned promise
219+ Using the Promise API allows you to use the Hooks API, and it's actually the
220+ recommended way of using the hooks api. By default, if the returned promise
210221resolves, it will be an empty array. That's intentional, because if you are
211222using the hooks api it's unnecessary to pollute the memory putting huge objects
212223to a "result array". So if you want results array to contain the Context objects
@@ -224,9 +235,12 @@ function(options)
224235
225236#### Params
226237
227- - `options` ** {object }** - see ` globCache.stream ` options , in addition here we have ` options.buffered ` too
228- - ` options.buffered ` ** {boolean }** - if ` true ` returned array will contain [Context ]((#context - and - how - it - works )) objects , default ` false `
229- - ` returns ` ** {Promise }** - if ` options.buffered: true ` resolves to ` Array<Context> ` , otherwise empty array
238+ - `options` ** {object }** - see ` globCache.stream ` options , in addition here we
239+ have ` options.buffered ` too
240+ - ` options.buffered ` ** {boolean }** - if ` true ` returned array will contain
241+ [Context ](<(#context -and -how -it -works )>) objects , default ` false `
242+ - ` returns ` ** {Promise }** - if ` options.buffered: true ` resolves to
243+ ` Array<Context> ` , otherwise empty array
230244
231245< span id = " globcache.promise-examples" > </span >
232246
@@ -245,7 +259,7 @@ const globby = require('globby');
245259 hooks: {
246260 changed(ctx) {},
247261 always(ctx) {},
248- }
262+ },
249263 });
250264 console.log(res); // => []
251265
@@ -465,10 +479,9 @@ your [support](#support-the-project) to them:
465479
466480## License
467481
468- Copyright (c) 2020-present,
469- [Charlike Mike Reagent](https://tunnckocore.com) ` < opensource @tunnckocore .com > `
470- & [contributors](#wonderful-contributors).<br> Released under the
471- [MPL-2.0 License][license-url].
482+ Copyright (c) 2020-present, [Charlike Mike Reagent](https://tunnckocore.com)
483+ ` < opensource @tunnckocore .com > ` & [contributors](#wonderful-contributors).<br>
484+ Released under the [MPL-2.0 License][license-url].
472485
473486<!-- badges -->
474487
@@ -498,7 +511,7 @@ Copyright (c) 2020-present,
498511[codestyle-img]: https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb&cache=300
499512
500513[linuxbuild-url]: https://github.com/tunnckocore/opensource/actions
501- [linuxbuild-img]: https://badgen. net/github/checks/tunnckoCore/opensource/master?cache=300&label=build&icon=github
514+ [linuxbuild-img]: https://badgen- net.charlike.now.sh /github/checks/tunnckoCore/opensource/master/test ?cache=300&label=build&icon=github
502515
503516[ccommits-url]: https://conventionalcommits.org/
504517[ccommits-img]: https://badgen.net/badge/conventional%20commits/v1.0.0/green?cache=300
@@ -563,4 +576,4 @@ Copyright (c) 2020-present,
563576[fast-glob]: https://github.com/mrmlnc/fast-glob
564577[glob]: https://github.com/isaacs/node-glob
565578[globby]: https://github.com/sindresorhus/globby
566- [tiny-glob]: https://github.com/terkelg/tiny-glob
579+ [tiny-glob]: https://github.com/terkelg/tiny-glob
0 commit comments