Gathering detailed insights and metrics for @nexucis/kvsearch
Gathering detailed insights and metrics for @nexucis/kvsearch
Gathering detailed insights and metrics for @nexucis/kvsearch
Gathering detailed insights and metrics for @nexucis/kvsearch
npm install @nexucis/kvsearch
Typescript
Module System
Node Version
NPM Version
KVSearch 0.9.1
Updated on Jul 16, 2024
KVSearch 0.9.0
Updated on Jul 16, 2024
Codemirror 0.3.1
Updated on Aug 05, 2022
KVSearch 0.8.1
Updated on Aug 05, 2022
Codemirror 0.3.0
Updated on Aug 03, 2022
Codemirror 0.2.0
Updated on May 23, 2022
TypeScript (98.8%)
JavaScript (0.76%)
HTML (0.44%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
87 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jul 16, 2024
Latest Version
0.9.1
Package Id
@nexucis/kvsearch@0.9.1
Unpacked Size
61.67 kB
Size
8.42 kB
File Count
11
NPM Version
9.5.1
Node Version
18.16.0
Published on
Jul 16, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
1npm install @nexucis/kvsearch
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:
labels
value is an object, then check if the pattern
is matching a key in the object return by labels
scrapePool
, excepting it returns a string, so the code won't loop other a list of key, it will just
check if the value of scrapePool
is matching the pattern
Note that the matching is using the lib @nexucis/fuzzy
, so it's not an exact match used.
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.
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' })
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 coming soon.
For the moment, the codemirror support doesn't handle the regexp.
No vulnerabilities found.
No security vulnerabilities found.