diff --git a/globule/globule-tests.ts b/globule/globule-tests.ts new file mode 100644 index 0000000000..d0e1eb3ccb --- /dev/null +++ b/globule/globule-tests.ts @@ -0,0 +1,28 @@ +import * as globule from 'globule'; + +let filepaths: string[]; + +filepaths = globule.find('**/*.js'); +filepaths = globule.find(['**/*.js']); +filepaths = globule.find('**/*.js', '**/*.less'); +filepaths = globule.find('*.js', { matchBase: true }); +filepaths = globule.find('**/*.js', '**/*.less', { filter: 'isFile' }); +filepaths = globule.find('**/*.js', '**/*.less', { filter: /jQuery/i.test }); +filepaths = globule.find({ src: '**/*.js' }); + +filepaths = globule.match('*.js', '/home/code'); +filepaths = globule.match('*.js', '/home/code', { matchBase: true }); + +let bResult: boolean; +bResult = globule.isMatch('*.js', '/home/code'); +bResult = globule.isMatch('*.js', '/home/code', { matchBase: true }); + +let mappings = globule.mapping(['*.js']); +let len = mappings.length; +let src = mappings[0].src; +let dest = mappings[0].dest; + +mappings = globule.mapping(['*.js'], { srcBase: '/home/code' }); +mappings = globule.mapping(['*.js', '*.less']); +mappings = globule.mapping(['*.js'], ['*.less']); + diff --git a/globule/index.d.ts b/globule/index.d.ts new file mode 100644 index 0000000000..595a4d2aec --- /dev/null +++ b/globule/index.d.ts @@ -0,0 +1,87 @@ +// Type definitions for globule 1.1 +// Project: https://github.com/cowboy/node-globule +// Definitions by: Dusan Radovanovic +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import minimatch = require('minimatch'); +import glob = require('glob'); + +interface FindOptions extends glob.IOptions { + src?: string; + filter?: string | ((filepath?: string, options?: any) => boolean); + nonull?: boolean; + matchBase?: boolean; + srcBase?: string; + prefixBase?: boolean; +} + +interface MappingOptions extends FindOptions { + srcBase?: string; + destBase?: string; + ext?: string; + extDot?: 'first' | 'last'; + flatten?: boolean; + rename?: (p: string) => string; +} + +interface OneMapping { + src: string[]; + dest: string; +} + +interface GlobuleStatic { + /** + * Match one or more globbing patterns against one or more file paths. + * Returns a uniqued array of all file paths that match any of the specified globbing patterns. + */ + match(patterns: string | string[], filepaths: string | string[], options?: minimatch.IOptions): string[]; + + /** + * Tests pattern(s) against against one or more file paths and returns true if any files were matched, otherwise false. + */ + isMatch(patterns: string | string[], filepaths: string | string[], options?: minimatch.IOptions): boolean; + + /** + * Returns a unique array of all file or directory paths that match the given globbing pattern(s) + */ + find(pattern: string | string[], options?: FindOptions): string[]; + + /** + * Returns a unique array of all file or directory paths that match the given globbing pattern(s) + */ + find(options: FindOptions): string[]; + + /** + * Returns a unique array of all file or directory paths that match the given globbing pattern(s) + */ + find(pattern: string | string[], pattern2: string | string[], options?: FindOptions): string[]; + + /** + * Returns a unique array of all file or directory paths that match the given globbing pattern(s) + */ + find(pattern: string, pattern2: string, pattern3: string | string[], options?: FindOptions): string[]; + + /** + * Given a set of source file paths, returns an array of src-dest file mapping objects + */ + mapping(filepaths: string[], options?: MappingOptions): OneMapping[]; + + /** + * Given a set of source file paths, returns an array of src-dest file mapping objects + */ + mapping(options: MappingOptions): OneMapping[]; + + /** + * Given a set of source file paths, returns an array of src-dest file mapping objects + */ + mapping(filepaths: string[], filepaths2: string[], options?: MappingOptions): OneMapping[]; + + /** + * Given a set of source file paths, returns an array of src-dest file mapping objects + */ + mapping(filepaths: string[], filepaths2: string[], filepaths3: string[], options?: MappingOptions): OneMapping[]; +} + +declare var globule: GlobuleStatic; +export = globule; + diff --git a/globule/tsconfig.json b/globule/tsconfig.json new file mode 100644 index 0000000000..ec155b8b0f --- /dev/null +++ b/globule/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "globule-tests.ts" + ] +} \ No newline at end of file diff --git a/globule/tslint.json b/globule/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/globule/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }