Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/dim-si/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ const picogram = gram.scaled(PICO);

See [prefixes.ts](./src/prefixes.ts) for all available SI prefixes.

## Type Annotations

Each unit module exports a dimension type (e.g., `Length`, `Velocity`). Wrap
these with `Quantity` to annotate function parameters and return types:

```typescript
import type { Quantity } from "@isentropic/dim-quantity";
import type { Length } from "@isentropic/dim-si/length";
import type { Time } from "@isentropic/dim-si/time";
import type { Velocity } from "@isentropic/dim-si/velocity";
import { divide } from "@isentropic/dim-si/ops";

function speed(
distance: Quantity<Length>,
duration: Quantity<Time>,
): Quantity<Velocity> {
return divide(distance, duration);
}
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it could live in the Quick Start rather than its own section — it's a natural next step after using built-in units.

## Compound Units

Create units like `km/h` by combining scale factors from existing units:

```typescript
import { kilometer } from "@isentropic/dim-si/length";
import { hour } from "@isentropic/dim-si/time";
import { meterPerSecond } from "@isentropic/dim-si/velocity";

const kilometerPerHour = meterPerSecond.scaled(kilometer.scale / hour.scale);
```

## Adding a New Unit

Units are organized one file per dimension. To add a new unit to an existing
Expand Down