Merge pull request #3937 from misak113/object-hash+fs-finder

Add libraries object-hash + fs-finder
This commit is contained in:
Masahiro Wakame
2015-03-25 01:06:20 +09:00
4 changed files with 242 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
/// <reference path="fs-finder.d.ts" />
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');
+55
View File
@@ -0,0 +1,55 @@
// Type definitions for fs-finder v1.8.0
// Project: https://github.com/sakren/node-fs-finder
// Definitions by: Michael Zabka <https://github.com/misak113/>
// 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;
}
+48
View File
@@ -0,0 +1,48 @@
/// <reference path="object-hash.d.ts" />
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();
+52
View File
@@ -0,0 +1,52 @@
// Type definitions for object-hash v0.5.0
// Project: https://github.com/puleos/object-hash
// Definitions by: Michael Zabka <https://github.com/misak113/>
// 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;
}