From ccde25e8d410fdd5eb97c1ebe7c0a29e7479ea33 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 10 Jun 2019 21:41:14 +0300 Subject: [PATCH] refactor: set async method as default method --- README.md | 2 - .../suites/async/fast-glob-current.ts | 2 +- src/index.spec.ts | 6 +- src/index.ts | 71 ++++++++----------- 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 0d329d10..d7de4f3c 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ $ npm install --save fast-glob const fg = require('fast-glob'); fg(['src/**/*.js', '!src/**/*.spec.js']).then((entries) => console.log(entries)); -fg.async(['src/**/*.js', '!src/**/*.spec.js']).then((entries) => console.log(entries)); ``` #### Synchronous @@ -61,7 +60,6 @@ stream.once('end', () => console.log(entries)); ## API ### fg(patterns, [options]) -### fg.async(patterns, [options]) Returns a `Promise` with an array of matching [entries](#entry). diff --git a/src/benchmark/suites/async/fast-glob-current.ts b/src/benchmark/suites/async/fast-glob-current.ts index 6ffc2e9b..7913d498 100644 --- a/src/benchmark/suites/async/fast-glob-current.ts +++ b/src/benchmark/suites/async/fast-glob-current.ts @@ -11,7 +11,7 @@ const settings = new Settings({ const timeStart = utils.timeStart(); -glob.async(process.env.BENCHMARK_PATTERN as string, settings) +glob(process.env.BENCHMARK_PATTERN as string, settings) .then((matches) => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); diff --git a/src/index.spec.ts b/src/index.spec.ts index 7140be1b..cc9c654c 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -51,7 +51,7 @@ describe('Package', () => { it('should throw an error when input values can not pass validation', async () => { try { /* tslint:disable-next-line no-any */ - await pkg.async(null as any); + await pkg(null as any); throw new Error('An unexpected error was found.'); } catch (error) { assert.strictEqual((error as Error).toString(), 'TypeError: Patterns must be a string or an array of strings'); @@ -69,7 +69,7 @@ describe('Package', () => { 'fixtures/second/nested/file.md' ]; - const actual = await pkg.async(['fixtures/**/*.md']); + const actual = await pkg(['fixtures/**/*.md']); actual.sort(); @@ -86,7 +86,7 @@ describe('Package', () => { 'fixtures/second/nested/file.md' ]; - const actual = await pkg.async(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']); + const actual = await pkg(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']); actual.sort(); diff --git a/src/index.ts b/src/index.ts index b274291d..8e5a3dd2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,19 +13,9 @@ type EntryObjectModePredicate = { [P in keyof Pick]-?: tr type EntryStatsPredicate = { [P in keyof Pick]-?: true }; type EntryObjectPredicate = EntryObjectModePredicate | EntryStatsPredicate; -function sync(source: Pattern | Pattern[], options: Options & EntryObjectPredicate): Entry[]; -function sync(source: Pattern | Pattern[], options?: Options): string[]; -function sync(source: Pattern | Pattern[], options?: Options): EntryItem[] { - assertPatternsInput(source); - - const works = getWorks(source, ProviderSync, options); - - return utils.array.flatten(works); -} - -function async(source: Pattern | Pattern[], options: Options & EntryObjectPredicate): Promise; -function async(source: Pattern | Pattern[], options?: Options): Promise; -function async(source: Pattern | Pattern[], options?: Options): Promise { +function FastGlob(source: Pattern | Pattern[], options: Options & EntryObjectPredicate): Promise; +function FastGlob(source: Pattern | Pattern[], options?: Options): Promise; +function FastGlob(source: Pattern | Pattern[], options?: Options): Promise { try { assertPatternsInput(source); } catch (error) { @@ -37,26 +27,38 @@ function async(source: Pattern | Pattern[], options?: Options): Promise(source: Pattern | Pattern[], _Provider: new (settings: Settings) => Provider, options?: Options): T[] { @@ -82,15 +84,4 @@ function isString(source: unknown): source is string { return typeof source === 'string'; } -export default async; -export { - async, - sync, - stream, - generateTasks, - - Options, - Settings, - Task, - EntryItem -}; +export = FastGlob;