1.0.6 • Published 11 months ago

@jswork/config-query v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

config-query

A flexible library for dynamic queries on configuration objects with customizable filters.

version license size download

installation

npm install @jswork/config-query

usage

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.

1.0.6

11 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago