{"id":20473,"library":"prettysize","title":"prettysize","description":"A lightweight utility to convert byte counts into human-readable strings (e.g., 1024 → \"1 kB\") for logging and CLI output. Version 2.0.0 supports sizes from bytes up to exabytes, with options to remove spaces, use single-character suffixes, control decimal places, or return only the numeric value. Minimal dependencies, pure JavaScript, works in Node.js and browsers. Alternatives like filesize.js offer more formatting features, but prettysize focuses on simplicity and small footprint.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/davglass/prettysize","tags":["javascript","size","bytes","MB","megs"],"install":[{"cmd":"npm install prettysize","lang":"bash","label":"npm"},{"cmd":"yarn add prettysize","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettysize","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"prettysize uses CommonJS; default export is the function. ESM import is not supported natively; use a bundler or wrapper.","wrong":"import pretty from 'prettysize'","symbol":"prettysize","correct":"const pretty = require('prettysize')"},{"note":"If using a bundler (e.g., webpack) with esModuleInterop, default import works. For Node.js ESM, use createRequire or dynamic import.","wrong":null,"symbol":"prettysize","correct":"import pretty from 'prettysize'"},{"note":"The module exports a single function, not an object. Destructuring will result in undefined.","wrong":"const { pretty } = require('prettysize')","symbol":"prettysize","correct":"const pretty = require('prettysize')"}],"quickstart":{"code":"const pretty = require('prettysize');\n\n// Basic usage\nconsole.log(pretty(1024));           // \"1 kB\"\nconsole.log(pretty(1048576));        // \"1 MB\"\n\n// Options: remove space, single character, decimal places\nconsole.log(pretty(123456789, { nospace: true }));         // \"117.7M\"\nconsole.log(pretty(123456789, { one: true, places: 2 }));  // \"117.74 M\"\nconsole.log(pretty(123456789, { numOnly: true }));         // 117.7","lang":"javascript","description":"Demonstrates basic usage with a byte value, shows options for no space, single character suffix, decimal places, and numeric-only output."},"warnings":[{"fix":"Update code to expect one decimal place by default, or explicitly set places option.","message":"Version 2.0.0 changed the default decimal places from 0 to 1.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use options object: { nospace: true, one: true, places: 2 } instead of positional args.","message":"Positional arguments (true, true, 2) are deprecated in favor of options object.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use { nospace: true } to remove space, or { numOnly: true } to get a number directly.","message":"The function returns a string with a space by default (e.g., '1 kB'), which may not match expectations for pure numeric output.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `const pretty = require('prettysize');` not `const { pretty } = require('prettysize');`","cause":"CommonJS require returns a module object; destructuring incorrectly.","error":"TypeError: pretty is not a function"},{"fix":"Use `import pretty from 'prettysize'` (with bundler) or `createRequire` from 'module'.","cause":"Trying to require the package in a strict ESM context without proper handling.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}