deepsearchjs

build test

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

sample data

index.ts

TODO

Benchmark

  • text-based search x 8,817 ops/sec ±2.15% (68 runs sampled)

  • regex-based search x 11,201 ops/sec ±2.04% (62 runs sampled)

  • cb-based search x 3,621 ops/sec ±4.19% (65 runs sampled)

  • Fastest method ( for the current release ): regex-based search ✨🎉!!

JSON results

Last updated