Registry / productivity / prefix-si

prefix-si

JSON →
library1.2.0jsnpmunverified

A JavaScript library for formatting numbers with SI, IEC, and BS1852 prefixes. Supports binary (KiB/MiB), metric (k/M/G), and BS1852 (e.g., 4K7) styles. Current stable version 1.2.0. TypeScript types included. Lightweight with no dependencies. Comparable to filesize.js but with BS1852 support.

npm install prefix-si
INSTALL
IMPORT
SIG · PREFIX-SI
P
prefix-si
productivityjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prefix
import prefix from 'prefix-si'
const { prefix } = require('prefix-si')
Default export is the function itself; no named export 'prefix'.
default import
import prefix from 'prefix-si'
import { prefix } from 'prefix-si'
Only default export exists.
require
const prefix = require('prefix-si')
const { prefix } = require('prefix-si')
CommonJS require returns the function directly.

Showcases three formatting modes (metric, binary, BS1852) with the prefix function.

import prefix from 'prefix-si'; // Metric: 1200 g → 1.2 kg console.log(prefix(1200, 'g')); // Binary: 1048576 bytes → 1 MiB console.log(prefix(1048576, 'B', { binary: true })); // BS1852: 4700 Ω → 4K7 console.log(prefix(4700, 'R', { bs1852: true })); // Custom SI prefix example console.log(prefix(3.14e6, 'm', { si: true })); // 3.14 Mm
Debug
Known issues
gotchaDefault export is a function; do not destructure import.
fix
Use `import prefix from 'prefix-si'` instead of destructuring.
affects: >=1.0.0
breakingIn version 1.0.0, the library switched to ES module. CommonJS require still works but returns a different shape? (Check docs)
fix
Use `import` syntax or use `require('prefix-si').default` if using CJS.
affects: >=1.0.0 <2.0.0
deprecatedOptions `binary` and `si` flags may be deprecated in future versions. (Check docs)
fix
Use explicit prefix style option instead.
affects: >=1.0.0
gotchaBS1852 output uses uppercase letters (e.g., 'K' for kilo), not lowercase.
fix
When parsing BS1852 output, expect uppercase prefix letters.
affects: >=1.0.0
gotchaLarge numbers (>1e21) may produce unexpected results due to JavaScript number precision.
fix
Use a big number library for extremely large values.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , _prefixSi.default) is not a function
Using ES import with TypeScript but module resolution not set to ESM.
fix
Set `"module": "ESNext"` or use `const prefix = require('prefix-si')`.
prefix is not a function
Destructured import: `import { prefix } from 'prefix-si'`.
fix
Use `import prefix from 'prefix-si'`.
Cannot find module 'prefix-si'
Package not installed or misspelled.
fix
Run `npm install prefix-si` and check spelling.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
36 hits · last 30 days
node
30
OpenAI (training)
1
Resources
prefix-si — npm install prefix-si · libregistry