Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/afeiship/config-query
A flexible library for dynamic queries on configuration objects with customizable filters.
https://github.com/afeiship/config-query
config filter find local query select sql
Last synced: about 2 months ago
JSON representation
A flexible library for dynamic queries on configuration objects with customizable filters.
- Host: GitHub
- URL: https://github.com/afeiship/config-query
- Owner: afeiship
- License: mit
- Created: 2018-03-15T07:12:55.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-09-18T04:51:43.000Z (5 months ago)
- Last Synced: 2024-10-28T07:30:41.606Z (3 months ago)
- Topics: config, filter, find, local, query, select, sql
- Language: TypeScript
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# config-query
> A flexible library for dynamic queries on configuration objects with customizable filters.[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]## installation
```shell
npm install @jswork/config-query
```## usage
```js
import ConfigQuery from '@jswork/config-query';const configs = [
{
school_level: null,
language: "zh-CN",
key: "yes_or_no",
value: [
{ label: "是", value: "yes" },
{ label: "否", value: "no" },
],
},
{
school_level: null,
language: "en-US",
key: "yes_or_no",
value: [
{ label: "Yes", value: "yes" },
{ label: "No", value: "no" },
],
},
];const query = new ConfigQuery(configs);
// select by key
const yes_no_items = query.select({ key: "yes_or_no" });
console.log(yes_no_items);/* ------------------------------ output ------------------------------
* [
* {
* "school_level": null,
* "language": "zh-CN",
* "key": "yes_or_no",
* "value": [
* { "label": "是", "value": "yes" },
* { "label": "否", "value": "no" }
* ]
* },
* {
* "school_level": null,
* "language": "en-US",
* "key": "yes_or_no",
* "value": [
* { "label": "Yes", "value": "yes" },
* { "label": "No", "value": "no" }
* ]
* }
* ]
*/// get by language
const en = query.find({ language: "en-US" });
console.log(en);/* ------------------------------ output ------------------------------
* {
* "school_level": null,
* "language": "en-US",
* "key": "yes_or_no",
* "value": [
* { "label": "Yes", "value": "yes" },
* { "label": "No", "value": "no" }
* ]
* }
*/// value filter
const yes = query.value({ key: "yes_or_no", "language": "zh-CN" });
console.log(yes);/* ------------------------------ output ------------------------------
* [
* { "label": "是", "value": "yes" },
* { "label": "否", "value": "no" }
* ]
*/
```## license
Code released under [the MIT license](https://github.com/afeiship/config-query/blob/master/LICENSE.txt).[version-image]: https://img.shields.io/npm/v/@jswork/config-query
[version-url]: https://npmjs.org/package/@jswork/config-query[license-image]: https://img.shields.io/npm/l/@jswork/config-query
[license-url]: https://github.com/afeiship/config-query/blob/master/LICENSE.txt[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/config-query
[size-url]: https://github.com/afeiship/config-query/blob/master/dist/index.min.js[download-image]: https://img.shields.io/npm/dm/@jswork/config-query
[download-url]: https://www.npmjs.com/package/@jswork/config-query