From 428fb90a130661f221b3eb0bbdddd7e77913bf8b Mon Sep 17 00:00:00 2001 From: Heye Voecking Date: Thu, 4 Apr 2019 16:46:34 +0200 Subject: [PATCH] Add type definitions for array-binarysearch.closest --- .../array-binarysearch.closest-tests.ts | 29 +++++++++++++++++++ types/array-binarysearch.closest/index.d.ts | 13 +++++++++ .../array-binarysearch.closest/tsconfig.json | 23 +++++++++++++++ types/array-binarysearch.closest/tslint.json | 1 + 4 files changed, 66 insertions(+) create mode 100644 types/array-binarysearch.closest/array-binarysearch.closest-tests.ts create mode 100644 types/array-binarysearch.closest/index.d.ts create mode 100644 types/array-binarysearch.closest/tsconfig.json create mode 100644 types/array-binarysearch.closest/tslint.json diff --git a/types/array-binarysearch.closest/array-binarysearch.closest-tests.ts b/types/array-binarysearch.closest/array-binarysearch.closest-tests.ts new file mode 100644 index 0000000000..eff67da3c2 --- /dev/null +++ b/types/array-binarysearch.closest/array-binarysearch.closest-tests.ts @@ -0,0 +1,29 @@ +import { binarySearch } from 'array-binarysearch.closest'; + +// Test with object + +binarySearch( + [{ time: new Date(21) }, { time: new Date(42) }, { time: new Date(91) }, { time: new Date(91) }], + { time: new Date(92) }, + (a, b) => a.time.getTime() - b.time.getTime(), + null, + 0, + 4, +); + +// Test with primitve types +// Tests below are the examples from the projects README + +binarySearch([21, 42, 91, 91], 40); +// 1 +binarySearch([21, 42, 91, 91], 42, null, null, 2); +// 2 +binarySearch([21, 42, 91, 91], 92, null, null, 2, 4); +// 4 + +binarySearch([21, 42, 91, 91], 40, (a, b) => a === b ? 0 : (a < b ? -1 : 1)); +// 1 +binarySearch(['G', 'KG', 'KG', 'MG'], 'g', (a, b, i) => a.toLowerCase().localeCompare(b.toLowerCase()), null, 1); +// 1 +binarySearch(['G', 'KG', 'KG', 'MG'], 'KG', (a, b, i, arr) => a.localeCompare(b), null, 1, 4); +// 2 diff --git a/types/array-binarysearch.closest/index.d.ts b/types/array-binarysearch.closest/index.d.ts new file mode 100644 index 0000000000..205e1c6926 --- /dev/null +++ b/types/array-binarysearch.closest/index.d.ts @@ -0,0 +1,13 @@ +// Type definitions for array-binarysearch.closest 0.2 +// Project: https://www.npmjs.com/package/array-binarysearch.closest +// Definitions by: Heye Vöcking +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export function binarySearch( + arr: ReadonlyArray, + val: T, + fn?: null | ((itm: T, val: T, m: any, arr: ReadonlyArray) => number), + ths?: any, + bgn?: number, + end?: number, +): number; diff --git a/types/array-binarysearch.closest/tsconfig.json b/types/array-binarysearch.closest/tsconfig.json new file mode 100644 index 0000000000..becce72408 --- /dev/null +++ b/types/array-binarysearch.closest/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "array-binarysearch.closest-tests.ts" + ] +} diff --git a/types/array-binarysearch.closest/tslint.json b/types/array-binarysearch.closest/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/array-binarysearch.closest/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }