{"id":19889530,"url":"https://github.com/tsmx/human-readable","last_synced_at":"2025-05-02T17:33:39.757Z","repository":{"id":40697342,"uuid":"298362522","full_name":"tsmx/human-readable","owner":"tsmx","description":"Easily create human-readable strings from byte sizes, e.g. 17238 --\u003e 17.24 kB. Supports decimal (MB,GB,..) and binary (MiB, GiB,..) units as well as user-defined conversion from/to other sizes.","archived":false,"fork":false,"pushed_at":"2024-08-06T19:24:37.000Z","size":607,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-07T03:18:49.208Z","etag":null,"topics":["binary","bytes","conversion","decimal","filesize","human-readable","iec","pretty-print","si"],"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/tsmx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-09-24T18:26:53.000Z","updated_at":"2024-08-06T19:24:40.000Z","dependencies_parsed_at":"2023-01-30T02:00:40.617Z","dependency_job_id":"c6549dcd-31ab-4600-a64f-6628a27189c0","html_url":"https://github.com/tsmx/human-readable","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsmx%2Fhuman-readable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsmx%2Fhuman-readable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsmx%2Fhuman-readable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsmx%2Fhuman-readable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsmx","download_url":"https://codeload.github.com/tsmx/human-readable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223983097,"owners_count":17236080,"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":["binary","bytes","conversion","decimal","filesize","human-readable","iec","pretty-print","si"],"created_at":"2024-11-12T18:10:38.696Z","updated_at":"2024-11-12T18:10:39.783Z","avatar_url":"https://github.com/tsmx.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [**@tsmx/human-readable**](https://github.com/tsmx/human-readable)\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n![npm (scoped)](https://img.shields.io/npm/v/@tsmx/human-readable)\n![node-current (scoped)](https://img.shields.io/node/v/@tsmx/human-readable)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/tsmx/human-readable/git-build.yml?branch=master)](https://img.shields.io/github/actions/workflow/status/tsmx/human-readable/git-build.yml?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/tsmx/human-readable/badge.svg?branch=master)](https://coveralls.io/github/tsmx/human-readable?branch=master)\n\n\u003e Easily create human-readable strings from byte sizes, e.g. `17238` → `17.24 kB`. Supports decimal (MB,GB,..) and binary (MiB, GiB,..) units as well as user-defined conversion from/to other sizes.\n\nFor details about the differences of decimal (SI) and binary (IEC) units please refer to [Wikipedia](https://en.wikipedia.org/wiki/Byte).\n\nAlso check out the [full documentation](https://tsmx.net/human-readable/). Type declarations for seamless usage in TypeScript projects are included. If you need to use this package on the client-side in the browser using plain JavaScript, refer to [this article](https://tsmx.net/npm-packages-browser/).\n\n## Usage\n\n```js\nconst hr = require('@tsmx/human-readable');\n\nhr.fromBytes(17238);\n// '17.24 kB'\n\nhr.fromBytes(17238, { mode: 'IEC' });\n// '16.83 KiB'\n\nhr.fromBytes(17238, { numberOnly: true });\n// '17.24'\n\nhr.fromBytes(17238, { fixedPrecision: 1 });\n// '17.2 kB'\n\nhr.fromBytes(17238, { fullPrecision: true });\n// '17.238 kB'\n\nhr.fromTo(17, 'GBYTE', 'KBYTE');\n// '17000000 kB'\n\nhr.fromTo(17, 'GBYTE', 'KBYTE', { mode: 'IEC' });\n// '17825792 KiB'\n\nhr.availableSizes();\n// [ 'BYTE', 'KBYTE', 'MBYTE', 'GBYTE', 'TBYTE', 'PBYTE' ]\n```\n\n## API\n\n### fromBytes(bytes, options)\n\nAutomatically creates a human-readable string out of a given number of bytes. E.g. `71255` → `71.26 kB`\n\n#### bytes\n\nType: `Number`\n\nAmount of bytes.\n\n#### options\n\nType: `Object`\n\nOptional. \n\n##### mode\n\nType: `String`\nDefault: none (use decimal mode)\n\nCan be set to `IEC` to use binary conversion (factor 1.024) and units (KiB,MiB,...). If not set or to any other value, decimal conversion (factor 1.000) and units (kB, MB,...) are used. \n\n##### numberOnly\n\nType: `Boolean`\nDefault: `false`\n\nIf set to true, conversion only returns the number and omits the unit. Overrides `noWhitespace`.\n\n##### fixedPrecision\n\nType: `Number`\n\nIf set the returned number string is formatted to the given fixed decimal places. If not set, the default behaviour of the conversion is to use a dynamic number of decimal places from zero up to two.\n\n##### fullPrecision\n\nType: `Boolean`\nDefault: `false`\n\nIf set to true, the returned number value will be presented with full available decimal places. Overrides `fixedPrecision`.\n\n##### noWhitespace\n\nType: `Boolean`\nDefault: `false`\n\nIf set to true, the whitespace between the number and unit string is omitted. E.g. `10MB` instead of `10 MB`.\n\n### fromTo(value, fromSize, toSize, options)\n\nConverts a value from a given size unit to a human-readable string of the target size. E.g. converting Gigabytes to Megabytes.\n\n#### value\n\nType: `Number`\n\nThe value to be converted.\n\n#### fromSize\n\nType: `String`\n\nThe size `value` has. Must be one out of `availableSizes`.\n\n#### toSize\n\nType: `String`\n\nThe size `value` should be converted to. Must be one out of `availableSizes`.\n\n#### options\n\nType: `Object`\n\nSee options description under `fromBytes`.\n\n### availableSizes()\n\nReturns an array of strings of all available sizes.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsmx%2Fhuman-readable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsmx%2Fhuman-readable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsmx%2Fhuman-readable/lists"}