@types/sorted-array-functions
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

Installation

npm install --save @types/sorted-array-functions

Summary

This package contains type definitions for sorted-array-functions (https://github.com/mafintosh/sorted-array-functions).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sorted-array-functions.

index.d.ts

export type CompareFn<T = any> = (a: T, b: T) => -1 | 0 | 1;

/**
 * Insert a new value into the list sorted.
 * Optionally you can use a custom compare function that returns, compare(a, b) that returns 1 if a > b, 0 if a === b and -1 if a < b.
 */
export function add<T>(list: T[], value: T, compareFn?: CompareFn<T>): void;

/**
 * Inserts a new value (same result as sorted.add()) optimized for prepend.
 */
export function addFromFront<T>(list: T[], value: T, compareFn?: CompareFn<T>): void;

/**
 * Remove a value.
 * Returns true if the value was in the list.
 */
export function remove<T>(list: T[], value: T, compareFn?: CompareFn<T>): boolean;

/**
 * Check if a value is in the list.
 */
export function has<T>(list: readonly T[], value: T, compareFn?: CompareFn<T>): boolean;

/**
 * Get the index of a value in the list (uses binary search).
 * If the value could not be found, -1 is returned.
 */
export function eq<T>(list: readonly T[], value: T, compareFn?: CompareFn<T>): number;

/**
 * Get the index of the first value that is >=.
 * If the value could not be found, -1 is returned.
 */
export function gte<T>(list: readonly T[], value: T, compareFn?: CompareFn<T>): number;

/**
 * Get the index of the first value that is >.
 * If the value could not be found, -1 is returned.
 */
export function gt<T>(list: readonly T[], value: T, compareFn?: CompareFn<T>): number;

/**
 * Get the index of the first value that is <=.
 * If the value could not be found, -1 is returned.
 */
export function lte<T>(list: readonly T[], value: T, compareFn?: CompareFn<T>): number;

/**
 * Get the index of the first value that is <.
 * If the value could not be found, -1 is returned.
 */
export function lt<T>(list: readonly T[], value: T, compareFn?: CompareFn<T>): number;

export function nearest<T>(list: readonly T[], value: T, compareFn?: CompareFn<T>): number;

Additional Details

  • Last updated: Mon, 20 Nov 2023 23:36:24 GMT
  • Dependencies: none

Credits

These definitions were written by Behind The Math.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/sorted-array-functions

Weekly Downloads

4,010

Version

1.3.3

License

MIT

Unpacked Size

6.42 kB

Total Files

5

Last publish

Collaborators

  • types