js工具库j4tools(二)

j4tools
【js工具库j4tools(二)】一款支持 tree-shaking,轻量级的工具库

文档地址

github 地址 欢迎 star 和 pr
功能介绍
判断浏览器

import { isBrowser } from "j4tools"; isBrowser(); // true or false

判断设备
import { deviceType } from "j4tools"; deviceType(); // Mobile or Desktop

获取 url 参数
import { getURLParams } from "j4tools"; getURLParams("google.com"); // {}getURLParams("http://google.com/page?name=knox&surname=zhang"); // {name: 'knox', surname: 'zhang'}

通过属性查找路径
import { getNodePath } from "j4tools"; const data = https://www.it610.com/article/[ { id: 1, children: [ { id: 2, parentId: 1 }, { id: 3, parentId: 1, children: [ { id: 4, parentId: 3, }, ], }, ], }, ]; getNodePath(data, 4); // [ //{ //"id": 1, //"children": [ //{ //"id": 2, //"parentId": 1 //}, //{ //"id": 3, //"parentId": 1, //"children": [ //{ //"id": 4, //"parentId": 3 //} //] //} //] //}, //{ //"id": 3, //"parentId": 1, //"children": [ //{ //"id": 4, //"parentId": 3 //} //] //}, //{ //"id": 4, //"parentId": 3 //} // ]

自定义属性查找路径
import { getNodePath } from "j4tools"; const data = https://www.it610.com/article/[ { kid: 1, kchildren: [ { kid: 2, kparentId:"1" }, { kid: 3, kparentId: "1" }, ], }, ]; getNodePath(data, "3", { idKey: "kid", parentIdKey: "kparentId", childrenKey: "kchildren", }); // [ //{ kid: '1', kchildren: [ [Object], [Object] ] }, //{ kid: 2, kparentId: '1' } // ]

文档地址

github 地址 欢迎 star 和 pr

    推荐阅读