From cd8e349fe7aa27a8445ab7c03d993dff0efdae95 Mon Sep 17 00:00:00 2001 From: Douglas Duteil Date: Wed, 28 Jun 2017 11:18:37 +0200 Subject: [PATCH] feat(globby): add typings for `globby` --- types/globby/globby-tests.ts | 27 +++++++++++++++++++++++++++ types/globby/index.d.ts | 17 +++++++++++++++++ types/globby/tsconfig.json | 22 ++++++++++++++++++++++ types/globby/tslint.json | 1 + 4 files changed, 67 insertions(+) create mode 100644 types/globby/globby-tests.ts create mode 100644 types/globby/index.d.ts create mode 100644 types/globby/tsconfig.json create mode 100644 types/globby/tslint.json diff --git a/types/globby/globby-tests.ts b/types/globby/globby-tests.ts new file mode 100644 index 0000000000..0e08024c63 --- /dev/null +++ b/types/globby/globby-tests.ts @@ -0,0 +1,27 @@ +// + +import { IOptions } from 'glob'; + +import * as globby from "globby"; + +(async () => { + let result: string[]; + result = await globby('*.tmp') + result = await globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']) + + result = globby.sync('*.tmp') + result = globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']) + + result = await globby('*.tmp', Object.freeze({ignore: Object.freeze([])})) + result = globby.sync('*.tmp', Object.freeze({ignore: Object.freeze([])})) +})() + + +const tasks: Array<{ + pattern: string, + options: IOptions +}> = globby.generateGlobTasks(['*.tmp', '!b.tmp'], {ignore: ['c.tmp']}); + +console.log(globby.hasMagic('**') === true); +console.log(globby.hasMagic(['**', 'path1', 'path2']) === true); +console.log(globby.hasMagic(['path1', 'path2']) === false); diff --git a/types/globby/index.d.ts b/types/globby/index.d.ts new file mode 100644 index 0000000000..a469cc3a0b --- /dev/null +++ b/types/globby/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for globby 0.6 +// Project: https://github.com/sindresorhus/globby#readme +// Definitions by: Douglas Duteil +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { IOptions } from 'glob'; + +declare function globby(patterns: string | string[], options?: Partial): Promise; + +declare namespace globby { + function sync(patterns: string | string[], options?: Partial): string[]; + function generateGlobTasks(patterns: string | string[], options?: Partial): Array<{pattern: string, options: IOptions}>; + function hasMagic(patterns: string | string[], options?: Partial): boolean; +} + +export = globby; diff --git a/types/globby/tsconfig.json b/types/globby/tsconfig.json new file mode 100644 index 0000000000..fd75c832f1 --- /dev/null +++ b/types/globby/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "globby-tests.ts" + ] +} diff --git a/types/globby/tslint.json b/types/globby/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/globby/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }