mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Add type definitions for micromatch (and parse-glob)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/// <reference path="./micromatch.d.ts"/>
|
||||
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');
|
||||
Vendored
+164
@@ -0,0 +1,164 @@
|
||||
// Type definitions for micromatch 2.3.7
|
||||
// Project: https://www.npmjs.com/package/micromatch
|
||||
// Definitions by: glen-84 <https://github.com/glen-84>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../parse-glob/parse-glob.ts" />
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user