{"id":22267562,"url":"https://github.com/lakca/decent-unit","last_synced_at":"2025-03-25T14:43:01.644Z","repository":{"id":57126166,"uuid":"288633894","full_name":"lakca/decent-unit","owner":"lakca","description":"Decent conversion of measurement units.","archived":false,"fork":false,"pushed_at":"2020-09-04T08:44:47.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T04:05:05.477Z","etag":null,"topics":["conversion","decent","unit"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lakca.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-19T04:33:28.000Z","updated_at":"2020-09-04T08:44:49.000Z","dependencies_parsed_at":"2022-08-31T08:12:00.549Z","dependency_job_id":null,"html_url":"https://github.com/lakca/decent-unit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fdecent-unit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fdecent-unit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fdecent-unit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lakca%2Fdecent-unit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lakca","download_url":"https://codeload.github.com/lakca/decent-unit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245485311,"owners_count":20623229,"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","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":["conversion","decent","unit"],"created_at":"2024-12-03T11:07:24.493Z","updated_at":"2025-03-25T14:43:01.620Z","avatar_url":"https://github.com/lakca.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# decent-unit\n\nDecent conversion of measurement units.\n\n[![Build Status](https://travis-ci.org/lakca/decent-unit.svg?branch=master)](https://travis-ci.org/lakca/decent-unit)\n[![codecov](https://codecov.io/gh/lakca/decent-unit/branch/master/graph/badge.svg)](https://codecov.io/gh/lakca/decent-unit)\n\n## Usage\n\n```js\nconst decentUnit = require('@lakca/decent-unit')\n```\n\n## Example\n\n```js\n// decent result: { value: 2, unit: 'G' }\ndecentUnit(2 * 1024 ** 3)\n\n// decent result: { value: 2, unit: 'E' }\ndecentUnit(2 * 1024 ** 3, { fromUnit: 'G' })\n\n// decent result { value: 2, unit: 'E' }\ndecentUnit(2 * 1000 ** 3, { fromUnit: 'G', radix: 1000 })\n\n// decent result { value: 1, unit: 'G' }\ndecentUnit(20000, { fromUnit: '', radix: [100, 20, 10, 2], units: ['', 'K', 'M', 'G', 'T'] })\n\n// expected result { value: 2048, unit: 'P' }\ndecentUnit(2 * 1024 ** 3, { fromUnit: 'G', toUnit: 'P' })\n```\n\nMore in [test](test/main.js).\n\n## API\n\n### `decentUnit(num: number, options?: object)`\n\n#### `{T} [options.fromUnit='']`\n\n\u003e unit of `num`.\n\n#### `{T} [options.toUnit]`\n\n\u003e target unit, if empty, decent unit will be returned.\n\n#### `{number|number[]} [options.radix=1024]`\n\n\u003e conversion radix.\n  If is an `array`, element is radix between every nearby units,\n  and filled with the last array element if length is more than 1 less than `options.units`.\n\n#### `@param {T[]} [options.units=['', 'K', 'M', 'G', 'T', 'P', 'E']]`\n\n\u003e available units\n\nSee [decentUnit](index.js#L28)\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flakca%2Fdecent-unit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flakca%2Fdecent-unit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flakca%2Fdecent-unit/lists"}