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
Name | Type |
---|---|
targetVal | DateSearchTargets |
searchVal | T |
Returns
number
Defined in
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
Name | Type |
---|---|
index? | number |
value? | T |
Defined in
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
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
Functions
dateSearch
▸ dateSearch<T
>(array
, target
, comparator?
, dateSearchMode?
): DateSearchResult
<T
>
Binary Search for dates or time series data.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
array | T [] | undefined | Sorted array containing date/time values |
target | DateSearchTargets | undefined | date/time value |
comparator | null | string | Comparator <T > | defaultTimeComparator | string pointing to a nested key or comparator function |
dateSearchMode | DateSearchModes | DateSearchModes.EXACT | Exact or fuzzy search |
Returns
Defined in
dateSearchBetween
▸ dateSearchBetween<T
>(array
, startDate
, endDate
, comparator?
): DateSearchBetweenResult
<T
>
Binary Search for dates or time series data.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
array | T [] | undefined | Sorted array containing date/time values |
startDate | DateSearchTargets | undefined | - |
endDate | DateSearchTargets | undefined | - |
comparator | null | string | Comparator <T > | defaultTimeComparator | string pointing to a nested key or comparator function |
Returns
DateSearchBetweenResult
<T
>
Defined in
deepTimeComparator
▸ deepTimeComparator<T
>(target
, search
, stringPath?
, comparator?
): number
Compare nested data that contains a date/time stamp.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
target | DateSearchTargets | undefined | searched for value |
search | T | undefined | compared value |
stringPath | string | "value" | deep pointer to key in nested objects |
comparator | Comparator <T > | defaultTimeComparator | comparison fn |
Returns
number
number
Defined in
defaultTimeComparator
▸ defaultTimeComparator<T
>(targetVal
, searchVal
): number
Compares two times/dates and determine which direction to search.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
targetVal | DateSearchTargets |
searchVal | T |
Returns
number
number
Defined in
isDateType
▸ isDateType<T
>(x
): boolean
Determines if dayJS can parse the input value.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
x | T | any input type |
Returns
boolean
boolean
Defined in
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
Name | Type |
---|---|
x | T |
Returns
number
number