mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add npm library object-hash
This commit is contained in:
parent
f0c934f8c4
commit
4d64698eff
48
object-hash/object-hash-tests.ts
Normal file
48
object-hash/object-hash-tests.ts
Normal 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
52
object-hash/object-hash.d.ts
vendored
Normal 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user