Skip to content
Merged
Show file tree
Hide file tree
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
70 changes: 46 additions & 24 deletions packages/dim-si/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,52 @@ bun add @isentropic/dim-si

### Derived

| Quantity | Units |
| --------------------- | ------------------------------------------------------------------- |
| Area | `squareMeter`, `hectare` |
| Volume | `cubicMeter`, `liter`, `milliliter`, `microliter` |
| Velocity | `meterPerSecond` |
| Acceleration | `meterPerSecondSquared` |
| Force | `newton` |
| Pressure | `pascal`, `bar`, `millibar` |
| Energy | `joule`, `kilojoule`, `megajoule`, `kilowattHour` |
| Power | `watt`, `milliwatt`, `kilowatt`, `megawatt`, `gigawatt`, `terawatt` |
| Frequency | `hertz`, `kilohertz`, `megahertz`, `gigahertz`, `becquerel` |
| Voltage | `volt`, `millivolt`, `kilovolt` |
| Resistance | `ohm`, `milliohm`, `kilohm`, `megohm` |
| Capacitance | `farad`, `microfarad`, `nanofarad`, `picofarad` |
| Inductance | `henry`, `millihenry`, `microhenry` |
| Charge | `coulomb` |
| Magnetic Flux | `weber` |
| Magnetic Flux Density | `tesla` |
| Conductance | `siemens` |
| Illuminance | `lux` |
| Luminous Flux | `lumen` |
| Catalytic Activity | `katal` |
| Thermal Conductance | `wattPerKelvin`, `milliwattPerKelvin`, `kilowattPerKelvin` |
| Absorbed Dose | `gray`, `sievert` |
| Quantity | Units |
| ----------------------- | ------------------------------------------------------------------- |
| Area | `squareMeter`, `squareKilometer`, `squareCentimeter`, `hectare` |
| Volume | `cubicMeter`, `liter`, `milliliter`, `microliter` |
| Velocity | `meterPerSecond`, `kilometerPerHour` |
| Acceleration | `meterPerSecondSquared` |
| Force | `newton` |
| Pressure | `pascal`, `bar`, `millibar`, `atmosphere` |
| Energy | `joule`, `kilojoule`, `megajoule`, `kilowattHour` |
| Power | `watt`, `milliwatt`, `kilowatt`, `megawatt`, `gigawatt`, `terawatt` |
| Frequency | `hertz`, `kilohertz`, `megahertz`, `gigahertz`, `becquerel` |
| Density | `kilogramPerCubicMeter`, `gramPerLiter`, `gramPerCubicCentimeter` |
| Specific Volume | `cubicMeterPerKilogram` |
| Momentum | `newtonSecond` |
| Angular Velocity | `radianPerSecond`, `revolutionPerMinute` |
| Angular Acceleration | `radianPerSecondSquared` |
| Torque | `newtonMeter` |
| Dynamic Viscosity | `pascalSecond` |
| Kinematic Viscosity | `squareMeterPerSecond` |
| Surface Tension | `newtonPerMeter` |
| Wavenumber | `reciprocalMeter` |
| Voltage | `volt`, `millivolt`, `kilovolt` |
| Resistance | `ohm`, `milliohm`, `kilohm`, `megohm` |
| Capacitance | `farad`, `microfarad`, `nanofarad`, `picofarad` |
| Inductance | `henry`, `millihenry`, `microhenry` |
| Charge | `coulomb`, `ampereHour`, `milliampereHour` |
| Magnetic Flux | `weber` |
| Magnetic Flux Density | `tesla` |
| Conductance | `siemens` |
| Electric Field Strength | `voltPerMeter` |
| Permittivity | `faradPerMeter` |
| Permeability | `henryPerMeter` |
| Current Density | `amperePerSquareMeter` |
| Illuminance | `lux` |
| Luminous Flux | `lumen` |
| Catalytic Activity | `katal` |
| Thermal Conductance | `wattPerKelvin`, `milliwattPerKelvin`, `kilowattPerKelvin` |
| Heat Capacity | `joulePerKelvin` |
| Specific Heat Capacity | `joulePerKilogramKelvin` |
| Specific Energy | `joulePerKilogram` |
| Thermal Conductivity | `wattPerMeterKelvin` |
| Absorbed Dose | `gray`, `sievert` |
| Volumetric Flow Rate | `cubicMeterPerSecond`, `literPerSecond`, `literPerMinute` |
| Mass Flow Rate | `kilogramPerSecond` |
| Concentration | `molePerCubicMeter`, `molePerLiter` |
| Molar Mass | `kilogramPerMole`, `gramPerMole` |

