{"name":"filesize","version":"11.0.31","keywords":["file","filesize","size","readable","file system","bytes","diff"],"author":{"name":"Jason Mulligan","email":"jason.mulligan@avoidwork.com"},"license":"BSD-3-Clause","_id":"filesize@11.0.31","maintainers":[{"name":"avoidwork","email":"jason.mulligan@avoidwork.com"}],"homepage":"https://filesizejs.com","bugs":{"url":"https://github.com/avoidwork/filesize.js/issues"},"dist":{"shasum":"307b5feccf8cacf0e5e11b1b5c40ab94a8eb69f6","tarball":"http://registry-npm.ywwl.com/filesize/download/filesize-11.0.31.tgz","fileCount":6,"integrity":"sha512-czuWA5JoomIGnMe1thggiNNWIbMz7b9GNOL7gv75yn0Qxg9vjECW0zUXARFE+5WLraHh/m35++uumoi9h8nKWw==","signatures":[{"sig":"MEUCIQD0yo9vvvoxngnrMEM2D+ttibgbTnxOcWLGtU5VZlEstQIgYxBTx+YX5uxYPPWzI3/7fu/HXQE7g72OVneHxLIV7/E=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQCge2QRdiu2UZLhQpfaSajRqQS0dUX3MaqEJborCI3ArgIhAJRy3fgEHX/gUoJAqdGN5kQbO8nutwmR6z9EYvamrPfd","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":75126,"size":13857,"noattachment":false,"key":"/filesize/-/filesize-11.0.31.tgz"},"main":"dist/filesize.cjs","type":"module","types":"types/filesize.d.ts","module":"dist/filesize.js","source":"src/filesize.js","engines":{"node":">= 10.8.0"},"exports":{"types":"./types/filesize.d.ts","import":"./dist/filesize.js","require":"./dist/filesize.cjs"},"gitHead":"a01c4eb6f33245600849a1ac55bccba541a47542","scripts":{"dev":"npm run build:watch","fix":"npx oxlint --fix *.js benchmarks src tests && npx oxfmt *.js benchmarks src tests/unit --write","lint":"npx oxlint *.js benchmarks src tests && npx oxfmt *.js benchmarks src tests/unit --check","test":"npm run lint && node --test --experimental-test-coverage tests/**/*.js","build":"npm run rollup","rollup":"rollup --config","prepack":"npm run build","prepare":"husky","coverage":"node --test --experimental-test-coverage --test-coverage-exclude=dist/** --test-coverage-exclude=tests/** --test-reporter=spec tests/**/*.test.js 2>&1 | grep -A 1000 \"start of coverage report\" > coverage.txt","benchmark":"node benchmarks/index.js","changelog":"auto-changelog -p","test:watch":"node --test --watch tests/**/*.js","build:watch":"rollup --config --watch","analyze:size":"echo 'Bundle size analysis:' && du -h dist/* && echo 'Gzipped sizes:' && gzip -c dist/filesize.min.js | wc -c | awk '{print $1\" bytes (gzipped)\"}' && gzip -c dist/filesize.umd.min.js | wc -c | awk '{print $1\" bytes (umd gzipped)\"}'","benchmark:gc":"node --expose-gc benchmarks/index.js","build:analyze":"npm run rollup && npm run analyze:size","benchmark:basic":"node benchmarks/basic-performance.js","benchmark:stress":"node benchmarks/stress-test.js","benchmark:options":"node benchmarks/options-benchmark.js","benchmark:partial":"node benchmarks/partial-benchmark.js"},"_npmUser":{"name":"avoidwork","email":"jason.mulligan@avoidwork.com"},"repository":{"url":"git://github.com/avoidwork/filesize.js.git","type":"git"},"sourceType":"module","_npmVersion":"11.20.0","description":"Lightweight, zero-dependency JavaScript utility to convert bytes to human-readable strings with localization support","directories":{},"_nodeVersion":"26.13.0","_hasShrinkwrap":false,"devDependencies":{"husky":"^9.1.7","oxfmt":"^0.77.0","oxlint":"^1.87.0","rollup":"^4.64.1","auto-changelog":"^2.7.0","@rollup/plugin-terser":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/filesize_11.0.31_1794487127432_0.6699578754887486","host":"s3://npm-registry-packages-npm-production"},"readme":"# filesize\n[![npm version](https://badge.fury.io/js/filesize.svg)](https://www.npmjs.com/package/filesize)\n[![Node.js Version](https://img.shields.io/node/v/filesize.svg)](https://nodejs.org/)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n[![Build Status](https://github.com/avoidwork/filesize.js/actions/workflows/ci.yml/badge.svg)](https://github.com/avoidwork/filesize.js/actions)\n\nA lightweight, zero-dependency JavaScript utility that converts bytes to human-readable strings. Built for client and server applications that need to display file sizes — from download counters to disk-usage reports.\n\n## Why filesize?\n\n- **Zero dependencies** — no install weight, no supply-chain surface.\n- **100% test coverage** — every line, branch, and function is tested.\n- **TypeScript ready** — full type definitions for options and return types.\n- **Three unit standards** — SI, IEC, and JEDEC, each with its own symbols.\n- **Localization** — Intl-based formatting for any locale.\n- **BigInt support** — sizes beyond `Number.MAX_SAFE_INTEGER`.\n- **Functional API** — `partial()` creates reusable, immutable formatters.\n- **Client & server** — ships ESM, CJS, and UMD builds.\n\n## Installation\n\n```bash\nnpm install filesize\n```\n\n## Usage\n\n```javascript\nimport {filesize, partial} from \"filesize\";\n\nfilesize(1024); // \"1.02 kB\"\nfilesize(265318); // \"265.32 kB\"\nfilesize(1024, {standard: \"iec\"}); // \"1 KiB\"\nfilesize(1024, {bits: true}); // \"8.19 kbit\"\n```\n\n### Partial application\n\n`partial()` returns a pre-configured formatter with frozen options. Use it when you format many values with the same settings — it avoids re-parsing options on every call.\n\n```javascript\nimport {partial} from \"filesize\";\n\nconst formatBinary = partial({standard: \"iec\"});\nformatBinary(1024); // \"1 KiB\"\nformatBinary(1048576); // \"1 MiB\"\n```\n\n## Standards\n\nfilesize supports three unit standards. They differ in two ways: the base (1000 or 1024) and the unit symbols.\n\n| Standard | Base | Unit symbols | Example |\n|----------|------|--------------|---------|\n| SI | 1000 | kB, MB, GB | `filesize(1000)` → \"1 kB\" |\n| IEC | 1024 | KiB, MiB, GiB | `filesize(1024, {standard: \"iec\"})` → \"1 KiB\" |\n| JEDEC | 1024 | KB, MB, GB | `filesize(1024, {standard: \"jedec\"})` → \"1 KB\" |\n\nWhen you set `standard`, the base is implied and `base` is ignored. `base` is only consulted when `standard` is not set.\n\n## Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `bits` | boolean | `false` | Calculate bits instead of bytes |\n| `base` | number | `-1` | Number base (2 for binary, 10 for decimal, -1 for auto). Ignored when `standard` is set |\n| `round` | number | `2` | Decimal places to round to |\n| `precision` | number | `0` | Significant digits (0 for auto). When set, overrides `round` |\n| `pad` | boolean | `false` | Pad decimal places to match `round` |\n| `locale` | string\\|boolean | `\"\"` | Locale for formatting; `true` for the system locale |\n| `localeOptions` | Object | `{}` | Additional locale options |\n| `separator` | string | `\"\"` | Custom decimal separator |\n| `spacer` | string | `\" \"` | Value-unit separator |\n| `symbols` | Object | `{}` | Custom unit symbols |\n| `standard` | string | `\"\"` | Unit standard (`si`, `iec`, `jedec`) |\n| `output` | string | `\"string\"` | Output format (`string`, `array`, `object`, `exponent`) |\n| `fullform` | boolean | `false` | Use full unit names |\n| `fullforms` | Array | `[]` | Custom full unit names |\n| `exponent` | number | `-1` | Force a specific exponent (-1 for auto) |\n| `roundingMethod` | string | `\"round\"` | Math method (`round`, `floor`, `ceil`) |\n\n`round` controls decimal places; `precision` controls significant digits. When `precision` is greater than 0, it takes precedence over `round`.\n\n## Output formats\n\n```javascript\n// String (default)\nfilesize(1536); // \"1.54 kB\"\n\n// Array: [value, symbol]\nfilesize(1536, {output: \"array\"}); // [1.54, \"kB\"]\n\n// Object: {value, symbol, exponent, unit}\nfilesize(1536, {output: \"object\"});\n// {value: 1.54, symbol: \"kB\", exponent: 1, unit: \"kB\"}\n\n// Exponent: the unit index\nfilesize(1536, {output: \"exponent\"}); // 1\n```\n\n## Examples\n\n```javascript\n// Bits\nfilesize(1024, {bits: true}); // \"8.19 kbit\"\nfilesize(1024, {bits: true, base: 2}); // \"8 Kibit\"\n\n// Full unit names\nfilesize(1024, {fullform: true}); // \"1.02 kilobytes\"\nfilesize(1024, {base: 2, fullform: true}); // \"1 kibibyte\"\n\n// Custom decimal separator\nfilesize(265318, {separator: \",\"}); // \"265,32 kB\"\n\n// Padding\nfilesize(1536, {round: 3, pad: true}); // \"1.536 kB\"\n\n// Significant digits\nfilesize(1536, {precision: 3}); // \"1.54 kB\"\n\n// Locale\nfilesize(265318, {locale: \"de\"}); // \"265,32 kB\"\n\n// Custom symbols\nfilesize(1, {symbols: {B: \"Б\"}}); // \"1 Б\"\n\n// BigInt\nfilesize(BigInt(1024)); // \"1.02 kB\"\nfilesize(1024n ** 6n, {standard: \"iec\"}); // \"1 EiB\" (above Number.MAX_SAFE_INTEGER)\n\n// Negative numbers\nfilesize(-1024); // \"-1.02 kB\"\n```\n\n## Error handling\n\n`filesize()` throws a `TypeError` for invalid input.\n\n```javascript\ntry {\n  filesize(\"invalid\");\n} catch (error) {\n  // TypeError: \"Invalid number\"\n}\n\ntry {\n  filesize(1024, {roundingMethod: \"invalid\"});\n} catch (error) {\n  // TypeError: \"Invalid rounding method\"\n}\n```\n\nInvalid input includes non-numeric values, `NaN`, `Infinity`, and BigInt values whose conversion to `Number` is non-finite (for example, `10n ** 309n`). BigInt values above `Number.MAX_SAFE_INTEGER` are supported.\n\n## TypeScript\n\nFully typed with definitions included:\n\n```typescript\nimport {filesize, partial} from \"filesize\";\n\nconst result: string = filesize(1024);\nconst formatted: {value: number; symbol: string; exponent: number; unit: string} = filesize(1024, {output: \"object\"});\n\nconst formatter: (arg: number | bigint) => string = partial({standard: \"iec\"});\n```\n\n## Testing\n\n```bash\nnpm test              # Run all tests (lint + node:test)\nnpm run test:watch    # Live test watching\n```\n\n**100% test coverage** with 273 tests:\n\n```\n--------------|---------|----------|---------|---------|-------------------\nFile          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n--------------|---------|----------|---------|---------|-------------------\nAll files     |     100 |      100 |     100 |     100 |                   \n constants.js |     100 |      100 |     100 |     100 |                   \n filesize.js  |     100 |      100 |     100 |     100 |                   \n helpers.js   |     100 |      100 |     100 |     100 |                   \n--------------|---------|----------|---------|---------|-------------------\n```\n\n## Development\n\n```bash\nnpm install         # Install dependencies\nnpm run dev         # Build distributions in watch mode\nnpm run build       # Build distributions\nnpm run lint        # Check code style\nnpm run fix         # Auto-fix linting issues\n```\n\n### Project structure\n\n```\nfilesize.js/\n├── src/\n│   ├── filesize.js      # Main implementation (310 lines)\n│   ├── helpers.js       # Helper functions (641 lines)\n│   └── constants.js     # Constants (82 lines)\n├── tests/\n│   └── unit/\n├── dist/                # Built distributions\n└── types/               # TypeScript definitions\n```\n\n## Performance\n\n- **Basic conversions**: ~16-27M ops/sec\n- **With options**: ~5-13M ops/sec\n- **Locale formatting**: ~91K ops/sec (use sparingly)\n\n**Optimization tips:**\n1. Cache `partial()` formatters for reuse\n2. Avoid locale formatting in performance-critical code\n3. Use `object` output for fastest structured data access\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guidelines](https://github.com/avoidwork/filesize.js/blob/master/CONTRIBUTING.md) for details.\n\n## Changelog\n\nSee [CHANGELOG.md](https://github.com/avoidwork/filesize.js/blob/master/CHANGELOG.md) for a history of changes.\n\n## License\n\nCopyright (c) 2026 Jason Mulligan  \nLicensed under the BSD-3 license.\n","publish_time":1794487127519,"_cnpm_publish_time":1794487127519,"dist-tags":{"latest":"11.0.32"}}