{"id":41268,"library":"human-unit","title":"human-unit","description":"A flexible unit formatter for human-readable file size, time, and custom units. Current stable version 2.0.1, shipped as ESM with TypeScript types. Differentiates by allowing per-unit factors and ceils for precise control over unit bumping, using mixed SI/IEC standards for file sizes. Suitable for formatting bytes, durations, or any custom unit system.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/futurist/human-unit","tags":["javascript","unit","converter","formatter","human","size","file","typescript"],"install":[{"cmd":"npm install human-unit","lang":"bash","label":"npm"},{"cmd":"yarn add human-unit","lang":"bash","label":"yarn"},{"cmd":"pnpm add human-unit","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export; ESM-only since v2, no CommonJS support.","wrong":"const humanUnit = require('human-unit')","symbol":"humanUnit","correct":"import humanUnit from 'human-unit'"},{"note":"Named export for the built-in file size preset.","wrong":"import sizePreset from 'human-unit'","symbol":"sizePreset","correct":"import { sizePreset } from 'human-unit'"},{"note":"If using CommonJS, you must access .default; but ESM is preferred.","wrong":"const humanUnit = require('human-unit')","symbol":"humanUnit (CommonJS stub)","correct":"const humanUnit = require('human-unit').default"}],"quickstart":{"code":"import humanUnit, { sizePreset } from 'human-unit';\n\n// Format file size\nconst result1 = humanUnit(1024, sizePreset);\nconsole.log(result1); // { value: 1, unit: 'KB' }\n\n// Custom unit preset for time\nconst timePreset = {\n  factors: [1000, 60, 60, 24],\n  units: ['mili', 'sec', 'min', 'hour', 'day']\n};\nconst result2 = humanUnit(18000000, timePreset);\nconsole.log(result2); // { value: 5, unit: 'hour' }\n\n// Override unit target\nconst result3 = humanUnit(1024 * 1024, { ...sizePreset, unit: 'MB' });\nconsole.log(result3); // { value: 1, unit: 'GB' }","lang":"typescript","description":"Demonstrates default size formatting and custom time units with the humanUnit function."},"warnings":[{"fix":"Use import syntax or switch to dynamic import().","message":"v2.0 switched to ESM-only; CommonJS require() no longer works as expected.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use `import humanUnit from 'human-unit'` and `import { sizePreset } from 'human-unit'`.","message":"Default export is the humanUnit function; named exports (like sizePreset) changed paths.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure factors array has at least (units.length - 1) elements when using array form.","message":"Factors array length must match or exceed number of unit transitions. Mismatch may cause unexpected results.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the `unit` option is one of the predefined units in the preset.","message":"When using `unit` option, the value will be converted to that base unit before formatting; may produce unexpected if unit is not in the units list.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.0.1':21 'allow':30 'bump':42 'byte':53 'ceil':36 'control':39 'convert':62 'current':18 'custom':16,57 'differenti':28 'durat':54 'esm':24 'factor':34 'file':12,48,66 'flexibl':5 'format':52 'formatt':7,63 'human':2,10,64 'human-read':9 'human-unit':1 'javascript':60 'mix':44 'per':32 'per-unit':31 'precis':38 'readabl':11 'ship':22 'si/iec':45 'size':13,49,65 'stabl':19 'standard':46 'suitabl':50 'system':59 'time':14 'type':27 'typescript':26,67 'unit':3,6,17,33,41,58,61 'use':43 'version':20","created_at":"2026-06-04T18:51:35.408304+00:00","updated_at":"2026-06-04T18:51:35.408304+00:00","problems":[{"fix":"Use `import humanUnit from 'human-unit'` or `const humanUnit = require('human-unit').default`.","cause":"Using CommonJS require creates an object with a default property; the default export isn't accessed.","error":"TypeError: humanUnit is not a function"},{"fix":"Use import syntax or set `type: 'module'` in package.json.","cause":"human-unit v2 is ESM-only; require() is not supported.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/futurist/human-unit#readme","github":"https://github.com/futurist/human-unit","docs":null,"changelog":null,"pypi":null,"npm":"human-unit","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}