{"id":15429628,"url":"https://github.com/yanickrochon/number-scale","last_synced_at":"2026-04-29T22:04:18.682Z","repository":{"id":21377488,"uuid":"24694897","full_name":"yanickrochon/number-scale","owner":"yanickrochon","description":"Convert numbers according to a given scale.","archived":false,"fork":false,"pushed_at":"2014-10-03T14:44:31.000Z","size":176,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-24T04:41:06.107Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/yanickrochon.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}},"created_at":"2014-10-01T20:49:17.000Z","updated_at":"2016-02-23T00:32:57.000Z","dependencies_parsed_at":"2022-07-30T04:07:49.396Z","dependency_job_id":null,"html_url":"https://github.com/yanickrochon/number-scale","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yanickrochon/number-scale","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fnumber-scale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fnumber-scale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fnumber-scale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fnumber-scale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanickrochon","download_url":"https://codeload.github.com/yanickrochon/number-scale/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fnumber-scale/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32445578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T20:22:27.477Z","status":"ssl_error","status_checked_at":"2026-04-29T20:22:26.507Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":"2024-10-01T18:12:03.863Z","updated_at":"2026-04-29T22:04:18.668Z","avatar_url":"https://github.com/yanickrochon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# number-scale\n\nConvert numbers according to a given scale.\n\n\n# Avant propos\n\nThis module is heavily inspired from [human-format](https://github.com/julien-f/human-format). While there are still a strong base from that module, the API and behaviour is substantially different in `number-scale`.\n\n\n## Installation\n\n```\nnpm install number-scale --save\n```\n\n## Usage\n\n```javascript\nvar numberScale = require('number-scale');\n\nvar n = 123456.789;\n\nconsole.log(numberScale(n));\n// \"123.46K\"\n\nconsole.log(numberScale(n, { \n  scale: 'time',\n  roundMode: 'even',\n  recursive: 3\n}));\n// [ '1d', '10h', '17m', '36.79s' ]\n```\n\n\n## API\n\n### numberScale(n:Number[, options:Object]) : String|Array\n\nA function receiving a number, and optionally some options, and return the scale (aka human readable) representation as a string.\n\n* **n**:*Number* - any numeric value. If the argument is not a valid number, `NaN` is returned.\n* **options**:*Object* - the formatting options\n  * **precision**:*Number* - a numeric value indicating the number of decimal digits to round to. *(Defaults to `2`)*\n  * **roundMode**:*String* - the rounding method to use. May be one of the following : `\"up\"` always round up, `\"down\"` always round down, `\"even\"` round to nearest even value, `\"odd\"` round to nearest odd value. *(Defaults to `\"up\"`)*\n  * **scale**:*String* - the scale to use (see [predefined scales](#predefined-scales), or [custom scales](#custom-scales).) *(Defaults to `\"SI\"`)*\n  * **unit**:*String* - the scale unit suffix *(Defaults to `\"\"`)*\n  * **recursive**:*Number* - instead of returning a string, return an array of length `recursive + 1` elements.\n\n**NOTE** : default options can be overridden by modifying `numberScale.options.default`.\n\n\n#### Predefined Options\n\nFor convenience, these predefined options are specified\n\n* **numberScale.options.default**:*Object* - predefined default options\n\n\n### numberScale.scales : Object\n\nThis is where the known scales are defined.\n\n#### Known Scales\n\n* **SI** - the [International System of Units](https://en.wikipedia.org/wiki/International_System_of_Units)\n* **time** - the time scale (i.e. day, hour, minute, second, milliseconds, microseconds, nanoseconds)\n* **IEEE1541** - is a powers of 2 scale for bytes measurements similar to the **SI** scale.\n\n\n### numberScale.defineScale(name:String, scale:Object, baseUnitValue:Number)\n\nIt is possible to define a new scale, or even override a current one, by calling `numberScale.defineScale(name, scale, base)` where `scale` is an `Object` defining the scale's properties. Take a look at the [known scale definitions](lib/number-scale.js#L46-L94) for more information.\n\n\n#### Custom Scales\n\nCustom scales are accessible just like any other scales, through the `numberScale.scales` object.\n\n\n### numberScale.parse(value:String|Array[, options:Object]) : Number\n\nThis is the inverse of `numberScale(value, options)`. The function returns `NaN` is the given value cannot be parsed.\n\n\n## Contribution\n\nAll contributions welcome! Every PR **must** be accompanied by their associated\nunit tests!\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Mind2Soft \u003cyanick.rochon@mind2soft.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanickrochon%2Fnumber-scale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanickrochon%2Fnumber-scale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanickrochon%2Fnumber-scale/lists"}