object-hash updated to v1.3.1 (#36071)

* Drop hashtable impl from object-hash as of v1.0

* Adding writeToStream method in object-hash

* Addin missing options in object-hash

* Bumping version and "Definitions by" headers
This commit is contained in:
Artur Diniz Adam
2019-06-11 18:38:14 -03:00
committed by Ron Buckton
parent 26fec8242e
commit 5788e4e16c
2 changed files with 17 additions and 56 deletions

View File

@@ -1,8 +1,12 @@
// Type definitions for object-hash v1.2.0
// Type definitions for object-hash v1.3.1
// Project: https://github.com/puleos/object-hash
// Definitions by: Michael Zabka <https://github.com/misak113>
// Definitions by: Michael Zabka <https://github.com/misak113>, Artur Diniz <https://github.com/artdiniz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import stream = require("stream");
import HashStatic = ObjectHash.HashStatic;
export = HashStatic;
export as namespace objectHash;
@@ -15,43 +19,22 @@ declare namespace ObjectHash {
ignoreUnknown?: boolean;
replacer?: (value: any) => any;
respectFunctionProperties?: boolean;
respectFunctionNames?: boolean;
respectFunctionNames?: boolean;
respectType?: boolean;
unorderedArrays?: boolean;
unorderedSets?: boolean;
unorderedSets?: boolean;
unorderedObjects?: boolean;
excludeKeys?: (key: string) => 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;
writeToStream(value: any, stream: stream.PassThrough): void;
writeToStream(value: any, options: IOptions, stream: stream.PassThrough): void;
}
export var HashStatic: Hash;

View File

@@ -1,6 +1,5 @@
import hash = require('object-hash');
import stream = require('stream')
var hashed: string;
@@ -14,6 +13,10 @@ hashed = hash.keys(obj);
hashed = hash.MD5(obj);
hashed = hash.keysMD5(obj);
var passThroughStream = new stream.PassThrough();
hash.writeToStream(obj, passThroughStream);
hashed = passThroughStream.read().toString();
var options = {
algorithm: 'md5',
encoding: 'utf8',
@@ -22,28 +25,3 @@ var options = {
};
hashed = hash(obj, options);
// HashTable
var table: any;
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();