{"id":10892,"library":"filesize","title":"Filesize Utility","description":"The `filesize` library is a lightweight, high-performance JavaScript utility designed to convert byte values into human-readable strings, such as \"1.02 kB\" or \"1 MiB\". Currently at version 11.0.15, it emphasizes reliability and efficiency with zero external dependencies and 100% test coverage. Key differentiators include full TypeScript support, robust internationalization via the `Intl` API, `BigInt` compatibility for extremely large numbers, and support for multiple unit standards (SI, IEC, JEDEC). It offers a functional API with partial application for creating reusable formatters and is fully compatible with both Node.js and browser environments. While a specific release cadence isn't published, the project appears actively maintained with regular updates.","status":"active","version":"11.0.15","language":"javascript","source_language":"en","source_url":"git://github.com/avoidwork/filesize.js","tags":["javascript","file","filesize","size","readable","file system","bytes","diff","typescript"],"install":[{"cmd":"npm install filesize","lang":"bash","label":"npm"},{"cmd":"yarn add filesize","lang":"bash","label":"yarn"},{"cmd":"pnpm add filesize","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v10.0.0, both ESM and CommonJS imports require named destructuring. The `import filesize from 'filesize'` syntax is incorrect for ESM, and `const filesize = require('filesize');` is incorrect for CJS.","wrong":"import filesize from 'filesize';","symbol":"filesize","correct":"import { filesize } from 'filesize';"},{"note":"Similar to `filesize`, `partial` is a named export. Ensure named destructuring for both ESM and CommonJS after v10.0.0.","wrong":"const partial = require('filesize');","symbol":"partial","correct":"import { partial } from 'filesize';"},{"note":"Import types separately using `import type` for explicit type annotations in TypeScript environments.","symbol":"FileSizeOptions","correct":"import type { FileSizeOptions } from 'filesize';"}],"quickstart":{"code":"import { filesize, partial } from 'filesize';\n\n// Convert bytes to a human-readable string using default (SI) standard\nconst sizeInBytes = 265318;\nconsole.log(`Default SI format: ${filesize(sizeInBytes)}`); // \"265.32 kB\"\n\n// Use IEC standard with base 2 for binary sizes\nconst binarySize = 1048576; // 1 MiB\nconsole.log(`IEC binary format: ${filesize(binarySize, { standard: 'iec', base: 2 })}`); // \"1 MiB\"\n\n// Create a partially applied formatter for consistent styling\nconst formatBinaryIEC = partial({ standard: 'iec', base: 2, round: 0, spacer: '' });\nconsole.log(`Formatted with partial application: ${formatBinaryIEC(binarySize)}`); // \"1MiB\"\n\n// Output as an object for programmatic access\nconst sizeObject = filesize(1536, { output: 'object' });\nconsole.log(`Output as object: ${JSON.stringify(sizeObject)}`); // {\"value\":1.54,\"symbol\":\"kB\",\"exponent\":1,\"unit\":\"kB\"}","lang":"typescript","description":"Demonstrates basic filesize conversion, using different standards (SI, IEC), partial application for reusable formatters, and various output formats including string and object."},"warnings":[{"fix":"Adjust CommonJS `require` statements to use named destructuring: `const { filesize, partial } = require('filesize');`","message":"Since v10.0.0, the CommonJS export is no longer a default export and requires named destructuring, e.g., `const { filesize } = require('filesize');`. Older versions allowed `const filesize = require('filesize');`.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Upgrade Node.js to version 16 or higher, or pin the `filesize` package to a version less than 10.0.0.","message":"Version 10.0.0 dropped support for Node.js 12 and 14. Users on these Node.js versions should remain on `filesize` < v10 or upgrade their Node.js environment.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Explicitly set the `standard` option if non-SI behavior is desired (e.g., `{ standard: 'iec', base: 2 }`). If relying on the 'suffix' option, refactor your code as it is no longer available.","message":"Version 9.0.0 changed the default standard to SI (base 10) from previous defaults, and removed the 'suffix' option. It also dropped support for Node.js 10 and 12.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Always specify `{ standard: 'iec', base: 2 }` together for accurate binary IEC units.","message":"When using `standard: \"iec\"`, it is crucial to also set `base: 2` to ensure correct binary (1024-based) calculations and symbols (KiB, MiB). Otherwise, `standard: \"iec\"` with `base: -1` (auto, often 10) might produce unexpected results or use SI (decimal) calculations with IEC symbols.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For ESM, use `import { filesize } from 'filesize';`. For CommonJS (since v10), use `const { filesize } = require('filesize');`.","cause":"Incorrect CommonJS `require` or mixed ESM/CJS environment trying to access a default export that no longer exists.","error":"TypeError: filesize is not a function"},{"fix":"Ensure that `filesize` is explicitly imported as a named export. In CommonJS, this means `const { filesize } = require('filesize');`.","cause":"Attempting to destructure a CommonJS `require` statement where the package was imported as a default, or the default export was expected.","error":"TypeError: Cannot read properties of undefined (reading 'filesize')"},{"fix":"Ensure the input to `filesize` is a valid `number` or `bigint`.","cause":"Passing an invalid or non-numeric value (e.g., `null`, `undefined`, a string that cannot be parsed) to the `filesize` function.","error":"TypeError: filesize called on non-object"}],"ecosystem":"npm"}