{"id":28433366,"url":"https://github.com/log1997/log-utils","last_synced_at":"2025-08-23T09:11:55.314Z","repository":{"id":130430999,"uuid":"606319627","full_name":"LOG1997/log-utils","owner":"LOG1997","description":"log1997's utils package","archived":false,"fork":false,"pushed_at":"2023-04-04T07:27:02.000Z","size":1226,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-16T15:45:02.776Z","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/LOG1997.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,"zenodo":null}},"created_at":"2023-02-25T05:57:57.000Z","updated_at":"2023-02-25T13:08:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"e8915faa-27d3-40f8-a8da-fb355fe312dc","html_url":"https://github.com/LOG1997/log-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LOG1997/log-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LOG1997%2Flog-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LOG1997%2Flog-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LOG1997%2Flog-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LOG1997%2Flog-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LOG1997","download_url":"https://codeload.github.com/LOG1997/log-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LOG1997%2Flog-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271746302,"owners_count":24813557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-06-05T18:08:59.207Z","updated_at":"2025-08-23T09:11:55.300Z","avatar_url":"https://github.com/LOG1997.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# log-utils\n\u003cp\u003e\u003cimg alt=\"GitHub package.json version\" src=\"https://img.shields.io/github/package-json/v/log1997/log-utils\"\u003e\u003c/p\u003e\n\na collection of common utils by [log1997](https://github.com/LOG1997)\n\nit's can be used with vue,react or other js framework.\n\n## Install\n\n```bash\nnpm install log1997-utils\n```\n\n## Usage\n\nthere are some utils in this package.you can use them by import them.\nfor example:\n```js\n// this function can be used to get tree data from list data\nimport { arrayToTree } from 'log1997-utils'\nconst arrData=[\n    {id:1,name:'a',pid:0},\n    {id:2,name:'b',pid:1},\n    {id:3,name:'c',pid:1},\n    {id:4,name:'d',pid:2},\n    {id:5,name:'e',pid:2},\n    {id:6,name:'f',pid:3},\n    {id:7,name:'g',pid:3},\n    {id:8,name:'h',pid:4},\n]\ncosnt treeData=arrayToTree(arrData);\nconsole.log(treeData);\n```\n\n## API\n\u003c!-- toc --\u003e\n* [ArrayFunc](#arrayfunc)\n  * [arrayToTree](#arraytotree)\n  * [treeToArray](#treetoarray)\n* [ColorFunc](#colorfunc)\n    * [getRandomGradientColor](#getrandomgradientcolor)\n* [MathFunc](#mathfunc)\n    * [byteToUnit](#bytetounit)\n\u003c!-- tocstop --\u003e\n### ArrayFuc\n#### `arrayToTree`\nthere are some params in this function:\n**your arrData's item have to have idKey and pidKey.**\n* arrData:a array and it's **necessary**.\n* idKey:the key of id in arrData,it's default value is 'id',**not necessary**.\n* pidKey:the key of pid in arrData,it's default value is 'pid'.**not necessary**.\n* childrenKey:the key of children in arrData,it's default value is 'children'.**not necessary**.\n\nthere are a return data:\n* treeData:it's a tree data.\n\n\n#### `treeToArray`\nthere are some params in this function:\n\n* treeData:a tree data and it's **necessary**.\n* childrenKey:the key of children in treeData,it's default value is 'children'.**not necessary**.\n\nthere are a return data:\n* arrData:it's a array data.\n\n\n### ColorFunc\n#### `getRandomGradientColor`\nthis function can be used to get a random gradient color string.\nthere are some params in this function:\n* hexColor:the number of hexcolor in gradient color string. like:#ffffff.**not necessary**.\n* deg:the deg of gradient color,it's tyep is number. like:90.**not necessary**.\n* Colorangle:the angle of gradient color,it's type is number. like:90.**not necessary**.\nthere are a return data:\n* color:it's a gradient color string.like:linear-gradient(90deg, #ffffff, #ffffff).\n\nand ther are other functions in this package.\n\ntable of contents:\n\n| Function | Description |\n| --- | --- |\n|rgb2Hsv|rgb to hsv|\n|rgb2Hsl|rgb to hsl|\n|rgb2Hex|rgb to hex|\n|hex2Rgb|hex to rgb|\n|hsv2Rgb|hsv to rgb|\n|rotateHsv|rotate hsv default angle is 30°|\n|randomColor|get a random color|\n\n### MathFunc\n#### `byteToUnit`\nthis function can be used to convert byte to unit.\nfor example,if you want to convert 1024 byte to kb, you can use this function like this:\n```js\nimport { byteToUnit } from 'log1997-utils'\nconst kb=byteToUnit(1025,'kb'); //100.10KB\n```\nparams:\n* byte:the number of byte.**necessary**.\n* unit:the unit of byte.default value is ''**not necessary**.\n* fixed:the number of fixed.default value is 2.**not necessary**.\n\nreturn:\n* unitByte:the string of unit data.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flog1997%2Flog-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flog1997%2Flog-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flog1997%2Flog-utils/lists"}