From f26ed9b31c629b2500c4782725c857be58ae0458 Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Thu, 16 Nov 2017 18:16:06 +0300 Subject: [PATCH 1/2] refactor(glob-stream): Update definitions --- types/glob-stream/glob-stream-tests.ts | 27 ++++++++++---- types/glob-stream/index.d.ts | 49 +++++++++++++++++++------- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/types/glob-stream/glob-stream-tests.ts b/types/glob-stream/glob-stream-tests.ts index 617246799c..ca436746cc 100644 --- a/types/glob-stream/glob-stream-tests.ts +++ b/types/glob-stream/glob-stream-tests.ts @@ -2,9 +2,24 @@ import gs = require('glob-stream'); var read: NodeJS.ReadableStream; -read = gs.create('xx'); -read = gs.create('xx', {}); -read = gs.create(['xx'], {}); -read = gs.create(['xx'], {cwd: 'xx'}); -read = gs.create(['xx'], {base: 'xx'}); -read = gs.create(['xx'], {cwdbase: true}); +// Types +var strPredicate: gs.UniqueByStringPredicate = 'base'; +var fnPredicate: gs.UniqueByFunctionPredicate = (entry) => entry.path; + +// Base cases +read = gs('xx'); +read = gs('xx', {}); +read = gs(['xx'], {}); + +// Package options +read = gs(['xx'], { allowEmpty: true }); +read = gs(['xx'], { base: 'xx' }); +read = gs(['xx'], { cwdbase: true }); +read = gs(['xx'], { uniqueBy: 'path' }); +read = gs(['xx'], { uniqueBy: 'base' }); +read = gs(['xx'], { uniqueBy: 'cwd' }); +read = gs(['xx'], { uniqueBy: (entry: gs.Entry) => entry.path }); + +// Glob options +read = gs(['xx'], { root: 'root' }); +read = gs(['xx'], { debug: true }); diff --git a/types/glob-stream/index.d.ts b/types/glob-stream/index.d.ts index 36a5d9fb92..f3bec97f6c 100644 --- a/types/glob-stream/index.d.ts +++ b/types/glob-stream/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for glob-stream v3.1.12 +// Type definitions for glob-stream v6.1.0 // Project: https://github.com/wearefractal/glob-stream // Definitions by: Bart van der Schoor // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -8,17 +8,40 @@ import glob = require('glob'); -export interface Options extends glob.IOptions { - cwd?: string; - base?: string; - cwdbase?: boolean; +declare function GlobStream(glob: string | string[]): NodeJS.ReadableStream; +declare function GlobStream(glob: string | string[], options: GlobStream.Options): NodeJS.ReadableStream; + +declare namespace GlobStream { + export interface Entry { + cwd: string; + base: string; + path: string; + } + + export type UniqueByStringPredicate = 'cwd' | 'base' | 'path'; + export type UniqueByFunctionPredicate = (entry: Entry) => string; + + export interface Options extends glob.IOptions { + /** + * Whether or not to error upon an empty singular glob. + */ + allowEmpty?: boolean; + /** + * The absolute segment of the glob path that isn't a glob. This value is attached + * to each globobject and is useful for relative pathing. + */ + base?: string; + /** + * Whether or not the `cwd` and `base` should be the same. + */ + cwdbase?: boolean; + /** + * Filters stream to remove duplicates based on the string property name or the result of function. + * When using a function, the function receives the streamed + * data (objects containing `cwd`, `base`, `path` properties) to compare against. + */ + uniqueBy?: UniqueByStringPredicate | UniqueByFunctionPredicate; + } } -export interface Element { - cwd: string; - base: string; - path: string; -} - -export declare function create(glob: string, opts?: Options): NodeJS.ReadableStream; -export declare function create(globs: string[], opts?: Options): NodeJS.ReadableStream; +export = GlobStream; From 9fce513d769c2bd1788cfb0e1b000f92d0347604 Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Thu, 16 Nov 2017 18:17:02 +0300 Subject: [PATCH 2/2] chore(glob-stream): Add me to authors --- types/glob-stream/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/glob-stream/index.d.ts b/types/glob-stream/index.d.ts index f3bec97f6c..d9d9c6d7c6 100644 --- a/types/glob-stream/index.d.ts +++ b/types/glob-stream/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for glob-stream v6.1.0 // Project: https://github.com/wearefractal/glob-stream // Definitions by: Bart van der Schoor +// mrmlnc // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped ///