diff --git a/micromatch/micromatch-tests.ts b/micromatch/micromatch-tests.ts new file mode 100644 index 0000000000..8452acdcbc --- /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 0000000000..68cfbc2192 --- /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 0000000000..9a6697e3e3 --- /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 0000000000..460905e12e --- /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; +}