Installations
npm install @nexucis/kvsearch
Score
89.9
Supply Chain
99.1
Quality
77.6
Maintenance
100
Vulnerability
100
License
Releases
KVSearch 0.9.1
Published on 16 Jul 2024
KVSearch 0.9.0
Published on 16 Jul 2024
Codemirror 0.3.1
Published on 05 Aug 2022
KVSearch 0.8.1
Published on 05 Aug 2022
Codemirror 0.3.0
Published on 03 Aug 2022
Codemirror 0.2.0
Published on 23 May 2022
Developer
Nexucis
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
18.16.0
NPM Version
9.5.1
Statistics
2 Stars
87 Commits
2 Watching
1 Branches
1 Contributors
Updated on 16 Jul 2024
Languages
TypeScript (98.8%)
JavaScript (0.76%)
HTML (0.44%)
Total Downloads
Cumulative downloads
Total Downloads
671,544
Last day
-20%
1,195
Compared to previous day
Last week
7.5%
10,351
Compared to previous week
Last month
-1.7%
48,235
Compared to previous month
Last year
80.2%
386,867
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
KVSearch
Overview
This lib is providing a way to filter an array of any kind of object. You can provide an array of field you would like to "index", or you can generate your own query.
Installation
1npm install @nexucis/kvsearch
Usage
- Filter a list of object using a list of index
1import { KVSearch } from '@nexucis/kvsearch'; 2 3const list = [ 4 { 5 labels: { instance: 'demo.org', job: 'demo' }, 6 scrapePool: 'scrapePool demo' 7 }, 8 { 9 labels: { instance: 'k8s.org', job: 'constellation' }, 10 scrapePool: 'galaxy' 11 } 12] 13const search = new KVSearch({ 14 indexedKeys: [ 15 'labels', 16 'scrapePool', 17 ], 18}); 19search.filter('demo', list) // will match the first object 20search.filter('constellation', list) // won't match any object present in the list, since the attribute `labels.jop` is not indexed
Here the indexed list says:
- Since
labels
value is an object, then check if thepattern
is matching a key in the object return bylabels
- Same thing for
scrapePool
, excepting it returns a string, so the code won't loop other a list of key, it will just check if the value ofscrapePool
is matching thepattern
Note that the matching is using the lib @nexucis/fuzzy
, so it's not an exact match used.
- Filter a list of object using a list of index, with some regexp
1import { KVSearch } from '@nexucis/kvsearch'; 2 3const list = [ 4 { 5 labels: { instance: 'demo.org', job: 'demo' }, 6 scrapePool: 'scrapePool demo' 7 }, 8 { 9 labels: { instance: 'k8s.org', job: 'constellation' }, 10 scrapePool: 'galaxy' 11 } 12] 13const search = new KVSearch({ 14 indexedKeys: [ 15 'labels', 16 ['labels', /.*/], 17 'scrapePool', 18 ], 19}); 20search.filter('constel', list) // will match only the 2nd object
The difference here is we indexed the attributes of the labels
object. In this example, by using the Regexp /.*/
we
indexed every attribute of the object labels
. That's why the pattern constellation
is matching the second object.
But we could also just index the field job
of the labels
like that ['labels', 'job']
. It would have worked as
well.
- Filter a list of object using a specific query.
Using a list of index is simple, but it always used a fuzzy match. Probably sometimes you would like to do an exact match or a negative match depending on the context.
You can do it by creating your own query like that:
1import { KVSearch } from '@nexucis/kvsearch'; 2 3const list = [ 4 { 5 labels: { instance: 'demo.org', job: 'demo' }, 6 scrapePool: 'scrapePool demo' 7 }, 8 { 9 labels: { instance: 'k8s.org', job: 'constellation' }, 10 scrapePool: 'galaxy' 11 } 12] 13const search = new KVSearch(); 14search.filterWithQuery({ keyPath: ['labels', /.*/], match: 'exact', pattern: 'constellation' })
- Filter a list of object using a complex query.
It's possible to combine query together, so you can write multiple conditions.
1import { KVSearch } from '@nexucis/kvsearch'; 2 3const list = [ 4 { 5 labels: { instance: 'demo.org', job: 'demo' }, 6 scrapePool: 'scrapePool demo' 7 }, 8 { 9 labels: { instance: 'k8s.org', job: 'constellation' }, 10 scrapePool: 'galaxy' 11 }, 12 { 13 labels: { instance: 'awx.com', job: 'constellation' }, 14 scrapePool: 'galaxy', 15 } 16] 17const search = new KVSearch(); 18search.filterWithQuery({ 19 operator: 'and', 20 left: { 21 keyPath: ['scrapePool'], 22 match: 'fuzzy', 23 pattern: 'gal' 24 }, 25 right: { 26 keyPath: ['labels', 'instance'], 27 match: 'exact', 28 pattern: 'awx.com' 29 } 30}) // this query is matching the last element of the list.
Note as it can be painful to write the query himself, a support to write it with a string in the codemirror editor is available. Check it here
Demo
A demo is available if you want to run it.
- you need
node 16
andnpm 8
- Clone the project
- at the root of the project, run
npm install
- then run
npm start
the demo should start with webpack and you can open your browser with the URL provided by webpack.
License
No vulnerabilities found.
No security vulnerabilities found.
Other packages similar to @nexucis/kvsearch
@nexucis/fuzzy
small, standalone fuzzy search / fuzzy filter. browser or node
ng-onoff
[![CircleCI](https://circleci.com/gh/Nexucis/ng-onoff.svg?style=shield)](https://circleci.com/gh/Nexucis/ng-onoff) [![npm version](https://badge.fury.io/js/ng-onoff.svg)](https://badge.fury.io/js/ng-onoff) [![License](https://img.shields.io/:license-mit-b
@nexucis/codemirror-kvsearch
Codemirror-kvsearch ========