_<a id="affine">\*</a>
[Affine quantity](https://github.com/isentropic-dev/dim/blob/main/packages/dim-unit/README.md#affine-units)
Expand Down
24 changes: 23 additions & 1 deletion packages/dim-si/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,29 @@
"./illuminance": "./src/illuminance.ts",
"./absorbed-dose": "./src/absorbed-dose.ts",
"./catalytic-activity": "./src/catalytic-activity.ts",
"./thermal-conductance": "./src/thermal-conductance.ts"
"./thermal-conductance": "./src/thermal-conductance.ts",
"./density": "./src/density.ts",
"./specific-volume": "./src/specific-volume.ts",
"./momentum": "./src/momentum.ts",
"./angular-velocity": "./src/angular-velocity.ts",
"./angular-acceleration": "./src/angular-acceleration.ts",
"./torque": "./src/torque.ts",
"./dynamic-viscosity": "./src/dynamic-viscosity.ts",
"./kinematic-viscosity": "./src/kinematic-viscosity.ts",
"./surface-tension": "./src/surface-tension.ts",
"./wavenumber": "./src/wavenumber.ts",
"./heat-capacity": "./src/heat-capacity.ts",
"./specific-heat-capacity": "./src/specific-heat-capacity.ts",
"./specific-energy": "./src/specific-energy.ts",
"./thermal-conductivity": "./src/thermal-conductivity.ts",
"./electric-field-strength": "./src/electric-field-strength.ts",
"./permittivity": "./src/permittivity.ts",
"./permeability": "./src/permeability.ts",
"./current-density": "./src/current-density.ts",
"./volumetric-flow-rate": "./src/volumetric-flow-rate.ts",
"./mass-flow-rate": "./src/mass-flow-rate.ts",
"./concentration": "./src/concentration.ts",
"./molar-mass": "./src/molar-mass.ts"
},
"version": "0.4.3"
}
3 changes: 2 additions & 1 deletion packages/dim-si/src/absorbed-dose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* SI unit: gray (Gy).
*
* Note: gray (absorbed radiation dose) and sievert (equivalent dose)
* share this dimension. This is intentional per SI.
* share this dimension. This is intentional per SI — the type system
* cannot distinguish them.
*
* @example Creating dose quantities
* ```ts
Expand Down
29 changes: 29 additions & 0 deletions packages/dim-si/src/angular-acceleration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Angular acceleration units (T⁻²).
*
* SI unit: radian per second squared (rad/s²).
*
* @example Creating an angular acceleration
* ```ts
* import { radianPerSecondSquared } from "@isentropic/dim-si/angular-acceleration";
*
* const alpha = radianPerSecondSquared(5);
* ```
*
* @module
*/

import type { AngularAcceleration as AngularAccelerationDim } from "@isentropic/dim-isq";
import type { Linear } from "@isentropic/dim-unit";
import { angularAcceleration } from "@isentropic/dim-isq";
import type { BaseUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";

/** An SI angular acceleration quantity. */
export type AngularAcceleration = Linear<AngularAccelerationDim, Si>;

/** Radian per second squared (rad/s²) — SI unit of angular acceleration. */
export const radianPerSecondSquared: BaseUnit<AngularAccelerationDim> = si.unit(
angularAcceleration,
);
39 changes: 39 additions & 0 deletions packages/dim-si/src/angular-velocity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Angular velocity units (T⁻¹).
*
* SI unit: radian per second (rad/s).
*
* Note: angular velocity shares this dimension with frequency
* (hertz). This is intentional per SI — the type system cannot
* distinguish them.
*
* @example Converting RPM to radians per second
* ```ts
* import { radianPerSecond, revolutionPerMinute } from "@isentropic/dim-si/angular-velocity";
* import { valueIn } from "@isentropic/dim-si/ops";
*
* const engine = revolutionPerMinute(3000);
* valueIn(engine, radianPerSecond); // ~314.16
* ```
*
* @module
*/

import type { AngularVelocity as AngularVelocityDim } from "@isentropic/dim-isq";
import type { Linear } from "@isentropic/dim-unit";
import { angularVelocity } from "@isentropic/dim-isq";
import type { BaseUnit, ScaledUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";

/** An SI angular velocity quantity. */
export type AngularVelocity = Linear<AngularVelocityDim, Si>;

/** Radian per second (rad/s) — SI unit of angular velocity. */
export const radianPerSecond: BaseUnit<AngularVelocityDim> = si.unit(
angularVelocity,
);

/** Revolution per minute (rpm) — 2π/60 rad/s. */
export const revolutionPerMinute: ScaledUnit<AngularVelocityDim> =
radianPerSecond.scaled(2 * Math.PI / 60);
11 changes: 11 additions & 0 deletions packages/dim-si/src/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ import { area } from "@isentropic/dim-isq";
import type { BaseUnit, ScaledUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";
import { centimeter, kilometer } from "./length.ts";

/** An SI area quantity. */
export type Area = Linear<AreaDim, Si>;

/** Square meter (m²) — SI unit of area. */
export const squareMeter: BaseUnit<AreaDim> = si.unit(area);

/** Square kilometer (km²) — 10⁶ square meters. */
export const squareKilometer: ScaledUnit<AreaDim> = squareMeter.scaled(
kilometer.scale ** 2,
);

/** Square centimeter (cm²) — 10⁻⁴ square meters. */
export const squareCentimeter: ScaledUnit<AreaDim> = squareMeter.scaled(
centimeter.scale ** 2,
);

/** Hectare (ha) — 10000 square meters. */
export const hectare: ScaledUnit<AreaDim> = squareMeter.scaled(10000);
14 changes: 13 additions & 1 deletion packages/dim-si/src/charge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@
import type { Charge as ChargeDim } from "@isentropic/dim-isq";
import type { Linear } from "@isentropic/dim-unit";
import { charge } from "@isentropic/dim-isq";
import type { BaseUnit } from "./types.ts";
import type { BaseUnit, ScaledUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";
import { ampere, milliampere } from "./current.ts";
import { hour } from "./time.ts";

/** An SI charge quantity. */
export type Charge = Linear<ChargeDim, Si>;

/** Coulomb (C) — SI unit of electric charge. */
export const coulomb: BaseUnit<ChargeDim> = si.unit(charge);

/** Ampere-hour (Ah) — 3600 coulombs. */
export const ampereHour: ScaledUnit<ChargeDim> = coulomb.scaled(
ampere.scale * hour.scale,
);

/** Milliampere-hour (mAh) — 3.6 coulombs. */
export const milliampereHour: ScaledUnit<ChargeDim> = coulomb.scaled(
milliampere.scale * hour.scale,
);
36 changes: 36 additions & 0 deletions packages/dim-si/src/concentration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Concentration units (N·L⁻³).
*
* SI unit: mole per cubic meter (mol/m³).
*
* @example Converting between concentration units
* ```ts
* import { molePerCubicMeter, molePerLiter } from "@isentropic/dim-si/concentration";
* import { valueIn } from "@isentropic/dim-si/ops";
*
* const c = molePerLiter(1);
* valueIn(c, molePerCubicMeter); // 1000
* ```
*
* @module
*/

import type { Concentration as ConcentrationDim } from "@isentropic/dim-isq";
import type { Linear } from "@isentropic/dim-unit";
import { concentration } from "@isentropic/dim-isq";
import type { BaseUnit, ScaledUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";
import { KILO } from "./prefixes.ts";

/** An SI concentration quantity. */
export type Concentration = Linear<ConcentrationDim, Si>;

/** Mole per cubic meter (mol/m³) — SI unit of concentration. */
export const molePerCubicMeter: BaseUnit<ConcentrationDim> = si.unit(
concentration,
);

/** Mole per liter (mol/L) — 1000 mol/m³. */
export const molePerLiter: ScaledUnit<ConcentrationDim> = molePerCubicMeter
.scaled(KILO);
29 changes: 29 additions & 0 deletions packages/dim-si/src/current-density.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Current density units (I·L⁻²).
*
* SI unit: ampere per square meter (A/m²).
*
* @example Creating a current density
* ```ts
* import { amperePerSquareMeter } from "@isentropic/dim-si/current-density";
*
* const j = amperePerSquareMeter(1e6);
* ```
*
* @module
*/

import type { CurrentDensity as CurrentDensityDim } from "@isentropic/dim-isq";
import type { Linear } from "@isentropic/dim-unit";
import { currentDensity } from "@isentropic/dim-isq";
import type { BaseUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";

/** An SI current density quantity. */
export type CurrentDensity = Linear<CurrentDensityDim, Si>;

/** Ampere per square meter (A/m²) — SI unit of current density. */
export const amperePerSquareMeter: BaseUnit<CurrentDensityDim> = si.unit(
currentDensity,
);
44 changes: 44 additions & 0 deletions packages/dim-si/src/density.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Density units (M·L⁻³).
*
* SI unit: kilogram per cubic meter (kg/m³).
*
* @example Converting between density units
* ```ts
* import { gramPerCubicCentimeter, gramPerLiter, kilogramPerCubicMeter } from "@isentropic/dim-si/density";
* import { valueIn } from "@isentropic/dim-si/ops";
*
* const water = kilogramPerCubicMeter(1000);
* valueIn(water, gramPerLiter); // 1000
* valueIn(water, gramPerCubicCentimeter); // 1
* ```
*
* @module
*/

import type { Density as DensityDim } from "@isentropic/dim-isq";
import type { Linear } from "@isentropic/dim-unit";
import { density } from "@isentropic/dim-isq";
import { roundScale } from "@isentropic/dim-unit";
import type { BaseUnit, ScaledUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";
import { gram } from "./mass.ts";
import { centimeter } from "./length.ts";
import { liter } from "./volume.ts";

/** An SI density quantity. */
export type Density = Linear<DensityDim, Si>;

/** Kilogram per cubic meter (kg/m³) — SI unit of density. */
export const kilogramPerCubicMeter: BaseUnit<DensityDim> = si.unit(density);

/** Gram per liter (g/L) — numerically equivalent to kg/m³. */
export const gramPerLiter: ScaledUnit<DensityDim> = kilogramPerCubicMeter
.scaled(gram.scale / liter.scale);

/** Gram per cubic centimeter (g/cm³) — 1000 kg/m³. */
export const gramPerCubicCentimeter: ScaledUnit<DensityDim> =
kilogramPerCubicMeter.scaled(
roundScale(gram.scale / centimeter.scale ** 3),
);
29 changes: 29 additions & 0 deletions packages/dim-si/src/dynamic-viscosity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Dynamic viscosity units (M·L⁻¹·T⁻¹).
*
* SI unit: pascal second (Pa·s).
*
* @example Creating a dynamic viscosity
* ```ts
* import { pascalSecond } from "@isentropic/dim-si/dynamic-viscosity";
*
* const water = pascalSecond(0.001);
* ```
*
* @module
*/

import type { DynamicViscosity as DynamicViscosityDim } from "@isentropic/dim-isq";
import type { Linear } from "@isentropic/dim-unit";
import { dynamicViscosity } from "@isentropic/dim-isq";
import type { BaseUnit } from "./types.ts";
import type { Si } from "./system.ts";
import { si } from "./system.ts";

/** An SI dynamic viscosity quantity. */
export type DynamicViscosity = Linear<DynamicViscosityDim, Si>;

/** Pascal second (Pa·s) — SI unit of dynamic viscosity. */
export const pascalSecond: BaseUnit<DynamicViscosityDim> = si.unit(
dynamicViscosity,
);
Loading
Loading