mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(globrex): new type definition (#43826)
- type definition - tests https://github.com/terkelg/globrex#api Thanks!
This commit is contained in:
parent
d3164d63b2
commit
621363e730
15
types/globrex/globrex-tests.ts
Normal file
15
types/globrex/globrex-tests.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import globrex = require('globrex');
|
||||
import { Options, Results } from 'globrex';
|
||||
|
||||
const result = globrex('p*uck'); // $ExpectType Results
|
||||
// => { regex: /^p.*uck$/, string: '^p.*uck$', segments: [ /^p.*uck$/ ] }
|
||||
|
||||
const options: Options = {
|
||||
extended: true,
|
||||
filepath: true,
|
||||
globstar: true,
|
||||
strict: true,
|
||||
};
|
||||
const resultWithOptions: Results = globrex('p*uck', options); // $ExpectType Results
|
||||
result.regex.test('pluck'); // $ExpectType boolean
|
||||
resultWithOptions.regex.test('pluck'); // $ExpectType boolean
|
||||
78
types/globrex/index.d.ts
vendored
Normal file
78
types/globrex/index.d.ts
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
// Type definitions for globrex 0.1
|
||||
// Project: https://github.com/terkelg/globrex#readme
|
||||
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Transform globs into regular expressions.
|
||||
* {@link: https://github.com/terkelg/globrex#api}
|
||||
* @param glob - Glob string to transform.
|
||||
* @param options - transform options
|
||||
*/
|
||||
declare function globrex(glob: string, options?: globrex.Options): globrex.Results;
|
||||
|
||||
declare namespace globrex {
|
||||
interface Results {
|
||||
/** This property only exists if the option `filepath` is true. */
|
||||
path?: Path;
|
||||
/** JavaScript RegExp instance. */
|
||||
regex: RegExp;
|
||||
}
|
||||
|
||||
interface Path {
|
||||
/**
|
||||
* Array of RegExp instances separated by /.
|
||||
* This can be usable when working with file paths or urls.
|
||||
* ```js
|
||||
* [ /^foo$/, /^bar$/, /^([^\/]*)$/, '^baz\\.(md|js|txt)$' ]
|
||||
* ```
|
||||
*/
|
||||
segments: RegExp[];
|
||||
/**
|
||||
* String representation of the RegExp
|
||||
*/
|
||||
string: string;
|
||||
/**
|
||||
* JavaScript RegExp instance build for testing against paths.
|
||||
* The regex have different path separators depending on host OS.
|
||||
*/
|
||||
regex: RegExp;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
* Enable all advanced features from extglob.
|
||||
* Matching so called "extended" globs pattern like single character matching,
|
||||
* matching ranges of characters, group matching, etc.
|
||||
* Note: Interprets [a-d] as [abcd].
|
||||
* To match a literal -, include it as first or last character.
|
||||
* @default false
|
||||
*/
|
||||
extended?: boolean;
|
||||
/**
|
||||
* When `globstar` is false globs like '/foo/*' are transformed to the following '^\/foo\/.*$'
|
||||
* which will match any string beginning with '/foo/'
|
||||
* When the globstar option is true, the same '/foo/*'
|
||||
* glob is transformed to '^\/foo\/[^/]*$' which will match any string beginning with '/foo/'
|
||||
* that does not have a '/' to the right of it. '/foo/*' will match: '/foo/bar', '/foo/bar.txt' but not '/foo/bar/baz' or '/foo/bar/baz.txt'.
|
||||
* Note: When globstar is true, '/foo/**' is equivalent to '/foo/*' when globstar is false
|
||||
* @default false
|
||||
*/
|
||||
globstar?: boolean;
|
||||
/**
|
||||
* Be forgiving about multiple slashes, like /// and make everything after the first / optional
|
||||
* This is how bash glob works.
|
||||
* @default false
|
||||
*/
|
||||
strict?: boolean;
|
||||
/**
|
||||
* Parse input strings as it was a file path for special path related features.
|
||||
* This feature only makes sense if the input is a POSIX path like /foo/bar/hello.js or URLs.
|
||||
* When true the returned object will have an additional path object.
|
||||
* @default false
|
||||
*/
|
||||
filepath?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export = globrex;
|
||||
23
types/globrex/tsconfig.json
Normal file
23
types/globrex/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"globrex-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/globrex/tslint.json
Normal file
1
types/globrex/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user