# format

Human-readable number formatting utilities.

---

## `formatBytes(bytes, decimals?) → string`

Converts a raw byte count into a human-readable string using binary (IEC) prefixes (KiB, MiB, GiB, …).

### Parameters

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `bytes` | `number` | *(required)* | The byte count to format. |
| `decimals` | `number` | `2` | Number of decimal places in the output. Negative values are treated as `0`. |

### Returns

`string` — A formatted string such as `"1.46 KiB"` or `"0 Bytes"`.

### Example

```typescript
import { formatBytes } from '@yaoc1996/js-tools'

formatBytes(0)              // "0 Bytes"
formatBytes(512)            // "512 Bytes"
formatBytes(1024)           // "1 KiB"
formatBytes(1536, 1)        // "1.5 KiB"
formatBytes(1024 ** 2)      // "1 MiB"
formatBytes(1024 ** 3)      // "1 GiB"
formatBytes(1024 ** 8)      // "1 YiB"
formatBytes(1500, 0)        // "1 KiB"
```

### Notes

- Uses binary (base-1024) prefixes: **KiB**, **MiB**, **GiB**, **TiB**, **PiB**, **EiB**, **ZiB**, **YiB** (not KB/MB/GB).
- `NaN` is treated identically to `0` and returns `"0 Bytes"`.
- Throws for negative values or `Infinity`.
