From c50af0ccba4fff6c0ab1a00da4bca89e3ef4fd8e Mon Sep 17 00:00:00 2001 From: lochiego Date: Tue, 13 Aug 2019 15:00:22 -0500 Subject: [PATCH] Add type for hash-it (#37593) --- types/hash-it/hash-it-tests.ts | 39 +++++++++++++++ types/hash-it/index.d.ts | 89 ++++++++++++++++++++++++++++++++++ types/hash-it/tsconfig.json | 23 +++++++++ types/hash-it/tslint.json | 1 + 4 files changed, 152 insertions(+) create mode 100644 types/hash-it/hash-it-tests.ts create mode 100644 types/hash-it/index.d.ts create mode 100644 types/hash-it/tsconfig.json create mode 100644 types/hash-it/tslint.json diff --git a/types/hash-it/hash-it-tests.ts b/types/hash-it/hash-it-tests.ts new file mode 100644 index 0000000000..c19693aac1 --- /dev/null +++ b/types/hash-it/hash-it-tests.ts @@ -0,0 +1,39 @@ +/// tests originate from https://github.com/planttheidea/hash-it + +import hash from "hash-it"; + +const foo = { foo: "bar"}; +const alsoFoo = {foo: "bar"}; +const stillFoo = { foo: "bar"}; + +hash(foo); + +hash.is(null, 123); +hash.is(null, null); + +const isNull = hash.is(null); +isNull(123); +isNull(null); + +hash.is.all(foo, alsoFoo, stillFoo); + +const isAllFoo = hash.is.all(foo); +isAllFoo(alsoFoo, stillFoo); + +const nopeBar = { + bar: "baz" +}; + +hash.is.any(foo, alsoFoo); +hash.is.any(foo, nopeBar); +hash.is.any(foo, alsoFoo, nopeBar); + +const isAnyFoo = hash.is.any(foo); +isAnyFoo(alsoFoo, nopeBar); + +hash.is.not(null, 123); +hash.is.not(null, null); + +const isNotNull = hash.is.not(null); +isNotNull(123); +isNotNull(null); diff --git a/types/hash-it/index.d.ts b/types/hash-it/index.d.ts new file mode 100644 index 0000000000..6766e793f0 --- /dev/null +++ b/types/hash-it/index.d.ts @@ -0,0 +1,89 @@ +// Type definitions for hash-it 4.0 +// Project: https://github.com/planttheidea/hash-it +// Definitions by: Eric Gonzalez +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Documentation based on: https://github.com/planttheidea/hash-it + +export default hash; + +/** + * hash the value passed to a unique, consistent hash value + * + * @param value the value to hash + * @returns the object hash + */ +export function hash(object: any): number; + +export namespace hash { + /** + * create a comparator for the object passed to determine if a second is equal + * + * @param object the object to test against + * @returns the method to test against the object + */ + function is(object: any): (anotherObject: any) => boolean; + + /** + * create a comparator for the first object passed to determine if the second is equal + * + * @param object the object to test against + * @param anotherObject the object to compare + * @returns are the objects equal + */ + function is(object: any, anotherObject: any): boolean; + + namespace is { + type Comparator = (...objects: any[]) => boolean; + + /** + * create a comparator to determine if all of the objects passed are equal in value to the initial + * + * @param object the object to test for equality + * @returns comparator function that checks if all objects equal the initial + */ + function all(object: any): Comparator; + + /** + * determine if all of the objects passed are equal in value to the first + * + * @param object the object to test for equality against + * @param objects the objects to test for equality + * @returns are the objects equal + */ + function all(object: any, ...objects: any[]): boolean; + + /** + * create a comparator to determine if any objects are equal in value to the initial + * + * @param object the object to test for equality + * @returns comparator function that checks if all the objects equal the initial + */ + function any(object: any): Comparator; + + /** + * determine if any of the objects passed are equal in value to the first + * + * @param object the object to test for equality against + * @param objects the objects to test for equality + * @returns are the objects equal + */ + function any(object: any, ...args: any[]): boolean; + + /** + * create a comparator for the first object passed to determine if a second is not equal + * + * @param object the object to test against + * @returns the method to test against the object + */ + function not(object: any): Comparator; + + /** + * determine if all of the objects passed are not equal in value to the first + * + * @param object the object to test against + * @param objects the objects to compare + * @returns are all the objects different from the first + */ + function not(object: any, ...objects: any[]): boolean; + } +} diff --git a/types/hash-it/tsconfig.json b/types/hash-it/tsconfig.json new file mode 100644 index 0000000000..6991bdcb40 --- /dev/null +++ b/types/hash-it/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "hash-it-tests.ts" + ] +} diff --git a/types/hash-it/tslint.json b/types/hash-it/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hash-it/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }