https://github.com/evinism/typed-si
https://github.com/evinism/typed-si
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/evinism/typed-si
- Owner: evinism
- Created: 2022-07-19T03:06:06.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-10T07:05:41.000Z (almost 4 years ago)
- Last Synced: 2025-08-20T00:30:20.517Z (11 months ago)
- Language: TypeScript
- Size: 101 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `typed-si`: Strongly typed physical units

[](https://www.npmjs.com/package/typed-si)
Installation via `npm i typed-si`
`typed-si` is a typescript library for working with si-based phyisical quantities and measures with strong type safety guarantees.
## Basic usage:
```ts
import {Quantity, feet, kilo, newtons, atmospheres} from 'typed-si';
const sqft = Quantity.of(50, feet.squared());
const force = Quantity.of(10, kilo(newtons));
console.log(`Atmospheres: ${force.over(sqft).in(atmospheres)}`)
```
## Rational by Default
All quantities in `typed-si` use rationals by default under the hood, leading to reasonable conversion with minimal loss of precision.
## Aliases, Aliases, Aliases
`typed-si` has a lot of aliases for things to improve readability. They behave identically and are often the same function instance.
```js
// Aliasing of singular and plurals
Quantity.of(1, mile).in(meters);
// Aliasing of unit and quantity division.
Quantity.of(60, miles.per(hour));
Quantity.of(60, miles.div(hour));
Quantity.of(60, miles.over(hour));
```