From f0c934f8c40459756ba9c96e3ec1163064975304 Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Sun, 22 Mar 2015 18:09:35 +0100 Subject: [PATCH] Add npm library fs-finder --- fs-finder/fs-finder-tests.ts | 87 ++++++++++++++++++++++++++++++++++++ fs-finder/fs-finder.d.ts | 55 +++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 fs-finder/fs-finder-tests.ts create mode 100644 fs-finder/fs-finder.d.ts diff --git a/fs-finder/fs-finder-tests.ts b/fs-finder/fs-finder-tests.ts new file mode 100644 index 000000000..3f6a82d6c --- /dev/null +++ b/fs-finder/fs-finder-tests.ts @@ -0,0 +1,87 @@ +/// + +import finder = require('fs-finder'); + + +// static +var a: FsFinder.Finder = finder.in('./*'); + +var b: FsFinder.Finder = finder.from('./*'); + +var c: FsFinder.Finder = finder.find('./*'); +finder.find('./*', (paths: string[]) => {}); + +var d: FsFinder.Finder = finder.findFiles('./*'); +finder.findFiles('./*', (paths: string[]) => {}); + +var e: FsFinder.Finder = finder.findDirectories('./*'); +finder.findDirectories('./*', (paths: string[]) => {}); + +var f: FsFinder.Finder = finder.findFile('./*'); +finder.findFile('./*', (paths: string[]) => {}); + +var g: FsFinder.Finder = finder.findDirectory('./*'); +finder.findDirectory('./*', (paths: string[]) => {}); + + +// instance +var instance = finder.in('./any*'); + +var j: string[] = instance.find('./*'); +instance.find('./*', (paths: string[]) => {}); + +var k: string[] = instance.findFiles('./*'); +instance.findFiles('./*', (paths: string[]) => {}); + +var l: string[] = instance.findDirectories('./*'); +instance.findDirectories('./*', (paths: string[]) => {}); + +var m: string[] = instance.findFile('./*'); +instance.findFile('./*', (paths: string[]) => {}); + +var n: string[] = instance.findDirectory('./*'); +instance.findDirectory('./*', (paths: string[]) => {}); + +var paths: string[]; +paths = instance.find(); +paths = instance.findFiles(); +paths = instance.findDirectories(); +paths = instance.findFile(); +paths = instance.findDirectory(); + + +// Base +instance = instance.recursively(); +instance = instance.recursively(false); +instance = instance.exclude('b'); +instance = instance.exclude(['b']); +instance = instance.exclude('a', true); +instance = instance.showSystemFiles(); +instance = instance.showSystemFiles(false); +instance = instance.lookUp(); +instance = instance.lookUp(false); +instance = instance.findFirst(); +instance = instance.findFirst(true); +instance = instance.filter((path: string) => { + return false; +}); + +paths = instance.getPathsSync('all', './*', './dir'); +instance.getPathsAsync((paths: string[]) => {}, 'all', './*', './dir'); +paths = instance.getPathsSync('directories', './*', './dir'); +instance.getPathsAsync((paths: string[]) => {}, 'directories', './*', './dir'); +paths = instance.getPathsSync('files', './*', './dir'); +instance.getPathsAsync((paths: string[]) => {}, 'files', './*', './dir'); + +var is: boolean; +is = instance.checkExcludes('a'); +is = instance.checkSystemFiles('b'); +is = instance.checkFilters('c', {}); + +var numeric: number; +numeric = instance.checkFile('d', {}, './*.ts', 'all'); +numeric = instance.checkFile('d', {}, './*.ts', 'directories'); +numeric = instance.checkFile('d', {}, './*.ts', 'files'); + +paths = instance.getPathsFromParentsSync('a', 'all'); +instance.getPathsFromParentsAsync((paths: string[]) => {}, '*.ts', 'all'); diff --git a/fs-finder/fs-finder.d.ts b/fs-finder/fs-finder.d.ts new file mode 100644 index 000000000..a04ed8799 --- /dev/null +++ b/fs-finder/fs-finder.d.ts @@ -0,0 +1,55 @@ +// Type definitions for fs-finder v1.8.0 +// Project: https://github.com/sakren/node-fs-finder +// Definitions by: Michael Zabka +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module FsFinder { + + type AsyncFunction = (paths: string|string[]) => void; + type Type = string; // 'all'|'directories'|'files' + type Mask = string; + type Directory = string; + + export class Finder extends Base { + static TIME_FORMAT: string; + static in(path: string): Finder; + static from(path: string): Finder; + static find(path: string, fn?: AsyncFunction, type?: Type): Finder; + static findFiles(path?: string, fn?: AsyncFunction): Finder; + static findDirectories(path?: string, fn?: AsyncFunction): Finder; + static findFile(path?: string, fn?: AsyncFunction): Finder; + static findDirectory(path?: string, fn?: AsyncFunction): Finder; + find(mask?: Mask, fn?: AsyncFunction, type?: Type): string[]; + findFiles(mask?: Mask, fn?: AsyncFunction): string[]; + findDirectories(mask?: Mask, fn?: AsyncFunction): string[]; + findFile(mask?: Mask, fn?: AsyncFunction): string[]; + findDirectory(mask?: Mask, fn?: AsyncFunction): string[]; + size(operation?: any, value?: any): Finder; + date(operation?: any, value?: any): Finder; + } + + export class Base { + recursively(recursive?: boolean): Finder; + exclude(excludes: string|string[], exactly?: boolean): Finder; + showSystemFiles(systemFiles?: boolean): Finder; + lookUp(up?: boolean): Finder; + findFirst(findFirst?: boolean): Finder; + filter(fn: Function): Finder; + + getPathsSync(type?: Type, mask?: Mask, dir?: Directory): string[]; + getPathsAsync(fn: AsyncFunction, type?: Type, mask?: Mask, dir?: Directory): void; + + checkExcludes(path: string): boolean; + checkSystemFiles(path: string): boolean; + checkFilters(path: string, stats: any): boolean; + checkFile(path: string, stats: any, mask: Mask, type: Type): number; + + getPathsFromParentsSync(mask?: Mask, type?: Type): string[]; + getPathsFromParentsAsync(fn: AsyncFunction, mask?: Mask, type?: Type): void; + } +} + +declare module "fs-finder" { + import Finder = FsFinder.Finder; + export = Finder; +}