diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9e06228 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,151 @@ +export declare interface MatchOptions { + basename?: boolean; + bash?: boolean; + cache?: boolean; + dot?: boolean; + failglob?: boolean; + ignore?: string | string[]; + matchBase?: boolean; + nocase?: boolean; + nodupes?: boolean; + nonegate?: boolean; + noglobstar?: boolean; + nonull?: boolean; + nullglob?: boolean; + slash?: string | (() => string); + star?: string | (() => string); + snapdragon?: object; + sourcemap?: boolean; + unescape?: boolean; + unixify?: boolean; +} + +/** + * The main function takes a list of strings and one or more + * glob patterns to use for matching. + */ +declare function nanomatch( + list: string[], + patterns: string | string[], + options?: MatchOptions +): string[]; +declare namespace nanomatch { + /** + * Similar to the main function, but `pattern` must be a string. + */ + export function match( + list: string[], + pattern: string, + options?: MatchOptions + ): string[]; + /** + * Returns true if the specified `string` matches the given glob `pattern`. + */ + export function isMatch( + str: string, + pattern: string, + options?: MatchOptions + ): boolean; + /** + * Returns true if some of the elements in the given `list` match any of the + * given glob `patterns`. + */ + export function some( + list: string | string[], + patterns: string | string[], + options?: MatchOptions + ): boolean; + /** + * Returns true if every element in the given `list` matches + * at least one of the given glob `patterns`. + */ + export function every( + list: string | string[], + patterns: string | string[], + options?: MatchOptions + ): boolean; + /** + * Returns true if **any** of the given glob `patterns` + * match the specified `string`. + */ + export function any( + str: string | string[], + patterns: string | string[], + options?: MatchOptions + ): boolean; + /** + * Returns true if **all** of the given `patterns` + * match the specified string. + */ + export function all( + str: string | string[], + patterns: string | string[], + options?: MatchOptions + ): boolean; + /** + * Returns a list of strings that _**do not match any**_ of the given `patterns`. + */ + export function not( + list: string[], + patterns: string | string[], + options?: MatchOptions + ): string[]; + /** + * Returns true if the given `string` contains the given pattern. Similar + * to [.isMatch](#isMatch) but the pattern can match any part of the string. + */ + export function contains( + str: string, + patterns: string | string[], + options?: MatchOptions + ): boolean; + /** + * Filter the keys of the given object with the given `glob` pattern + * and `options`. Does not attempt to match nested keys. If you need this feature, + * use [glob-object][] instead. + */ + export function matchKeys< + T extends Record = Record + >(obj: T, patterns: string | string[], options?: MatchOptions): Partial; + /** + * Returns a memoized matcher function from the given glob `pattern` and `options`. + * The returned function takes a string to match as its only argument and returns + * true if the string is a match. + */ + export function matcher( + pattern: string, + options?: MatchOptions + ): (str: string) => boolean; + /** + * Returns an array of matches captured by `pattern` in `string, or + * `null` if the pattern did not match. + */ + export function capture( + pattern: string, + str: string, + options?: MatchOptions + ): string[] | null; + /** + * Create a regular expression from the given glob `pattern`. + */ + export function makeRe(pattern: string, options?: MatchOptions): RegExp; + /** + * Parses the given glob `pattern` and returns an object with the compiled `output` + * and optional source `map`. + */ + export function create(pattern: string, options?: MatchOptions): any; + /** + * Parse the given `str` with the given `options`. + */ + export function parse(pattern: string, options?: MatchOptions): any; + /** + * Compile the given `ast` or string with the given `options`. + */ + export function compile(ast: any, options?: MatchOptions): any; + /** + * Clear the regex cache. + */ + export function clearCache(): void; +} + +export = nanomatch; diff --git a/index.js b/index.js index 746a591..a39c187 100644 --- a/index.js +++ b/index.js @@ -552,7 +552,7 @@ nanomatch.matcher = function matcher(pattern, options) { * @param {String} `pattern` Glob pattern to use for matching. * @param {String} `string` String to match * @param {Object} `options` See available [options](#options) for changing how matches are performed - * @return {Boolean} Returns an array of captures if the string matches the glob pattern, otherwise `null`. + * @return {Array|null} Returns an array of captures if the string matches the glob pattern, otherwise `null`. * @api public */ diff --git a/package.json b/package.json index b92496d..b38afe8 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,10 @@ "license": "MIT", "files": [ "index.js", + "index.d.ts", "lib" ], + "typings": "index.d.ts", "main": "index.js", "engines": { "node": ">=4.0.0"