Add npm library object-hash

This commit is contained in:
Michael Zabka 2015-03-22 18:58:43 +01:00
parent f0c934f8c4
commit 4d64698eff
2 changed files with 100 additions and 0 deletions

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
object-hash/object-hash.d.ts vendored Normal file
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;
}