https://github.com/frankflitton/date-search
npm package to search time series data
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.1%) to scientific vocabulary
Keywords
Repository
npm package to search time series data
Basic Info
- Host: GitHub
- Owner: FrankFlitton
- License: apache-2.0
- Language: TypeScript
- Default Branch: main
- Homepage: https://date-search.netlify.app
- Size: 373 KB
Statistics
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 1
Topics
Metadata Files
README.md
date-search
Universal time series search
Search through your time series data with javascript. Find a value or its closest match through a list of dates or data frames. Dates can be represented as date string or number format that dateJS can parse.
For advanced use cases, you can provide a custom comparison function for non-standard formats.
Documentation
For detailed documentation: https://date-search.netlify.app
Installation
js
npm i date-search
Usage
Use the dateSearch function to quickly find if your target date is present.
```js import { dateSearch } from 'date-search'; // or use require
const bigSortedDatesArray = [Date('2000-1-1'), Date('2000-1-2'), Date('2000-1-3')]; const targetDate = '2000-1-1';
const {index, value} = dateSearch( bigSortedDatesArray, targetDate ); targetDate === value; // true index; // 0
```
The dateSearchBetween will return the closest matching results inclusive of the target start and end search dates.
```js import { dateSearchBetween } from 'date-search'; // or use require
const bigSortedDatesArray = [Date('2000-1-1'), Date(), Date(), ...];
const startDate = '2000-1-13'; const endDate = '2000-1-23';
const {startValue, endValue, array} = dateSearchBetween( bigSortedDatesArray, targetDate ); array.length; // 11
```
Features
- Date, timestamp string, and unix date numbers excepted.
- Custom comparators:
- String referencing a value within an object or nested object.
- Custom comparison function and date parsing.
- Get segment of array that matches between two dates.
- Built with DayJS for MomentJS regression and more reliable date parsing.
- Fuzzy search: find the exact or closest item.
- Written in typescript with type documentation.
Advanced Usage
The search algo accepts these parameters:
array
A typed array of dates or nested objects containing dates. These should be sorted by oldest to most recent.
target
The value the algo is searching for. This should be the date that is being searched for. Valid inputs include string, number, Date, and Dayjs objects. null can be supplied but the module will throw an error.
comparator (optional)
ComparatorFn
Uses the builtin defaultTimeComparator by default if no value is provided. It returns a positive or negative number that indicates which side of the array to search next.
```js dayjs.extend(customParseFormat)
dateSearch( array: [{id: 123, child: {date: '12-25-1995'}}, ...], target: '12-25-1995', comparator: (a, b) => dayJS(a, "MM-DD-YYYY").unix() - dayJS(b, "MM-DD-YYYY").unix(), ) ```
string
Points to a nested key of an object containing the date value. It uses the same comparison logic as the defaultTimeComparator once the values are parsed.
js
dateSearch(
array: [{id: 123, child: {date: '2020-1-1'}}, ...],
target: '2020-1-1',
comparator: 'child.date',
dateSearchMode: DateSearchModes.EXACT
)
dateSearchMode
EXACT
Find the exact value. Returns null if not found.
js
dateSearch(
array: [{id: 123, child: {date: '2020-1-1'}}, ...],
target: '1995-1-1',
comparator: defaultTimeComparator,
dateSearchMode: DateSearchModes.EXACT
) // not found, null is returned
CLOSEST_FLOOR
Find the closest index, rounding down. The first element is used if the target value is lower than the first array element.
js
dateSearch(
array: ['2020-1-1', '2020-2-1', '2020-5-1', ...],
target: '1995-3-1',
comparator: defaultTimeComparator,
dateSearchMode: DateSearchModes.CLOSEST_FLOOR
) // returns index 1, value of 2020-2-1
CLOSEST_CEIL
Find the closest index, rounding up. The last element is used if the target value is greater than the last array element.
js
dateSearch(
array: ['2020-1-1', '2020-2-1', '2020-5-1', ...],
target: '1995-3-1',
comparator: defaultTimeComparator,
dateSearchMode: DateSearchModes.CLOSEST_CEIL
) // returns index 2, value of 2020-2-1
Owner
- Name: Frank Flitton
- Login: FrankFlitton
- Kind: user
- Location: Seattle, WA, USA
- Company: @Google
- Website: http://frankflitton.com
- Twitter: frankflitton
- Repositories: 28
- Profile: https://github.com/FrankFlitton
UX Engineer. Fullstack Web + UI/UX
GitHub Events
Total
Last Year
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 30
- Total Committers: 1
- Avg Commits per committer: 30.0
- Development Distribution Score (DDS): 0.0
Top Committers
| Name | Commits | |
|---|---|---|
| Frank Flitton | f****n@g****m | 30 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- 430 dependencies
- @babel/preset-env ^7.20.2 development
- @rollup/plugin-typescript ^11.0.0 development
- @types/jest ^29.4.0 development
- @types/lodash.get ^4.4.7 development
- @types/lodash.isempty ^4.4.7 development
- babel-jest ^29.4.3 development
- jest ^29.4.3 development
- picocolors ^1.0.0 development
- rollup-plugin-typescript-paths ^1.4.0 development
- rollup-plugin-visualizer ^5.9.0 development
- ts-jest ^29.0.5 development
- tslib ^2.5.0 development
- typedoc ^0.23.25 development
- typescript ^4.9.3 development
- vite ^4.1.0 development
- vite-plugin-progress ^0.0.6 development
- dayjs ^1.11.7
- lodash.get ^4.4.2
- lodash.isempty ^4.4.0