美文网首页
key-value-equal

key-value-equal

作者: cq0122 | 来源:发表于2019-06-08 16:03 被阅读0次

https://github.com/cq0122/key-value-equal

Declare an object with the same key value.

Declare an object with the same key value, you need to use Ctrl+C many times.

const config = {
    USER: "USER",
    MENU: "MENU",

    PROVINCES: "PROVINCES",
    CITYS: "CITYS",
    
    ...
};

Installation kve.

$npm install key-value-equal --save

Use kve, no Ctrl+C necessary.

import { kve } from "key-value-equal";

const config = kve("USER", "MENU", "PROVINCES", "CITYS", ...);
//=> {USER:"USER", MENU:"MENU", PROVINCES:"PROVINCES", CITYS:"CITYS", ...}

Making the code easier to read, kve also supports grouping, the multidimensional array will be flattened.

import { kve } from "key-value-equal";

const config = kve(["USER", "MENU"], ["PROVINCES", "CITYS"], ...);
//=> {USER:"USER", MENU:"MENU", PROVINCES:"PROVINCES", CITYS:"CITYS", ...}

There are also little surprises.

  • kfn.upper
import { kve, kfn } from "key-value-equal";

const config = kve("user", "menu", "provinces", "citys", ... , kfn.upper);
//const config = kve("USER", "MENU", "PROVINCES", "CITYS", ...);
//=> {USER:"USER", MENU:"MENU", PROVINCES:"PROVINCES", CITYS:"CITYS", ...}
  • kfn.lower
import { kve, kfn } from "key-value-equal";

const config = kve("USER", "MENU", "PROVINCES", "CITYS", ... , kfn.lower);
//const config = kve("user", "menu", "provinces", "citys", ...);
//=> {user:"user", menu:"menu", provinces:"provinces", citys:"citys", ...}
  • kfn.hump
import { kve, kfn } from "key-value-equal";

const config = kve("user_setting", "menu_conf", "province_list", "city_list", ... , kfn.hump);
//const config = kve("userSetting", "menuConf", "provinceList", "cityList", ...);
//=> {userSetting:"userSetting", menuConf:"menuConf", provinceList:"provinceList", cityList:"cityList", ...}
  • kfn.line
import { kve, kfn } from "key-value-equal";

const config = kve("userSetting", "menuConf", "provinceList", "cityList", ... , kfn.line);
//const config = kve("user_setting", "menu_conf", "province_list", "city_list", ...);
//=> {user_setting:"user_setting", menu_conf:"menu_conf", province_list:"province_list", city_list:"city_list", ...}

Hope you will like !

相关文章

  • key-value-equal

    https://github.com/cq0122/key-value-equal Declare an obje...

网友评论

      本文标题:key-value-equal

      本文链接:https://www.haomeiwen.com/subject/ykvixctx.html