Add type definitions for array-binarysearch.closest

This commit is contained in:
Heye Voecking
2019-04-04 17:02:03 +02:00
parent 510793441f
commit 428fb90a13
4 changed files with 66 additions and 0 deletions
@@ -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
+13
View File
@@ -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 <https://github.com/hvoecking>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function binarySearch<T>(
arr: ReadonlyArray<T>,
val: T,
fn?: null | ((itm: T, val: T, m: any, arr: ReadonlyArray<T>) => number),
ths?: any,
bgn?: number,
end?: number,
): number;
@@ -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"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }