1.7.15 • Published 1 year ago
deepsearchjs v1.7.15
deepsearchjs
Search for key in deeply-nested objects.
Installation
$ yarn add deepsearchjs
Usage
search<T>(object: T, any> | Array<any>, searchTerm: string): P;
Name | Description | Required | Type |
---|---|---|---|
object | Object to be searched | True | T = Record<any, any> \| Array<any> |
searchTerm | string to search for, a function that determines if an object key matches the query, or a regular expression to use for matching | True | string or ((key: string, value: any) => boolean) or RegExp |
output | Output object | --- | P = Record<key: string, any> Where, key is a valid object path(eg. a.b.c[0].d.e , etc..) |
Parameters
obj
(T
): The object to search. It is also generic, meaning it can accept any type of object.query
(string
|((key: string, value: any) => boolean)
|RegExp
): The query to search for. This can be a string, a function, or a regular expression.- If it is a string, the function will search for keys that end with that string.
- If it is a function, it will determine if the key matches the query.
- If it is a regular expression, it will test the key against that regular
Example
index.ts
import { search } from "deepsearchjs";
import data from "./data.json";
// string as query
search(data, "city");
// call back function as query
search(data, (key: string, value: string): boolean => /city/gi.test(key));
// regex as query
search(data, /city/gi);
/*
* All three calls will have the same output:
* {
* "users[0].address.city": "Jenkinsboro",
* "users[0].address.previousAddresses[0].city": "Folsom",
* ...
* }
*/
TODO
- ci/cd: Automate versioning and releases
- feat: Optimize search algorithm to handle oversized datasets
- feat: Add a third parameter to the function to customize the search parameters ( leaf-node results only, etc... )
- feat: Search across values??
Benchmark
- text-based search x 22,188 ops/sec ±0.20% (94 runs sampled)
- regex-based search x 29,531 ops/sec ±0.11% (97 runs sampled)
- cb-based search x 9,243 ops/sec ±0.21% (96 runs sampled)
- Fastest method ( for the current release ): regex-based search :sparkles::tada:!!
1.7.15
1 year ago
1.7.3
1 year ago
1.5.5
1 year ago
1.7.2
1 year ago
1.5.4
1 year ago
1.7.1
1 year ago
1.5.3
1 year ago
1.5.2
1 year ago
1.6.0
1 year ago
1.5.1
1 year ago
1.5.0
1 year ago
1.7.10
1 year ago
1.7.11
1 year ago
1.5.10
1 year ago
1.7.12
1 year ago
1.7.13
1 year ago
1.5.12
1 year ago
1.5.11
1 year ago
1.5.14
1 year ago
1.5.13
1 year ago
1.5.15
1 year ago
1.7.9
1 year ago
1.5.9
1 year ago
1.5.8
1 year ago
1.5.7
1 year ago
1.5.6
1 year ago
1.4.0
1 year ago
1.2.0
1 year ago
1.1.0
1 year ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago
0.1.0
1 year ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago
0.0.1-alhpa.8
1 year ago
0.0.1-alhpa.7
1 year ago
0.0.1-alhpa.6
1 year ago
0.0.1-alhpa.5
1 year ago
0.0.1-alhpa.3
1 year ago
0.0.1-alhpa.2
1 year ago