From 3595eba4d02afed07962e1d4df648c83ba0de3c1 Mon Sep 17 00:00:00 2001 From: whatasoda Date: Wed, 6 Jun 2018 16:52:08 +0900 Subject: [PATCH] Added definitions for 'glob-to-regexp' --- types/glob-to-regexp/glob-to-regexp-tests.ts | 26 ++++++++++++ types/glob-to-regexp/index.d.ts | 44 ++++++++++++++++++++ types/glob-to-regexp/tsconfig.json | 23 ++++++++++ types/glob-to-regexp/tslint.json | 1 + 4 files changed, 94 insertions(+) create mode 100644 types/glob-to-regexp/glob-to-regexp-tests.ts create mode 100644 types/glob-to-regexp/index.d.ts create mode 100644 types/glob-to-regexp/tsconfig.json create mode 100644 types/glob-to-regexp/tslint.json diff --git a/types/glob-to-regexp/glob-to-regexp-tests.ts b/types/glob-to-regexp/glob-to-regexp-tests.ts new file mode 100644 index 0000000000..4234ea3f07 --- /dev/null +++ b/types/glob-to-regexp/glob-to-regexp-tests.ts @@ -0,0 +1,26 @@ +import * as globToRegExp from 'glob-to-regexp'; +let re = globToRegExp("p*uck"); +re.test("pot luck"); // true +re.test("pluck"); // true +re.test("puck"); // true + +re = globToRegExp("*.min.js"); +re.test("http://example.com/jquery.min.js"); // true +re.test("http://example.com/jquery.min.js.map"); // false + +re = globToRegExp("*/www/*.js"); +re.test("http://example.com/www/app.js"); // true +re.test("http://example.com/www/lib/factory-proxy-model-observer.js"); // true + +// Extended globs +re = globToRegExp("*/www/{*.js,*.html}", { extended: true }); +re.test("http://example.com/www/app.js"); // true +re.test("http://example.com/www/index.html"); // true + +// globstar +re = globToRegExp("**/www/*", { globstar: true }); +re.test("http://example.com/www/index.html"); // true +re.test("http://example.com/www/articles/index.html"); // false + +re = globToRegExp("*/www/*", { globstar: true }); +re.test("http://example.com/www/index.html"); // false diff --git a/types/glob-to-regexp/index.d.ts b/types/glob-to-regexp/index.d.ts new file mode 100644 index 0000000000..ac47a64f6a --- /dev/null +++ b/types/glob-to-regexp/index.d.ts @@ -0,0 +1,44 @@ +// Type definitions for glob-to-regexp 0.4 +// Project: https://github.com/fitzgen/glob-to-regexp#readme +// Definitions by: whatasoda +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/*~ Note that ES6 modules cannot directly export callable functions. + *~ This file should be imported using the CommonJS-style: + *~ import x = require('someLibrary'); + *~ + *~ Refer to the documentation to understand common + *~ workarounds for this limitation of ES6 modules. + */ + +/*~ If this module is a UMD module that exposes a global variable 'myFuncLib' when + *~ loaded outside a module loader environment, declare that global here. + *~ Otherwise, delete this declaration. + */ +export as namespace GlobToRegExp; + +/*~ This declaration specifies that the function + *~ is the exported object from the file + */ +export = GlobToRegExp; + +declare function GlobToRegExp(glob: string, options?: GlobToRegExp.Options): RegExp; + +/*~ If you want to expose types from your module as well, you can + *~ place them in this block. Often you will want to describe the + *~ shape of the return type of the function; that type should + *~ be declared in here, as this example shows. + */ +declare namespace GlobToRegExp { + interface Options { + extended?: boolean; + globstar?: boolean; + flags ?: string; + } + + /*~ If the module also has properties, declare them here. For example, + *~ this declaration says that this code is legal: + *~ import f = require('myFuncLibrary'); + *~ console.log(f.defaultName); + */ +} diff --git a/types/glob-to-regexp/tsconfig.json b/types/glob-to-regexp/tsconfig.json new file mode 100644 index 0000000000..e532e836d1 --- /dev/null +++ b/types/glob-to-regexp/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "glob-to-regexp-tests.ts" + ] +} diff --git a/types/glob-to-regexp/tslint.json b/types/glob-to-regexp/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/glob-to-regexp/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }