browser-utily-tools
Utility tools in the browser environment
API
API 参考
usage
npm install browser-utily-tools --save
DEMO-01
适配一个集合对数据
import { adapterDataListFormatSync } from "browser-utily-tools";
const source = [
{ number: 10, value: "黎明" },
{ number: 23, value: "liling" },
];
const rules = { number: "age", value: "name" };
const result = adapterDataListFormatSync(source, rules);
DEMO-02
适配一组数据
import { adapterDataFormatSync } from "browser-utily-tools";
const obj = { a: "a", b: "b" };
const rules = { a: "c" };
adapterDataFormatSync(obj);
DEMO-03
List 转为 Tree
import { listToTree } from "browser-utily-tools";
const entries = [
{
id: "12",
parentId: "0",
text: "Man",
level: "1",
children: null,
},
{
id: "6",
parentId: "12",
text: "Boy",
level: "2",
children: null,
},
{
id: "7",
parentId: "12",
text: "Other",
level: "2",
children: null,
},
{
id: "9",
parentId: "0",
text: "Woman",
level: "1",
children: null,
},
{
id: "11",
parentId: "9",
text: "Girl",
level: "2",
children: null,
},
];
listToTree(entries);
DEMO-04
一些基本类型方法
import { types } from "browser-utily-tools";
types.isArray([]);
types.isNAN(NAN);
types.isEqual({ a: 10 }, { a: 10 });
types.isNull(null);
types.isRegExp(/\[|]/g);
types.hasType(null);
types.hasType({});