From d4220eb84cc4da540909c7e65d63028e399bbdcd Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 3 Jan 2016 13:35:48 +0200 Subject: [PATCH 01/12] Add type definitions for micromatch (and parse-glob) --- micromatch/micromatch-tests.ts | 32 +++++++ micromatch/micromatch.d.ts | 164 +++++++++++++++++++++++++++++++++ parse-glob/parse-glob-tests.ts | 21 +++++ parse-glob/parse-glob.d.ts | 92 ++++++++++++++++++ 4 files changed, 309 insertions(+) create mode 100644 micromatch/micromatch-tests.ts create mode 100644 micromatch/micromatch.d.ts create mode 100644 parse-glob/parse-glob-tests.ts create mode 100644 parse-glob/parse-glob.d.ts diff --git a/micromatch/micromatch-tests.ts b/micromatch/micromatch-tests.ts new file mode 100644 index 000000000..8452acdcb --- /dev/null +++ b/micromatch/micromatch-tests.ts @@ -0,0 +1,32 @@ +/// +import mm = require('micromatch'); + +// Usage. +mm(['a.js', 'b.md', 'c.txt'], '*.{js,txt}'); + +// Multiple patterns. +mm(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.md', '*.txt']); + +// "isMatch" method. +mm.isMatch('.verb.md', '*.md'); +mm.isMatch('.verb.md', '*.md', {dot: true}); +mm.isMatch('.verb.md', {dot: true}); + +// "contains" method. +mm.contains('a/b/c', 'a/b'); + +// "matcher" method. +var isMatch = mm.matcher('*.md'); + +// "filter" method. +var fn = mm.filter('*.md'); + +// "any" method. +mm.any('abc', ['!*z']); +mm.any('abc', 'a*'); + +// "expand" method. +mm.expand('*.js'); + +// "makeRe" method. +mm.makeRe('*.js'); diff --git a/micromatch/micromatch.d.ts b/micromatch/micromatch.d.ts new file mode 100644 index 000000000..68cfbc219 --- /dev/null +++ b/micromatch/micromatch.d.ts @@ -0,0 +1,164 @@ +// Type definitions for micromatch 2.3.7 +// Project: https://www.npmjs.com/package/micromatch +// Definitions by: glen-84 +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare namespace Micromatch { + type Pattern = (string | RegExp | ((filePath: string) => boolean)); +} + +declare module 'micromatch' { + interface MicromatchOptions { + /** + * Normalize slashes in file paths and glob patterns to forward slashes. + */ + unixify?: boolean; + /** + * Match dotfiles. Same behavior as minimatch. + */ + dot?: boolean; + /** + * Unescape slashes in glob patterns. Use cautiously, especially on windows. + */ + unescape?: boolean; + /** + * Remove duplicate elements from the result array. + */ + nodupes?: boolean; + /** + * Allow glob patterns without slashes to match a file path based on its basename. Same behavior as minimatch. + */ + matchBase?: boolean; + /** + * Don't expand braces in glob patterns. Same behavior as minimatch nobrace. + */ + nobraces?: boolean; + /** + * Don't expand POSIX bracket expressions. + */ + nobrackets?: boolean; + /** + * Don't expand extended globs. + */ + noextglob?: boolean; + /** + * Use a case-insensitive regex for matching files. Same behavior as minimatch. + */ + nocase?: boolean; + /** + * If true, when no matches are found the actual (array-ified) glob pattern is returned instead of an empty + * array. Same behavior as minimatch. + */ + nonull?: boolean; + /** + * Cache the platform (e.g. win32) to prevent this from being looked up for every file path. + */ + cache?: boolean; + } + + interface Glob { + options: {}; // TODO: Expand? + pattern: string; + history: {msg: any, pattern: string}[]; + tokens: ParseGlob.Result; + orig: string; + negated: boolean; + + /** + * Initialize defaults. + */ + init(pattern: string): void; + + /** + * Push a change into `glob.history`. Useful for debugging. + */ + track(msg: any): void; + + /** + * Return true if `glob.pattern` was negated with `!`, also remove the `!` from the pattern. + */ + isNegated(): boolean; + + /** + * Expand braces in the given glob pattern. + */ + braces(): void; + + /** + * Expand bracket expressions in `glob.pattern`. + */ + brackets(): void; + + /** + * Expand extended globs in `glob.pattern`. + */ + extglob(): void; + + /** + * Parse the given pattern. + */ + parse(pattern: string): ParseGlob.Result; + + /** + * Escape special characters in the given string. + */ + escape(pattern: string): string; + + /** + * Unescape special characters in the given string. + */ + unescape(pattern: string): string; + } + + interface Micromatch { + (files: string | string[], patterns: Micromatch.Pattern | Micromatch.Pattern[]): string[]; + + isMatch: { + /** + * Returns true if a file path matches the given pattern. + */ + (filePath: string, pattern: Micromatch.Pattern, opts?: MicromatchOptions): boolean; + /** + * Returns a function for matching. + */ + (filePath: string, opts?: MicromatchOptions): ((filePath: string) => boolean); + }; + + /** + * Returns true if any part of a file path matches the given pattern. Think of this as "has path" versus + * "is path". + */ + contains(filePath: string, pattern: Micromatch.Pattern, opts?: MicromatchOptions): boolean; + + /** + * Returns a function for matching using the supplied pattern. e.g. create your own "matcher". The advantage of + * this method is that the pattern can be compiled outside of a loop. + */ + matcher(pattern: Micromatch.Pattern): ((filePath: string) => boolean); + + /** + * Returns a function that can be passed to Array#filter(). + */ + filter(patterns: Micromatch.Pattern | Micromatch.Pattern[], opts?: MicromatchOptions): ((filePath: string) => boolean); + + /** + * Returns true if a file path matches any of the given patterns. + */ + any(filePath: string, patterns: Micromatch.Pattern | Micromatch.Pattern[], opts?: MicromatchOptions): boolean; + + /** + * Returns an object with a regex-compatible string and tokens. + */ + expand(pattern: string, opts?: MicromatchOptions): Glob | {pattern: string, tokens: ParseGlob.Result, options: {} /* TODO: Expand? */}; + + /** + * Create a regular expression for matching file paths based on the given pattern. + */ + makeRe(pattern: string, opts?: MicromatchOptions): RegExp; + } + + const micromatch: Micromatch; + export = micromatch; +} diff --git a/parse-glob/parse-glob-tests.ts b/parse-glob/parse-glob-tests.ts new file mode 100644 index 000000000..9a6697e3e --- /dev/null +++ b/parse-glob/parse-glob-tests.ts @@ -0,0 +1,21 @@ +/// +import parseGlob = require('parse-glob'); + +var result = parseGlob('a/b/c/**/*.{yml,json}'); + +result.base; +result.glob; +result.is.braces; +result.is.brackets; +result.is.dotdir; +result.is.dotfile; +result.is.extglob; +result.is.glob; +result.is.globstar; +result.is.negated; +result.orig; +result.path.basename; +result.path.dirname; +result.path.ext; +result.path.extname; +result.path.filename; diff --git a/parse-glob/parse-glob.d.ts b/parse-glob/parse-glob.d.ts new file mode 100644 index 000000000..460905e12 --- /dev/null +++ b/parse-glob/parse-glob.d.ts @@ -0,0 +1,92 @@ +// Type definitions for parse-glob 3.0.4 +// Project: https://www.npmjs.com/package/parse-glob +// Definitions by: glen-84 +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare namespace ParseGlob { + interface Result { + /** + * A copy of the original, unmodified glob pattern. + */ + orig: string; + /** + * An object with boolean information about the glob. + */ + is: { + /** + * True if the pattern actually is a glob pattern. + */ + glob: boolean; + /** + * True if it's a negation pattern (!/foo.js). + */ + negated: boolean; + /** + * True if it has extglobs (@(foo|bar)). + */ + extglob: boolean; + /** + * True if it has braces ({1..2} or .{txt,md}). + */ + braces: boolean; + /** + * True if it has POSIX brackets ([[:alpha:]]). + */ + brackets: boolean; + /** + * True if the pattern has a globstar (double star, **). + */ + globstar: boolean; + /** + * True if the pattern should match dotfiles. + */ + dotfile: boolean; + /** + * True if the pattern should match dot-directories (like .git). + */ + dotdir: boolean; + }; + /** + * The glob pattern part of the string, if any. + */ + glob: string; + /** + * The non-glob part of the string, if any. + */ + base: string; + /** + * File path segments. + */ + path: { + /** + * Directory. + */ + dirname: string; + /** + * File name with extension. + */ + basename: string; + /** + * File name without extension. + */ + filename: string; + /** + * File extension with dot. + */ + extname: string; + /** + * File extension without dot. + */ + ext: string; + }; + } +} + +declare module 'parse-glob' { + interface ParseGlob { + (glob: string): ParseGlob.Result; + } + + const parseGlob: ParseGlob; + export = parseGlob; +} From 9bb2b005a235655464833e6e0d2d9d7bd097e89b Mon Sep 17 00:00:00 2001 From: Glen Date: Thu, 7 Jan 2016 16:42:51 +0200 Subject: [PATCH 02/12] Change project URLs --- micromatch/micromatch.d.ts | 2 +- parse-glob/parse-glob.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/micromatch/micromatch.d.ts b/micromatch/micromatch.d.ts index 68cfbc219..5d44244ac 100644 --- a/micromatch/micromatch.d.ts +++ b/micromatch/micromatch.d.ts @@ -1,5 +1,5 @@ // Type definitions for micromatch 2.3.7 -// Project: https://www.npmjs.com/package/micromatch +// Project: https://github.com/jonschlinkert/micromatch // Definitions by: glen-84 // Definitions: https://github.com/borisyankov/DefinitelyTyped diff --git a/parse-glob/parse-glob.d.ts b/parse-glob/parse-glob.d.ts index 460905e12..67fa772be 100644 --- a/parse-glob/parse-glob.d.ts +++ b/parse-glob/parse-glob.d.ts @@ -1,5 +1,5 @@ // Type definitions for parse-glob 3.0.4 -// Project: https://www.npmjs.com/package/parse-glob +// Project: https://github.com/jonschlinkert/parse-glob // Definitions by: glen-84 // Definitions: https://github.com/borisyankov/DefinitelyTyped From da35ad861da5ba65611519f13ecd5fbfc32f966d Mon Sep 17 00:00:00 2001 From: Glen Date: Thu, 7 Jan 2016 16:49:05 +0200 Subject: [PATCH 03/12] Update DefinitelyTyped repository URL --- micromatch/micromatch.d.ts | 2 +- parse-glob/parse-glob.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/micromatch/micromatch.d.ts b/micromatch/micromatch.d.ts index 5d44244ac..f8b101a61 100644 --- a/micromatch/micromatch.d.ts +++ b/micromatch/micromatch.d.ts @@ -1,7 +1,7 @@ // Type definitions for micromatch 2.3.7 // Project: https://github.com/jonschlinkert/micromatch // Definitions by: glen-84 -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// diff --git a/parse-glob/parse-glob.d.ts b/parse-glob/parse-glob.d.ts index 67fa772be..14a73d62d 100644 --- a/parse-glob/parse-glob.d.ts +++ b/parse-glob/parse-glob.d.ts @@ -1,7 +1,7 @@ // Type definitions for parse-glob 3.0.4 // Project: https://github.com/jonschlinkert/parse-glob // Definitions by: glen-84 -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace ParseGlob { interface Result { From 4e75dc7afa40a7c2039fd8bcb0865819eeadc007 Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 10 Jan 2016 13:12:55 +0200 Subject: [PATCH 04/12] Improve tests --- micromatch/micromatch-tests.ts | 27 ++++++++++++++++--------- parse-glob/parse-glob-tests.ts | 37 ++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/micromatch/micromatch-tests.ts b/micromatch/micromatch-tests.ts index 8452acdcb..7cf5e1eab 100644 --- a/micromatch/micromatch-tests.ts +++ b/micromatch/micromatch-tests.ts @@ -1,32 +1,41 @@ /// import mm = require('micromatch'); +var result: string[]; +var boolResult: boolean; +var regExpResult: RegExp; + // Usage. -mm(['a.js', 'b.md', 'c.txt'], '*.{js,txt}'); +result = mm(['a.js', 'b.md', 'c.txt'], '*.{js,txt}'); // Multiple patterns. -mm(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.md', '*.txt']); +result = mm(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.md', '*.txt']); // "isMatch" method. -mm.isMatch('.verb.md', '*.md'); -mm.isMatch('.verb.md', '*.md', {dot: true}); -mm.isMatch('.verb.md', {dot: true}); +boolResult = mm.isMatch('.verb.md', '*.md'); +boolResult = mm.isMatch('.verb.md', '*.md', {dot: true}); +boolResult = mm.isMatch('*.md', {dot: true})('.verb.md'); // "contains" method. -mm.contains('a/b/c', 'a/b'); +boolResult = mm.contains('a/b/c', 'a/b'); +boolResult = mm.contains('a/b/c', 'a/b', {dot: true}); // "matcher" method. var isMatch = mm.matcher('*.md'); // "filter" method. var fn = mm.filter('*.md'); +var fn = mm.filter('*.md', {dot: true}); // "any" method. -mm.any('abc', ['!*z']); -mm.any('abc', 'a*'); +boolResult = mm.any('abc', ['!*z']); +boolResult = mm.any('abc', 'a*'); +boolResult = mm.any('abc', 'a*', {dot: true}); // "expand" method. mm.expand('*.js'); +mm.expand('*.js', {dot: true}); // "makeRe" method. -mm.makeRe('*.js'); +regExpResult = mm.makeRe('*.js'); +regExpResult = mm.makeRe('*.js', {dot: true}); diff --git a/parse-glob/parse-glob-tests.ts b/parse-glob/parse-glob-tests.ts index 9a6697e3e..a1b10c7e1 100644 --- a/parse-glob/parse-glob-tests.ts +++ b/parse-glob/parse-glob-tests.ts @@ -1,21 +1,24 @@ /// import parseGlob = require('parse-glob'); -var result = parseGlob('a/b/c/**/*.{yml,json}'); +var result: ParseGlob.Result = parseGlob('a/b/c/**/*.{yml,json}'); -result.base; -result.glob; -result.is.braces; -result.is.brackets; -result.is.dotdir; -result.is.dotfile; -result.is.extglob; -result.is.glob; -result.is.globstar; -result.is.negated; -result.orig; -result.path.basename; -result.path.dirname; -result.path.ext; -result.path.extname; -result.path.filename; +var stringValue: string; +var boolValue: boolean; + +stringValue = result.base; +stringValue = result.glob; +boolValue = result.is.braces; +boolValue = result.is.brackets; +boolValue = result.is.dotdir; +boolValue = result.is.dotfile; +boolValue = result.is.extglob; +boolValue = result.is.glob; +boolValue = result.is.globstar; +boolValue = result.is.negated; +stringValue = result.orig; +stringValue = result.path.basename; +stringValue = result.path.dirname; +stringValue = result.path.ext; +stringValue = result.path.extname; +stringValue = result.path.filename; From da7a41e52b646a15387804e7880f1efff14829a1 Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 10 Jan 2016 14:03:23 +0200 Subject: [PATCH 05/12] Fix reference path --- micromatch/micromatch.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micromatch/micromatch.d.ts b/micromatch/micromatch.d.ts index f8b101a61..db3897fa2 100644 --- a/micromatch/micromatch.d.ts +++ b/micromatch/micromatch.d.ts @@ -3,7 +3,7 @@ // Definitions by: glen-84 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +/// declare namespace Micromatch { type Pattern = (string | RegExp | ((filePath: string) => boolean)); From 9b5743fcf341fb675ddd8eec257a813a513cbdac Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 10 Jan 2016 14:50:03 +0200 Subject: [PATCH 06/12] Move namespaces to inside the module declarations --- micromatch/micromatch.d.ts | 209 +++++++++++++++++---------------- parse-glob/parse-glob-tests.ts | 2 +- parse-glob/parse-glob.d.ts | 160 ++++++++++++------------- 3 files changed, 187 insertions(+), 184 deletions(-) diff --git a/micromatch/micromatch.d.ts b/micromatch/micromatch.d.ts index db3897fa2..e84b6c339 100644 --- a/micromatch/micromatch.d.ts +++ b/micromatch/micromatch.d.ts @@ -5,158 +5,161 @@ /// -declare namespace Micromatch { - type Pattern = (string | RegExp | ((filePath: string) => boolean)); -} - declare module 'micromatch' { - interface MicromatchOptions { - /** - * Normalize slashes in file paths and glob patterns to forward slashes. - */ - unixify?: boolean; - /** - * Match dotfiles. Same behavior as minimatch. - */ - dot?: boolean; - /** - * Unescape slashes in glob patterns. Use cautiously, especially on windows. - */ - unescape?: boolean; - /** - * Remove duplicate elements from the result array. - */ - nodupes?: boolean; - /** - * Allow glob patterns without slashes to match a file path based on its basename. Same behavior as minimatch. - */ - matchBase?: boolean; - /** - * Don't expand braces in glob patterns. Same behavior as minimatch nobrace. - */ - nobraces?: boolean; - /** - * Don't expand POSIX bracket expressions. - */ - nobrackets?: boolean; - /** - * Don't expand extended globs. - */ - noextglob?: boolean; - /** - * Use a case-insensitive regex for matching files. Same behavior as minimatch. - */ - nocase?: boolean; - /** - * If true, when no matches are found the actual (array-ified) glob pattern is returned instead of an empty - * array. Same behavior as minimatch. - */ - nonull?: boolean; - /** - * Cache the platform (e.g. win32) to prevent this from being looked up for every file path. - */ - cache?: boolean; - } + import parseGlob = require('parse-glob'); - interface Glob { - options: {}; // TODO: Expand? - pattern: string; - history: {msg: any, pattern: string}[]; - tokens: ParseGlob.Result; - orig: string; - negated: boolean; + namespace micromatch { + type Pattern = (string | RegExp | ((filePath: string) => boolean)); - /** - * Initialize defaults. - */ - init(pattern: string): void; + interface Options { + /** + * Normalize slashes in file paths and glob patterns to forward slashes. + */ + unixify?: boolean; + /** + * Match dotfiles. Same behavior as minimatch. + */ + dot?: boolean; + /** + * Unescape slashes in glob patterns. Use cautiously, especially on windows. + */ + unescape?: boolean; + /** + * Remove duplicate elements from the result array. + */ + nodupes?: boolean; + /** + * Allow glob patterns without slashes to match a file path based on its basename. Same behavior as + * minimatch. + */ + matchBase?: boolean; + /** + * Don't expand braces in glob patterns. Same behavior as minimatch nobrace. + */ + nobraces?: boolean; + /** + * Don't expand POSIX bracket expressions. + */ + nobrackets?: boolean; + /** + * Don't expand extended globs. + */ + noextglob?: boolean; + /** + * Use a case-insensitive regex for matching files. Same behavior as minimatch. + */ + nocase?: boolean; + /** + * If true, when no matches are found the actual (array-ified) glob pattern is returned instead of an empty + * array. Same behavior as minimatch. + */ + nonull?: boolean; + /** + * Cache the platform (e.g. win32) to prevent this from being looked up for every file path. + */ + cache?: boolean; + } - /** - * Push a change into `glob.history`. Useful for debugging. - */ - track(msg: any): void; + interface Glob { + options: {}; // TODO: Expand? + pattern: string; + history: {msg: any, pattern: string}[]; + tokens: parseGlob.Result; + orig: string; + negated: boolean; - /** - * Return true if `glob.pattern` was negated with `!`, also remove the `!` from the pattern. - */ - isNegated(): boolean; + /** + * Initialize defaults. + */ + init(pattern: string): void; - /** - * Expand braces in the given glob pattern. - */ - braces(): void; + /** + * Push a change into `glob.history`. Useful for debugging. + */ + track(msg: any): void; - /** - * Expand bracket expressions in `glob.pattern`. - */ - brackets(): void; + /** + * Return true if `glob.pattern` was negated with `!`, also remove the `!` from the pattern. + */ + isNegated(): boolean; - /** - * Expand extended globs in `glob.pattern`. - */ - extglob(): void; + /** + * Expand braces in the given glob pattern. + */ + braces(): void; - /** - * Parse the given pattern. - */ - parse(pattern: string): ParseGlob.Result; + /** + * Expand bracket expressions in `glob.pattern`. + */ + brackets(): void; - /** - * Escape special characters in the given string. - */ - escape(pattern: string): string; + /** + * Expand extended globs in `glob.pattern`. + */ + extglob(): void; - /** - * Unescape special characters in the given string. - */ - unescape(pattern: string): string; + /** + * Parse the given pattern. + */ + parse(pattern: string): parseGlob.Result; + + /** + * Escape special characters in the given string. + */ + escape(pattern: string): string; + + /** + * Unescape special characters in the given string. + */ + unescape(pattern: string): string; + } } interface Micromatch { - (files: string | string[], patterns: Micromatch.Pattern | Micromatch.Pattern[]): string[]; + (files: string | string[], patterns: micromatch.Pattern | micromatch.Pattern[]): string[]; isMatch: { /** * Returns true if a file path matches the given pattern. */ - (filePath: string, pattern: Micromatch.Pattern, opts?: MicromatchOptions): boolean; + (filePath: string, pattern: micromatch.Pattern, opts?: micromatch.Options): boolean; /** * Returns a function for matching. */ - (filePath: string, opts?: MicromatchOptions): ((filePath: string) => boolean); + (filePath: string, opts?: micromatch.Options): ((filePath: string) => boolean); }; /** * Returns true if any part of a file path matches the given pattern. Think of this as "has path" versus * "is path". */ - contains(filePath: string, pattern: Micromatch.Pattern, opts?: MicromatchOptions): boolean; + contains(filePath: string, pattern: micromatch.Pattern, opts?: micromatch.Options): boolean; /** * Returns a function for matching using the supplied pattern. e.g. create your own "matcher". The advantage of * this method is that the pattern can be compiled outside of a loop. */ - matcher(pattern: Micromatch.Pattern): ((filePath: string) => boolean); + matcher(pattern: micromatch.Pattern): ((filePath: string) => boolean); /** * Returns a function that can be passed to Array#filter(). */ - filter(patterns: Micromatch.Pattern | Micromatch.Pattern[], opts?: MicromatchOptions): ((filePath: string) => boolean); + filter(patterns: micromatch.Pattern | micromatch.Pattern[], opts?: micromatch.Options): ((filePath: string) => boolean); /** * Returns true if a file path matches any of the given patterns. */ - any(filePath: string, patterns: Micromatch.Pattern | Micromatch.Pattern[], opts?: MicromatchOptions): boolean; + any(filePath: string, patterns: micromatch.Pattern | micromatch.Pattern[], opts?: micromatch.Options): boolean; /** * Returns an object with a regex-compatible string and tokens. */ - expand(pattern: string, opts?: MicromatchOptions): Glob | {pattern: string, tokens: ParseGlob.Result, options: {} /* TODO: Expand? */}; + expand(pattern: string, opts?: micromatch.Options): micromatch.Glob | {pattern: string, tokens: parseGlob.Result, options: {} /* TODO: Expand? */}; /** * Create a regular expression for matching file paths based on the given pattern. */ - makeRe(pattern: string, opts?: MicromatchOptions): RegExp; + makeRe(pattern: string, opts?: micromatch.Options): RegExp; } const micromatch: Micromatch; diff --git a/parse-glob/parse-glob-tests.ts b/parse-glob/parse-glob-tests.ts index a1b10c7e1..a7b47ded0 100644 --- a/parse-glob/parse-glob-tests.ts +++ b/parse-glob/parse-glob-tests.ts @@ -1,7 +1,7 @@ /// import parseGlob = require('parse-glob'); -var result: ParseGlob.Result = parseGlob('a/b/c/**/*.{yml,json}'); +var result: parseGlob.Result = parseGlob('a/b/c/**/*.{yml,json}'); var stringValue: string; var boolValue: boolean; diff --git a/parse-glob/parse-glob.d.ts b/parse-glob/parse-glob.d.ts index 14a73d62d..fe83c2db2 100644 --- a/parse-glob/parse-glob.d.ts +++ b/parse-glob/parse-glob.d.ts @@ -3,88 +3,88 @@ // Definitions by: glen-84 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare namespace ParseGlob { - interface Result { - /** - * A copy of the original, unmodified glob pattern. - */ - orig: string; - /** - * An object with boolean information about the glob. - */ - is: { - /** - * True if the pattern actually is a glob pattern. - */ - glob: boolean; - /** - * True if it's a negation pattern (!/foo.js). - */ - negated: boolean; - /** - * True if it has extglobs (@(foo|bar)). - */ - extglob: boolean; - /** - * True if it has braces ({1..2} or .{txt,md}). - */ - braces: boolean; - /** - * True if it has POSIX brackets ([[:alpha:]]). - */ - brackets: boolean; - /** - * True if the pattern has a globstar (double star, **). - */ - globstar: boolean; - /** - * True if the pattern should match dotfiles. - */ - dotfile: boolean; - /** - * True if the pattern should match dot-directories (like .git). - */ - dotdir: boolean; - }; - /** - * The glob pattern part of the string, if any. - */ - glob: string; - /** - * The non-glob part of the string, if any. - */ - base: string; - /** - * File path segments. - */ - path: { - /** - * Directory. - */ - dirname: string; - /** - * File name with extension. - */ - basename: string; - /** - * File name without extension. - */ - filename: string; - /** - * File extension with dot. - */ - extname: string; - /** - * File extension without dot. - */ - ext: string; - }; - } -} - declare module 'parse-glob' { + namespace parseGlob { + interface Result { + /** + * A copy of the original, unmodified glob pattern. + */ + orig: string; + /** + * An object with boolean information about the glob. + */ + is: { + /** + * True if the pattern actually is a glob pattern. + */ + glob: boolean; + /** + * True if it's a negation pattern (!/foo.js). + */ + negated: boolean; + /** + * True if it has extglobs (@(foo|bar)). + */ + extglob: boolean; + /** + * True if it has braces ({1..2} or .{txt,md}). + */ + braces: boolean; + /** + * True if it has POSIX brackets ([[:alpha:]]). + */ + brackets: boolean; + /** + * True if the pattern has a globstar (double star, **). + */ + globstar: boolean; + /** + * True if the pattern should match dotfiles. + */ + dotfile: boolean; + /** + * True if the pattern should match dot-directories (like .git). + */ + dotdir: boolean; + }; + /** + * The glob pattern part of the string, if any. + */ + glob: string; + /** + * The non-glob part of the string, if any. + */ + base: string; + /** + * File path segments. + */ + path: { + /** + * Directory. + */ + dirname: string; + /** + * File name with extension. + */ + basename: string; + /** + * File name without extension. + */ + filename: string; + /** + * File extension with dot. + */ + extname: string; + /** + * File extension without dot. + */ + ext: string; + }; + } + } + interface ParseGlob { - (glob: string): ParseGlob.Result; + (glob: string): parseGlob.Result; } const parseGlob: ParseGlob; From 1ae2ddf27c6e9b98ad7e7fa496788f1aadf37933 Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 10 Jan 2016 14:55:12 +0200 Subject: [PATCH 07/12] Switch line endings from CRLF to LF (parse-glob files) --- parse-glob/parse-glob-tests.ts | 48 ++++----- parse-glob/parse-glob.d.ts | 184 ++++++++++++++++----------------- 2 files changed, 116 insertions(+), 116 deletions(-) diff --git a/parse-glob/parse-glob-tests.ts b/parse-glob/parse-glob-tests.ts index a7b47ded0..b4b3bc4c1 100644 --- a/parse-glob/parse-glob-tests.ts +++ b/parse-glob/parse-glob-tests.ts @@ -1,24 +1,24 @@ -/// -import parseGlob = require('parse-glob'); - -var result: parseGlob.Result = parseGlob('a/b/c/**/*.{yml,json}'); - -var stringValue: string; -var boolValue: boolean; - -stringValue = result.base; -stringValue = result.glob; -boolValue = result.is.braces; -boolValue = result.is.brackets; -boolValue = result.is.dotdir; -boolValue = result.is.dotfile; -boolValue = result.is.extglob; -boolValue = result.is.glob; -boolValue = result.is.globstar; -boolValue = result.is.negated; -stringValue = result.orig; -stringValue = result.path.basename; -stringValue = result.path.dirname; -stringValue = result.path.ext; -stringValue = result.path.extname; -stringValue = result.path.filename; +/// +import parseGlob = require('parse-glob'); + +var result: parseGlob.Result = parseGlob('a/b/c/**/*.{yml,json}'); + +var stringValue: string; +var boolValue: boolean; + +stringValue = result.base; +stringValue = result.glob; +boolValue = result.is.braces; +boolValue = result.is.brackets; +boolValue = result.is.dotdir; +boolValue = result.is.dotfile; +boolValue = result.is.extglob; +boolValue = result.is.glob; +boolValue = result.is.globstar; +boolValue = result.is.negated; +stringValue = result.orig; +stringValue = result.path.basename; +stringValue = result.path.dirname; +stringValue = result.path.ext; +stringValue = result.path.extname; +stringValue = result.path.filename; diff --git a/parse-glob/parse-glob.d.ts b/parse-glob/parse-glob.d.ts index fe83c2db2..b3bb7e85d 100644 --- a/parse-glob/parse-glob.d.ts +++ b/parse-glob/parse-glob.d.ts @@ -1,92 +1,92 @@ -// Type definitions for parse-glob 3.0.4 -// Project: https://github.com/jonschlinkert/parse-glob -// Definitions by: glen-84 -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare module 'parse-glob' { - namespace parseGlob { - interface Result { - /** - * A copy of the original, unmodified glob pattern. - */ - orig: string; - /** - * An object with boolean information about the glob. - */ - is: { - /** - * True if the pattern actually is a glob pattern. - */ - glob: boolean; - /** - * True if it's a negation pattern (!/foo.js). - */ - negated: boolean; - /** - * True if it has extglobs (@(foo|bar)). - */ - extglob: boolean; - /** - * True if it has braces ({1..2} or .{txt,md}). - */ - braces: boolean; - /** - * True if it has POSIX brackets ([[:alpha:]]). - */ - brackets: boolean; - /** - * True if the pattern has a globstar (double star, **). - */ - globstar: boolean; - /** - * True if the pattern should match dotfiles. - */ - dotfile: boolean; - /** - * True if the pattern should match dot-directories (like .git). - */ - dotdir: boolean; - }; - /** - * The glob pattern part of the string, if any. - */ - glob: string; - /** - * The non-glob part of the string, if any. - */ - base: string; - /** - * File path segments. - */ - path: { - /** - * Directory. - */ - dirname: string; - /** - * File name with extension. - */ - basename: string; - /** - * File name without extension. - */ - filename: string; - /** - * File extension with dot. - */ - extname: string; - /** - * File extension without dot. - */ - ext: string; - }; - } - } - - interface ParseGlob { - (glob: string): parseGlob.Result; - } - - const parseGlob: ParseGlob; - export = parseGlob; -} +// Type definitions for parse-glob 3.0.4 +// Project: https://github.com/jonschlinkert/parse-glob +// Definitions by: glen-84 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'parse-glob' { + namespace parseGlob { + interface Result { + /** + * A copy of the original, unmodified glob pattern. + */ + orig: string; + /** + * An object with boolean information about the glob. + */ + is: { + /** + * True if the pattern actually is a glob pattern. + */ + glob: boolean; + /** + * True if it's a negation pattern (!/foo.js). + */ + negated: boolean; + /** + * True if it has extglobs (@(foo|bar)). + */ + extglob: boolean; + /** + * True if it has braces ({1..2} or .{txt,md}). + */ + braces: boolean; + /** + * True if it has POSIX brackets ([[:alpha:]]). + */ + brackets: boolean; + /** + * True if the pattern has a globstar (double star, **). + */ + globstar: boolean; + /** + * True if the pattern should match dotfiles. + */ + dotfile: boolean; + /** + * True if the pattern should match dot-directories (like .git). + */ + dotdir: boolean; + }; + /** + * The glob pattern part of the string, if any. + */ + glob: string; + /** + * The non-glob part of the string, if any. + */ + base: string; + /** + * File path segments. + */ + path: { + /** + * Directory. + */ + dirname: string; + /** + * File name with extension. + */ + basename: string; + /** + * File name without extension. + */ + filename: string; + /** + * File extension with dot. + */ + extname: string; + /** + * File extension without dot. + */ + ext: string; + }; + } + } + + interface ParseGlob { + (glob: string): parseGlob.Result; + } + + const parseGlob: ParseGlob; + export = parseGlob; +} From 481622e150f962c98c0c53fd1ac5a0587cc06702 Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 10 Jan 2016 15:02:41 +0200 Subject: [PATCH 08/12] Add space after the reference path attribute value --- micromatch/micromatch-tests.ts | 2 +- parse-glob/parse-glob-tests.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/micromatch/micromatch-tests.ts b/micromatch/micromatch-tests.ts index 7cf5e1eab..2b0c8d784 100644 --- a/micromatch/micromatch-tests.ts +++ b/micromatch/micromatch-tests.ts @@ -1,4 +1,4 @@ -/// +/// import mm = require('micromatch'); var result: string[]; diff --git a/parse-glob/parse-glob-tests.ts b/parse-glob/parse-glob-tests.ts index b4b3bc4c1..267f2b4ed 100644 --- a/parse-glob/parse-glob-tests.ts +++ b/parse-glob/parse-glob-tests.ts @@ -1,4 +1,4 @@ -/// +/// import parseGlob = require('parse-glob'); var result: parseGlob.Result = parseGlob('a/b/c/**/*.{yml,json}'); From 4e944dbca0f3451d9d0d9695c0130be323cbf1bc Mon Sep 17 00:00:00 2001 From: Glen Date: Sat, 16 Jan 2016 19:05:46 +0200 Subject: [PATCH 09/12] Add MatchFunction type --- micromatch/micromatch.d.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/micromatch/micromatch.d.ts b/micromatch/micromatch.d.ts index e84b6c339..58aba394e 100644 --- a/micromatch/micromatch.d.ts +++ b/micromatch/micromatch.d.ts @@ -9,7 +9,8 @@ declare module 'micromatch' { import parseGlob = require('parse-glob'); namespace micromatch { - type Pattern = (string | RegExp | ((filePath: string) => boolean)); + type MatchFunction = ((value: T) => boolean); + type Pattern = (string | RegExp | MatchFunction); interface Options { /** @@ -126,7 +127,7 @@ declare module 'micromatch' { /** * Returns a function for matching. */ - (filePath: string, opts?: micromatch.Options): ((filePath: string) => boolean); + (filePath: string, opts?: micromatch.Options): micromatch.MatchFunction; }; /** @@ -139,12 +140,12 @@ declare module 'micromatch' { * Returns a function for matching using the supplied pattern. e.g. create your own "matcher". The advantage of * this method is that the pattern can be compiled outside of a loop. */ - matcher(pattern: micromatch.Pattern): ((filePath: string) => boolean); + matcher(pattern: micromatch.Pattern): micromatch.MatchFunction; /** * Returns a function that can be passed to Array#filter(). */ - filter(patterns: micromatch.Pattern | micromatch.Pattern[], opts?: micromatch.Options): ((filePath: string) => boolean); + filter(patterns: micromatch.Pattern | micromatch.Pattern[], opts?: micromatch.Options): micromatch.MatchFunction; /** * Returns true if a file path matches any of the given patterns. From bb058798f58280e0e34686fe59fa1852dfe0e9c4 Mon Sep 17 00:00:00 2001 From: Glen Date: Sat, 16 Jan 2016 19:26:30 +0200 Subject: [PATCH 10/12] Add more tests --- micromatch/micromatch-tests.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/micromatch/micromatch-tests.ts b/micromatch/micromatch-tests.ts index 2b0c8d784..75f9407ee 100644 --- a/micromatch/micromatch-tests.ts +++ b/micromatch/micromatch-tests.ts @@ -1,15 +1,17 @@ /// import mm = require('micromatch'); -var result: string[]; +var strArrResult: string[]; var boolResult: boolean; +var strMatchFuncResult: mm.MatchFunction; +var anyMatchFuncResult: mm.MatchFunction; var regExpResult: RegExp; // Usage. -result = mm(['a.js', 'b.md', 'c.txt'], '*.{js,txt}'); +strArrResult = mm(['a.js', 'b.md', 'c.txt'], '*.{js,txt}'); // Multiple patterns. -result = mm(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.md', '*.txt']); +strArrResult = mm(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.md', '*.txt']); // "isMatch" method. boolResult = mm.isMatch('.verb.md', '*.md'); @@ -21,11 +23,21 @@ boolResult = mm.contains('a/b/c', 'a/b'); boolResult = mm.contains('a/b/c', 'a/b', {dot: true}); // "matcher" method. -var isMatch = mm.matcher('*.md'); +strMatchFuncResult = mm.matcher('*.md'); +strMatchFuncResult = mm.matcher(/\.md$/); +strMatchFuncResult = mm.matcher((filePath: string) => true); // "filter" method. -var fn = mm.filter('*.md'); -var fn = mm.filter('*.md', {dot: true}); +anyMatchFuncResult = mm.filter('*.md'); +anyMatchFuncResult = mm.filter(/\.md$/); +anyMatchFuncResult = mm.filter((filePath: string) => true); + +anyMatchFuncResult = mm.filter('*.md', {dot: true}); +['a.js', 'b.txt', 'c.md'].filter(anyMatchFuncResult); + +var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 , 11, 12, 13, 14, 15]; +anyMatchFuncResult = mm.filter(['{1..10}', '![7-9]', '!{3..4}']); +arr.filter(anyMatchFuncResult); // "any" method. boolResult = mm.any('abc', ['!*z']); From 7cda84786520fd0673c934fde1aa722083e05f7b Mon Sep 17 00:00:00 2001 From: Glen Date: Sat, 23 Jan 2016 16:09:05 +0200 Subject: [PATCH 11/12] Add GlobData interface --- micromatch/micromatch-tests.ts | 5 +++-- micromatch/micromatch.d.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/micromatch/micromatch-tests.ts b/micromatch/micromatch-tests.ts index 75f9407ee..c0d47a80d 100644 --- a/micromatch/micromatch-tests.ts +++ b/micromatch/micromatch-tests.ts @@ -5,6 +5,7 @@ var strArrResult: string[]; var boolResult: boolean; var strMatchFuncResult: mm.MatchFunction; var anyMatchFuncResult: mm.MatchFunction; +var globDataResult: mm.GlobData; var regExpResult: RegExp; // Usage. @@ -45,8 +46,8 @@ boolResult = mm.any('abc', 'a*'); boolResult = mm.any('abc', 'a*', {dot: true}); // "expand" method. -mm.expand('*.js'); -mm.expand('*.js', {dot: true}); +globDataResult = mm.expand('*.js'); +globDataResult = mm.expand('*.js', {dot: true}); // "makeRe" method. regExpResult = mm.makeRe('*.js'); diff --git a/micromatch/micromatch.d.ts b/micromatch/micromatch.d.ts index 58aba394e..cea7098ec 100644 --- a/micromatch/micromatch.d.ts +++ b/micromatch/micromatch.d.ts @@ -62,7 +62,7 @@ declare module 'micromatch' { } interface Glob { - options: {}; // TODO: Expand? + options: micromatch.Options; pattern: string; history: {msg: any, pattern: string}[]; tokens: parseGlob.Result; @@ -114,6 +114,12 @@ declare module 'micromatch' { */ unescape(pattern: string): string; } + + interface GlobData { + pattern: string; + tokens: parseGlob.Result; + options: micromatch.Options; + } } interface Micromatch { @@ -155,7 +161,7 @@ declare module 'micromatch' { /** * Returns an object with a regex-compatible string and tokens. */ - expand(pattern: string, opts?: micromatch.Options): micromatch.Glob | {pattern: string, tokens: parseGlob.Result, options: {} /* TODO: Expand? */}; + expand(pattern: string, opts?: micromatch.Options): micromatch.Glob | micromatch.GlobData; /** * Create a regular expression for matching file paths based on the given pattern. From 53ab65f53eb3295f7aa0a3dbd082a738b4b61012 Mon Sep 17 00:00:00 2001 From: Glen Date: Mon, 25 Jan 2016 21:42:09 +0200 Subject: [PATCH 12/12] Remove space before comma --- micromatch/micromatch-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micromatch/micromatch-tests.ts b/micromatch/micromatch-tests.ts index c0d47a80d..f90c4a4bd 100644 --- a/micromatch/micromatch-tests.ts +++ b/micromatch/micromatch-tests.ts @@ -36,7 +36,7 @@ anyMatchFuncResult = mm.filter((filePath: string) => true); anyMatchFuncResult = mm.filter('*.md', {dot: true}); ['a.js', 'b.txt', 'c.md'].filter(anyMatchFuncResult); -var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 , 11, 12, 13, 14, 15]; +var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; anyMatchFuncResult = mm.filter(['{1..10}', '![7-9]', '!{3..4}']); arr.filter(anyMatchFuncResult);