From f0c934f8c40459756ba9c96e3ec1163064975304 Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Sun, 22 Mar 2015 18:09:35 +0100 Subject: [PATCH 1/2] 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; +} From 4d64698eff1569cd199831301cb694eccc55b87e Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Sun, 22 Mar 2015 18:58:43 +0100 Subject: [PATCH 2/2] Add npm library object-hash --- object-hash/object-hash-tests.ts | 48 +++++++++++++++++++++++++++++ object-hash/object-hash.d.ts | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 object-hash/object-hash-tests.ts create mode 100644 object-hash/object-hash.d.ts diff --git a/object-hash/object-hash-tests.ts b/object-hash/object-hash-tests.ts new file mode 100644 index 000000000..e72c9e489 --- /dev/null +++ b/object-hash/object-hash-tests.ts @@ -0,0 +1,48 @@ +/// + +import hash = require('object-hash'); + +var hashed: string; + +var obj = { any: true }; + +// hash object +hashed = hash(obj); + +hashed = hash.sha1(obj); +hashed = hash.keys(obj); +hashed = hash.MD5(obj); +hashed = hash.keysMD5(obj); + +var options = { + algorithm: 'md5', + encoding: 'utf8', + excludeValues: true +}; + +hashed = hash(obj, options); + +// HashTable +var table: ObjectHash.HashTable; +table = hash.HashTable(); +table = hash.HashTable(options); + +table = table.add(obj); +table = table.add(obj, obj); +table = table.remove(obj); +table = table.remove(obj, obj); + +var has: boolean = table.hasKey('whatEver'); +var value: any = table.getValue('whatEver'); +var count: number = table.getCount('whatEver'); + +var tableObject = table.table(); +tableObject['whatEver'].value; +tableObject['whatEver'].count; + +var tableArray = table.toArray(); +tableArray.shift().value; +tableArray.pop().count; +tableArray[2].hash; + +table = table.reset(); diff --git a/object-hash/object-hash.d.ts b/object-hash/object-hash.d.ts new file mode 100644 index 000000000..8faf058da --- /dev/null +++ b/object-hash/object-hash.d.ts @@ -0,0 +1,52 @@ +// Type definitions for object-hash v0.5.0 +// Project: https://github.com/puleos/object-hash +// Definitions by: Michael Zabka +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module ObjectHash { + export interface IOptions { + algorithm?: string; + encoding?: string; + excludeValues?: boolean; + } + + interface HashTableItem { + value: any; + count: number; + } + + interface HashTableItemWithKey extends HashTableItem { + hash: string; + } + + export interface HashTable { + add(...values: any[]): HashTable; + remove(...values: any[]): HashTable; + hasKey(key: string): boolean; + getValue(key: string): any; + getCount(key: string): number; + table(): { [key: string]: HashTableItem }; + toArray(): HashTableItemWithKey[]; + reset(): HashTable; + } + + export interface HashTableStatic { + (options?: IOptions): HashTable; + } + + export interface Hash { + (object: any, options?: IOptions): string; + sha1(object: any): string; + keys(object: any): string; + MD5(object: any): string; + keysMD5(object: any): string; + HashTable: HashTableStatic; + } + + export var HashStatic: Hash; +} + +declare module 'object-hash' { + import HashStatic = ObjectHash.HashStatic; + export = HashStatic; +}