Skip to content
On this page

date-search - v1.1.1 / Exports

date-search - v1.1.1

Table of contents

References

Enumerations

Type Aliases

Variables

Functions

References

default

Renames and re-exports dateSearch

Type Aliases

Comparator

Ƭ Comparator<T>: (targetVal: DateSearchTargets, searchVal: T) => number

Type parameters

Name
T

Type declaration

▸ (targetVal, searchVal): number

Compares the two values numerically

Parameters
NameType
targetValDateSearchTargets
searchValT
Returns

number

Defined in

dateSearch.ts:37


DateSearchResult

Ƭ DateSearchResult<T>: Object

Search result format returned by the search including the array index and the matching value.

Type parameters

Name
T

Type declaration

NameType
index?number
value?T

Defined in

dateSearch.ts:8


DateSearchTargets

Ƭ DateSearchTargets: string | number | Date | dayjs.Dayjs | null | undefined

Valid date inputs to provide to the target parameter. If the value is falsy an error will be thrown.

Defined in

dateSearch.ts:26

Variables

DATE_TYPES

Const DATE_TYPES: string[]

JS primitives that can describe a date. DayJS is used to parse them to Date objects.

Only "string", "number", "Date" objects are valid.

Defined in

dateSearch.ts:47

Functions

dateSearch

dateSearch<T>(array, target, comparator?, dateSearchMode?): DateSearchResult<T>

Binary Search for dates or time series data.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
arrayT[]undefinedSorted array containing date/time values
targetDateSearchTargetsundefineddate/time value
comparatornull | string | Comparator<T>defaultTimeComparatorstring pointing to a nested key or comparator function
dateSearchModeDateSearchModesDateSearchModes.EXACTExact or fuzzy search

Returns

DateSearchResult<T>

Defined in

dateSearch.ts:147


dateSearchBetween

dateSearchBetween<T>(array, startDate, endDate, comparator?): DateSearchBetweenResult<T>

Binary Search for dates or time series data.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
arrayT[]undefinedSorted array containing date/time values
startDateDateSearchTargetsundefined-
endDateDateSearchTargetsundefined-
comparatornull | string | Comparator<T>defaultTimeComparatorstring pointing to a nested key or comparator function

Returns

DateSearchBetweenResult<T>

Defined in

dateSearch.ts:228


deepTimeComparator

deepTimeComparator<T>(target, search, stringPath?, comparator?): number

Compare nested data that contains a date/time stamp.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
targetDateSearchTargetsundefinedsearched for value
searchTundefinedcompared value
stringPathstring"value"deep pointer to key in nested objects
comparatorComparator<T>defaultTimeComparatorcomparison fn

Returns

number

number

Defined in

dateSearch.ts:116


defaultTimeComparator

defaultTimeComparator<T>(targetVal, searchVal): number

Compares two times/dates and determine which direction to search.

Type parameters

Name
T

Parameters

NameType
targetValDateSearchTargets
searchValT

Returns

number

number

Defined in

dateSearch.ts:94


isDateType

isDateType<T>(x): boolean

Determines if dayJS can parse the input value.

Type parameters

Name
T

Parameters

NameTypeDescription
xTany input type

Returns

boolean

boolean

Defined in

dateSearch.ts:54


parseToValidNumber

parseToValidNumber<T>(x): number

Fallback, try to make a numeric representation of a non-standard input Arrays, Strings or objects use length.

Worst case, this allows for graceful failure and allows the algo to continue if invalid data is provided.

Type parameters

Name
T

Parameters

NameType
xT

Returns

number

number

Defined in

dateSearch.ts:72