{"id":19566345,"url":"https://github.com/surpri6e/bytes-transform","last_synced_at":"2025-04-27T02:31:20.885Z","repository":{"id":221667350,"uuid":"754271485","full_name":"surpri6e/bytes-transform","owner":"surpri6e","description":"Package to transform your bytes","archived":false,"fork":false,"pushed_at":"2024-04-06T16:52:59.000Z","size":91,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T14:04:39.291Z","etag":null,"topics":["bytes","bytesize","format","formatting","npm","npm-package","size-calculation","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/bytes-transform","language":"TypeScript","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/surpri6e.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-02-07T18:20:08.000Z","updated_at":"2024-06-24T05:49:50.000Z","dependencies_parsed_at":"2024-02-09T11:51:47.510Z","dependency_job_id":"db88b957-a2b2-4846-a045-7fd10328faa3","html_url":"https://github.com/surpri6e/bytes-transform","commit_stats":null,"previous_names":["surpri6e/bytes-transformer","surpri6e/bytes-transform"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpri6e%2Fbytes-transform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpri6e%2Fbytes-transform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpri6e%2Fbytes-transform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpri6e%2Fbytes-transform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surpri6e","download_url":"https://codeload.github.com/surpri6e/bytes-transform/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250983796,"owners_count":21518023,"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":["bytes","bytesize","format","formatting","npm","npm-package","size-calculation","typescript"],"created_at":"2024-11-11T05:31:17.933Z","updated_at":"2025-04-27T02:31:20.593Z","avatar_url":"https://github.com/surpri6e.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/bytes-transform.svg?style=flat-square)](https://www.npmjs.org/package/bytes-transform)\n[![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=bytes-transform\u0026query=$.install.pretty\u0026label=install%20size\u0026style=flat-square)](https://packagephobia.now.sh/result?p=bytes-transform)\n[![npm downloads](https://img.shields.io/npm/dy/bytes-transform.svg?style=flat-square)](https://npm-stat.com/charts.html?package=bytes-transform)\n\n# Bytes transform\n\n## Getting started\n\n```\nnpm i bytes-transform\n```\n\n### ECMAScript\n\nAfter that, we can use:\n\n```js\nimport { formatBytes } from 'bytes-transform';\n\nconst newFormat = formatBytes(1024, { from: 'MB', to: 'GB' });\nconsole.log(newFormat.amount, newFormat.prefix);\n```\n\nSince the object is returned we can use this syntax:\n\n```js\nformatBytes(1024, { from: 'MB', to: 'GB' }).amount; // 1\nformatBytes(1024, { from: 'MB', to: 'GB' }).prefix; // 'GB'\n```\n\nIf you need you can convert everything to bytes:\n\n```js\nimport { formatBytesToBytes } from 'bytes-transform';\n\nformatBytesToBytes(1024, 'MB')) // return -\u003e 1073741824 bytes\nformatBytesToBytes(4, 'MB')) // return -\u003e 4194304 bytes\n```\n\n### CommonJs\n\nAll that you can use with CommonJs:\n\n```js\nconst { formatBytes, formatBytesToBytes } = require('bytes-transform');\n\n...\n```\n\n## All structures\n\n### formatBytesToBytes\n\n```ts\ntype TFormatBytesToBytesSignature = (amount: number, from: TListOfPrefix, capacityStrength: TCapacityStrength) =\u003e number;\n\n/**\nTransfer your bytes with prefix to standart bytes.\n@param {number} amount count of bytes with prefix\n@param {TListOfPrefix} from prefix\n@param {TCapacityStrength} capacityStrength capacity strength\n\n@returns {number} number of standart bytes\n*/\nexport const formatBytesToBytes: TFormatBytesToBytesSignature = (amount, from, capacityStrength = 1024) =\u003e {...};\n```\n\n### formatBytes\n\n```ts\ntype TFormatBytesSignature = (amount: number, options: IFormatBytesOptions) =\u003e IFormattedBytes;\n\n/**\n  Transfer your bytes in bytes with other prefix\n  @param {number} amount count of bytes with prefix\n  @param {IFormatBytesOptions} options settigns for other information\n\n  @returns {IFormatBytesReturned} object with amount and another prefix\n*/\nexport const formatBytes: TFormatBytesSignature = (amount, options) =\u003e {...}\n```\n\n### TListOfPrefix\n\n```ts\nexport type TListOfPrefix = 'B' | 'KB' | 'MB' | 'GB' | 'TB';\n```\n\n### TCapacityStrength\n\n```ts\nexport type TCapacityStrength = 1000 | 1024;\n```\n\n### TFixTo\n\n```ts\nexport type TFixTo = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;\n```\n\n### IFormatBytesOptions\n\n```ts\nexport interface IFormatBytesOptions {\n    readonly from: TListOfPrefix;\n    readonly to: TListOfPrefix;\n    readonly capacityStrength?: TCapacityStrength;\n    readonly fixTo?: TFixTo;\n}\n```\n\n### IFormattedBytes\n\n```ts\nexport interface IFormattedBytes {\n    readonly amount: number;\n    readonly prefix: TListOfPrefix;\n}\n```\n\nHappy hacking!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurpri6e%2Fbytes-transform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurpri6e%2Fbytes-transform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurpri6e%2Fbytes-transform/lists"}