{"id":40872352,"url":"https://github.com/wenzi0github/kidash","last_synced_at":"2026-01-22T00:41:47.201Z","repository":{"id":258525813,"uuid":"873435646","full_name":"wenzi0github/kidash","owner":"wenzi0github","description":"JavaScript util tool","archived":false,"fork":false,"pushed_at":"2024-11-01T01:51:38.000Z","size":85,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-16T02:37:14.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wenzi0github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-16T06:59:01.000Z","updated_at":"2024-11-01T01:47:26.000Z","dependencies_parsed_at":"2024-10-20T13:04:15.766Z","dependency_job_id":null,"html_url":"https://github.com/wenzi0github/kidash","commit_stats":null,"previous_names":["wenzi0github/kidash"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wenzi0github/kidash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenzi0github%2Fkidash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenzi0github%2Fkidash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenzi0github%2Fkidash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenzi0github%2Fkidash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wenzi0github","download_url":"https://codeload.github.com/wenzi0github/kidash/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenzi0github%2Fkidash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28648460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T21:29:11.980Z","status":"ssl_error","status_checked_at":"2026-01-21T21:24:31.872Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-22T00:41:47.103Z","updated_at":"2026-01-22T00:41:47.196Z","avatar_url":"https://github.com/wenzi0github.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kidash\n\na famous and popular util tools.\n\n## covertNumToMaxSize\n\n将数字转为最高的单位，如：1024 转为 1KB。并可以相关的配置。非数字将被转为 0。\n\n详细使用可以参考： [数字转换为更高量级单位的工具方法](https://www.xiabingbao.com/post/fe/covert-num-sel4mj.html)\n\n```javascript\nimport { covertNumToMaxSize } from \"kidash\";\n\ncovertNumToMaxSize(null); // 0\ncovertNumToMaxSize(\"123\"); // 0\ncovertNumToMaxSize(1234567); // '123.5万'\ncovertNumToMaxSize(1367892445); // '13.7亿'\ncovertNumToMaxSize(1234567, { decimal: 2 }); // 保留2位小数，'123.46万'\n\n// 预计保留2位小数，但最后1位是0，进行舍弃\ncovertNumToMaxSize(1234017, { decimal: 2 }); // \"123.4万\"\n\n// 严格保留2位小数，不论最后一位是什么数字\ncovertNumToMaxSize(1234017, { decimal: 2, strict: true }); // \"123.40万\"\n\n// 默认会设置千分位\ncovertNumToMaxSize(1234); // '1,234'\n\n// 不设置千分位\ncovertNumToMaxSize(1234, { thousandth: false }); // 1234\n\n// 转为最高单位对应的数字，但不返回最后的单位\ncovertNumToMaxSize(1234017, { unit: false }); // 123.4\n\n// 设置转换基数和对应的单位\ncovertNumToMaxSize(1234017, {\n  sizes: [\n    [0, \"\"],\n    [1024, \"KB\"],\n    [1024 * 1024, \"MB\"],\n  ],\n}); // '1.2MB'\n```\n\n## getScript\n\nget script by async.\n\n异步加载 script。\n\n```javascript\nimport { getScript } from \"kidash\";\n\ngetScript(\"https://static.example.org/aa.js\").then(() =\u003e console.log(\"load aa complete\"));\n\ngetScript(\"https://static.example.org/bb.js\", {\n  id: \"script-bb-id\",\n  charset: \"UTF-8\",\n}).then(() =\u003e console.log(\"load bb complete\"));\n```\n\n## isNil\n\ncheck value is `null` or `undefined`.\n\n判断变量是否为 `null` 或 `undefined`。\n\n```javascript\nimport { isNil } from \"kidash\";\n\nisNil(null); // true\nisNil(undefined); // true\nisNil(false); // false\n```\n\n## isParamEmpty\n\ncheck value is empty.\n\n判断变量是否为空。这里与 lodash 的 isEmpty 不同，这里的 number, boolean 等类型的数据，认为是非空。\n\n```javascript\nimport { isParamEmpty } from \"kidash\";\n\nisParamEmpty(null); // true\nisParamEmpty(undefined); // true\n\nisParamEmpty(123); // false\nisParamEmpty(0); // false\nisParamEmpty(false); // false\nisParamEmpty(Number.NaN); // true\n\nisParamEmpty(\"   \"); // true\nisParamEmpty(\" abc  \"); // false\n\nisParamEmpty([]); // true\nisParamEmpty([1, 2]); // false\n\nisParamEmpty({}); // true\nisParamEmpty({ a: 21 }); // false\n\nisParamEmpty(new Map()); // true\nisParamEmpty(new Set()); // true\n\nconst map = new Map();\nmap.set(\"a\", 1);\nisParamEmpty(map); // false\n\nconst set = new Set();\nset.add(\"abc\");\nisParamEmpty(set); // false\n```\n\n## list2tree\n\n将数组转为树形结构。\n\n代码中会有 3 个默认值，但可以通过第 2 个参数修改配置：\n\n- id: 数据的主 id 字段名称；\n- pid: 父级 id 对应的字段名称，若字段名称不是 pid，可以设置为其他字段；\n- children: 子集元素对应的字段名称，若字段名称不是 children，可以设置为其他字段；\n\n```javascript\nimport { list2tree } from \"kidash\";\n\nconst list = [\n  { id: \"a\", name: \"aa\" },\n  { id: \"b\", name: \"bb\", pid: \"a\" },\n];\n\nlist2tree(list);\n/**\n * [\n *    {\n *      id: \"a\",\n *      name: \"aa\",\n *      children: [\n *        { id: \"b\", name: \"bb\", pid: \"a\" }\n *      ]\n *    }\n * ]\n */\n```\n\n字段对应不上，可以修改配置：\n\n```javascript\nconst list = [\n  { key: \"a\", name: \"aa\" },\n  { key: \"b\", name: \"bb\", parentId: \"a\" },\n];\n\nlist2tree(list, {\n  id: \"key\", // 主键字段名称\n  pid: \"parentId\", // 父级 id 对应的字段名称\n});\n```\n\n## openUrl\n\n在新页面打开链接。\n\n```javascript\nimport { openUrl } from \"kidash\";\n\nopenUrl(\"https://www.xiabingbao.com\");\n```\n\n## randomString\n\n获取随机字符串。\n\n- length: 获取字符串的长度，可选，默认长度是 32；\n- base: 从哪些字符中随机获取，可选，默认是 16 进制；\n\n\u003e 请注意，不要使用该方法用于生成唯一 id 使用。这里不保证全局的唯一性。\n\n```javascript\nimport { randomString } from \"kidash\";\n\nrandomString(); // 生成32位长度的随机字符串\nrandomString(12); // 生成12位长度的随机字符串\nrandomString(12, \"abcdefghijklmnopqrstuvwxyz\"); // 基于第2个参数的字符串，生成随机字符串\n```\n\n## random\n\n随机生成介于 min 和 max 之间`[min, max]`的数字，若只传一个参数，则认为是从 `[0, max]`。\n\n```javascript\nrandom(10, 20); // 生成介于10和20之间的随机数，包含上下限\nrandom(10); // 生成介于0和10之间的随机数，包含上下限\n```\n\n## size\n\n获取对象、数组、字符串的长度。\n\n```javascript\nsize(null); // 0\nsize(123); // 数字没有长度，为0\nsize([10, 20, 30]); // 3\nsize({ a: 1, b: 2 }); // 2\n\nconst map = new Map();\nmap.set(\"a\", 1);\nmap.set(\"b\", 3);\nsize(map); // 2\n```\n\n## sleep\n\n基于 Promise 的延时器。\n\n```javascript\nconst fn = async () =\u003e {\n  console.log(\"before sleep\", Date.now());\n  await sleep(1200);\n  console.log(\"after sleep\", Date.now());\n};\n```\n\n## trimData\n\n去除数据结构中，值的前后的空格。若该数据结构是 Object 或者 Array，将会递归。\n\n```javascript\ntrimData(\" a \"); // 'a'\ntrimData([\" a \", \" b \", \" c \"]); // ['a', 'b', 'c']\ntrimData({ a: \" a \", b: \" b \", c: \" c \" }); // { a: 'a', b: 'b', c: 'c' }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenzi0github%2Fkidash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwenzi0github%2Fkidash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenzi0github%2Fkidash/lists"}