{"_id":"all-units","_rev":"2-fa682a48cd83d6149c23bd237df99f1f","name":"all-units","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.1":{"name":"all-units","version":"1.0.1","keywords":["unit","convert","converter","units","measurement","length","mass","temperature","pressure","energy"],"author":{"name":"MaxGrushevsky"},"license":"MIT","_id":"all-units@1.0.1","maintainers":[{"name":"maxgrushevsky","email":"m.grushevsky10@gmail.com"}],"homepage":"https://github.com/MaxGrushevsky/unit-convert#readme","bugs":{"url":"https://github.com/MaxGrushevsky/unit-convert/issues"},"dist":{"shasum":"2e9f94eb270656c5d571b21924802ef347b71aa6","tarball":"https://registry.npmjs.org/all-units/-/all-units-1.0.1.tgz","fileCount":9,"integrity":"sha512-4hEFm2gxpRCua/3ItA6CznoZdvxill5AKWBi1287tuR1gm7NXPbITJj37ZOB432PNSQZps733wBmvLGgiLeLYA==","signatures":[{"sig":"MEYCIQCskghPpvAKJesZZY6DPUihwiBGcrxnJMZw3pGycJviIwIhANSAVbvphGXN6Ld5lwy1es4Orqd68BZ9oYBwMXNUiYzn","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":76786},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"gitHead":"1d2065931b5fd4b4f147e6a6be39b048740ba275","scripts":{"test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build && npm test"},"_npmUser":{"name":"maxgrushevsky","email":"m.grushevsky10@gmail.com"},"repository":{"url":"git+https://github.com/MaxGrushevsky/unit-convert.git","type":"git"},"_npmVersion":"10.9.3","description":"Universal unit converter — 13 categories, 100+ units. Zero dependencies. TypeScript-first.","directories":{},"sideEffects":false,"_nodeVersion":"22.19.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","vitest":"^2.0.0","typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/all-units_1.0.1_1772572095777_0.14215132272699615","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"all-units","version":"1.0.3","description":"Universal unit converter — 13 categories, 100+ units. Zero dependencies. TypeScript-first.","keywords":["unit","convert","converter","units","measurement","length","mass","temperature","pressure","energy"],"author":{"name":"MaxGrushevsky"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/MaxGrushevsky/all-units.git"},"homepage":"https://github.com/MaxGrushevsky/all-units#readme","bugs":{"url":"https://github.com/MaxGrushevsky/all-units/issues"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","unpkg":"./dist/index.global.js","jsdelivr":"./dist/index.global.js","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"sideEffects":false,"scripts":{"build":"tsup","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","typecheck":"tsc --noEmit","prepublishOnly":"npm run build && npm test"},"devDependencies":{"tsup":"^8.0.0","typescript":"^5.0.0","vitest":"^2.0.0"},"_id":"all-units@1.0.3","gitHead":"45fc8f338bb67935d7686babde9cdbe7bbedd980","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-rJ26qpSlfuLctyOEqtRTrSiVxXvS5UYkYgnTXjT0NbUui4AkN1Cg9dC8OaY+vQcdIpGwvRk+Nt7NkOyaRx+t/A==","shasum":"4a1cc990399cc13a6a43e0b5f394e494428e3089","tarball":"https://registry.npmjs.org/all-units/-/all-units-1.0.3.tgz","fileCount":8,"unpackedSize":23969,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD+67XACRXzusRvpOR6zIgA7lIlIiIIfLIGqjIk6RCTtwIgdAVIShEEjmJeWqmUbtpe/tGaqTOI52fQk7tr/Idmkhc="}]},"_npmUser":{"name":"maxgrushevsky","email":"m.grushevsky10@gmail.com"},"directories":{},"maintainers":[{"name":"maxgrushevsky","email":"m.grushevsky10@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/all-units_1.0.3_1772626374265_0.36228889345265114"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-03T21:08:15.776Z","modified":"2026-03-04T12:12:54.551Z","1.0.1":"2026-03-03T21:08:15.920Z","1.0.3":"2026-03-04T12:12:54.436Z"},"bugs":{"url":"https://github.com/MaxGrushevsky/all-units/issues"},"author":{"name":"MaxGrushevsky"},"license":"MIT","homepage":"https://github.com/MaxGrushevsky/all-units#readme","keywords":["unit","convert","converter","units","measurement","length","mass","temperature","pressure","energy"],"repository":{"type":"git","url":"git+https://github.com/MaxGrushevsky/all-units.git"},"description":"Universal unit converter — 13 categories, 100+ units. Zero dependencies. TypeScript-first.","maintainers":[{"name":"maxgrushevsky","email":"m.grushevsky10@gmail.com"}],"readme":"# all-units\n\n> Universal unit converter — 13 categories, 100+ units. Zero dependencies. TypeScript-first.\n\n[![npm](https://img.shields.io/npm/v/all-units)](https://www.npmjs.com/package/all-units)\n[![license](https://img.shields.io/npm/l/all-units)](./LICENSE)\n[![build](https://img.shields.io/github/actions/workflow/status/MaxGrushevsky/all-units/ci.yml)](https://github.com/MaxGrushevsky/all-units/actions)\n\n## Features\n\n- **13 categories**: length, mass, temperature, area, volume, time, speed, pressure, energy, power, digital storage, angle, frequency\n- **100+ units** with precise conversion factors\n- **Fluent API**: `convert(100).from('cm').to('m')` — readable and chainable\n- **Direct API**: `convert(100, 'cm', 'm')` — compact one-liner\n- Full **TypeScript types** with IDE autocomplete for all unit names\n- Throws a clear error when units are incompatible (different categories)\n- **Zero runtime dependencies**\n- Works in Node.js, Deno, Bun, and modern browsers\n- ESM + CommonJS dual build\n\n## Install\n\n```bash\nnpm install all-units\n# or\npnpm add all-units\n# or\nyarn add all-units\n```\n\n## Usage\n\n```ts\nimport { convert } from 'all-units'\n\n// Fluent API (recommended)\nconvert(100).from('cm').to('m')          // 1\nconvert(1).from('km').to('mi')           // 0.621371\nconvert(0).from('C').to('F')             // 32\nconvert(100).from('C').to('F')           // 212\nconvert(1).from('kg').to('lb')           // 2.204623\nconvert(1).from('kWh').to('J')           // 3600000\nconvert(1).from('GB').to('MB')           // 1000   (SI)\nconvert(1).from('GiB').to('MiB')         // 1024   (IEC)\nconvert(180).from('deg').to('rad')       // 3.14159 (π)\nconvert(1).from('atm').to('bar')         // 1.01325\n\n// Direct API\nconvert(1000, 'm', 'km')                 // 1\nconvert(32, 'F', 'C')                    // 0\n```\n\nCommonJS (require) is also supported:\n\n```js\nconst { convert } = require('all-units')\n\nconvert(1, 'mi', 'km')  // 1.609344\n```\n\n## API\n\n### `convert(value, from, to)`\n\n**Direct style** — pass value, source unit and target unit in one call.\n\n```ts\nconvert(value: number, from: Unit, to: Unit): number\n```\n\n### `convert(value).from(unit).to(unit)`\n\n**Fluent style** — build the conversion step by step.\n\n```ts\nconvert(value: number): FromStep\n// .from(unit).to(unit) → number\n```\n\nBoth styles throw `Error` if:\n- A unit string is unknown\n- The two units belong to different categories (e.g. `'cm'` → `'kg'`)\n\n### `canConvert(from, to)`\n\nReturns `true` if the two units are in the same category.\n\n```ts\ncanConvert('cm', 'm')    // true\ncanConvert('cm', 'kg')   // false\ncanConvert('xyz', 'm')   // false\n```\n\n### `getCategory(unit)`\n\nReturns the category name of a unit, or `undefined` if unknown.\n\n```ts\ngetCategory('km')    // 'length'\ngetCategory('C')     // 'temperature'\ngetCategory('GiB')   // 'digital'\n```\n\n### `possibilities(unit)`\n\nReturns all units that are compatible with the given unit (same category). Useful for populating UI dropdowns.\n\n```ts\npossibilities('km')  // ['um', 'mm', 'cm', 'm', 'km', 'in', 'ft', 'yd', 'mi', 'nmi']\npossibilities('C')   // ['C', 'F', 'K', 'R']\npossibilities('GB')  // ['bit', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']\n```\n\n### `listUnits()`\n\nReturns all units grouped by category, or just the list for one category.\n\n```ts\nlistUnits()            // { length: ['mm', 'cm', 'm', ...], temperature: [...], ... }\nlistUnits('length')    // ['um', 'mm', 'cm', 'm', 'km', 'in', 'ft', 'yd', 'mi', 'nmi']\n```\n\n## Supported units\n\n### Length\n| Unit | Name |\n|---|---|\n| `um` | Micrometre |\n| `mm` | Millimetre |\n| `cm` | Centimetre |\n| `m` | Metre |\n| `km` | Kilometre |\n| `in` | Inch |\n| `ft` | Foot |\n| `yd` | Yard |\n| `mi` | Mile |\n| `nmi` | Nautical mile |\n\n### Mass\n| Unit | Name |\n|---|---|\n| `mg` | Milligram |\n| `g` | Gram |\n| `kg` | Kilogram |\n| `t` | Metric ton |\n| `oz` | Ounce |\n| `lb` | Pound |\n| `st` | Stone |\n\n### Temperature\n| Unit | Name |\n|---|---|\n| `C` | Celsius |\n| `F` | Fahrenheit |\n| `K` | Kelvin |\n| `R` | Rankine |\n\n### Area\n`mm2` `cm2` `m2` `km2` `in2` `ft2` `yd2` `mi2` `ha` (hectare) `ac` (acre)\n\n### Volume\n`ml` `cl` `dl` `l` `m3` `tsp` `tbsp` `fl_oz` `cup` `pt` `qt` `gal` (US) `uk_gal` (UK)\n\n### Time\n`ms` `s` `min` `h` `d` `wk` `mo` `yr`\n\n### Speed\n`m/s` `km/h` `mph` `knot` `ft/s`\n\n### Pressure\n`Pa` `kPa` `MPa` `bar` `atm` `psi` `mmHg` `inHg`\n\n### Energy\n`J` `kJ` `cal` `kcal` `Wh` `kWh` `BTU` `eV`\n\n### Power\n`W` `kW` `MW` `GW` `hp`\n\n### Digital storage\n| Unit | Standard | Size |\n|---|---|---|\n| `bit` | — | 1 bit |\n| `B` | — | 1 byte |\n| `KB` `MB` `GB` `TB` `PB` | SI (powers of 10) | 10³ … 10¹⁵ bytes |\n| `KiB` `MiB` `GiB` `TiB` `PiB` | IEC (powers of 2) | 2¹⁰ … 2⁵⁰ bytes |\n\n### Angle\n`deg` (degree) `rad` (radian) `grad` (gradian)\n\n### Frequency\n`Hz` `kHz` `MHz` `GHz`\n\n## Development\n\n```bash\ngit clone https://github.com/MaxGrushevsky/unit-convert.git\ncd unit-convert\nnpm install\n\nnpm run build         # compile to dist/\nnpm test              # run tests once\nnpm run test:watch    # run tests in watch mode\nnpm run typecheck     # TypeScript type-check only\n```\n\n## License\n\n[MIT](./LICENSE)\n","readmeFilename":"README.md"}