From eab005010b1be143387d0500c074007459f89df8 Mon Sep 17 00:00:00 2001 From: Denis Malinochkin Date: Mon, 27 Jan 2020 21:47:29 +0300 Subject: [PATCH] micromatch: add options for scan method (#41858) --- types/micromatch/index.d.ts | 58 +++++++++++++++++++++++++++- types/micromatch/micromatch-tests.ts | 9 +++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/types/micromatch/index.d.ts b/types/micromatch/index.d.ts index 806f93231e..01014d2d81 100644 --- a/types/micromatch/index.d.ts +++ b/types/micromatch/index.d.ts @@ -266,6 +266,60 @@ declare namespace micromatch { */ windows?: boolean; } + + interface ScanOptions extends Options { + /** + * When `true`, the returned object will include an array of `tokens` (objects), representing each path "segment" in the scanned glob pattern. + * + * @default false + */ + tokens?: boolean; + /** + * When `true`, the returned object will include an array of strings representing each path "segment" in the scanned glob pattern. + * This is automatically enabled when `options.tokens` is `true`. + * + * @default false + */ + parts?: boolean; + } + + interface ScanInfo { + prefix: string; + input: string; + start: number; + base: string; + glob: string; + isBrace: boolean; + isBracket: boolean; + isGlob: boolean; + isExtglob: boolean; + isGlobstar: boolean; + negated: boolean; + } + + interface ScanInfoToken { + value: string; + depth: number; + isGlob: boolean; + + backslashes?: boolean; + isBrace?: boolean; + isBracket?: boolean; + isExtglob?: boolean; + isGlobstar?: boolean; + isPrefix?: boolean; + negated?: boolean; + } + + interface ScanInfoWithParts extends ScanInfo { + slashes: number[]; + parts: string[]; + } + + interface ScanInfoWithTokens extends ScanInfoWithParts { + maxDepth: number; + tokens: ScanInfoToken[]; + } } interface Micromatch { @@ -610,7 +664,9 @@ interface Micromatch { /** * Scan a glob pattern to separate the pattern into segments. */ - scan(pattern: string, options?: micromatch.Options): object; + scan(pattern: string, options: { parts: true } & micromatch.ScanOptions): micromatch.ScanInfoWithParts; + scan(pattern: string, options: { tokens: true } & micromatch.ScanOptions): micromatch.ScanInfoWithTokens; + scan(pattern: string, options?: micromatch.ScanOptions): micromatch.ScanInfo; } export as namespace micromatch; diff --git a/types/micromatch/micromatch-tests.ts b/types/micromatch/micromatch-tests.ts index 60bae6800b..f7cee74123 100644 --- a/types/micromatch/micromatch-tests.ts +++ b/types/micromatch/micromatch-tests.ts @@ -64,3 +64,12 @@ const regex: RegExp = mm.makeRe('*.js'); // .braces strArrResult = mm.braces('*.js'); strArrResult = mm.braces('*.js', { expand: true }); + +// $ExpectType ScanInfo +mm.scan('*'); + +// $ExpectType ScanInfoWithTokens +mm.scan('*', { tokens: true }); + +// $ExpectType ScanInfoWithParts +mm.scan('*', { parts: true });