Skip to content

Commit

Permalink
Add a bunch more units
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfv committed Jan 6, 2025
1 parent 19da370 commit a508702
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/dimensional/src/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export namespace Attribute {
export type Name = Dimension.Name
| 'area' | 'volume'
| 'velocity' | 'acceleration'
| 'force' | 'energy' | 'power';
| 'force' | 'energy' | 'power'
| 'pressure' | 'flow' | 'viscosity';
/**
* Is an object containing keys of attributes and values of nonzero exponents.
*/
Expand Down Expand Up @@ -98,6 +99,9 @@ export namespace Attribute {
force: () => new Attribute({ mass: 1, acceleration: 1 }, 'F'),
energy: () => new Attribute({ force: 1, length: 1 }, 'E'), // Same as mv^2, mgh, ...
power: () => new Attribute({ energy: 1, time: -1 }, 'P'),
pressure: () => new Attribute({ force: 1, area: -1 }, 'P'),
flow: () => new Attribute({ volume: 1, time: -1 }, 'Q'),
viscosity: () => new Attribute({ pressure: 1, time: -1 }, '\\mu'),
};
/**
* Represents a dimensionless attribute.
Expand Down
20 changes: 20 additions & 0 deletions packages/dimensional/src/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export namespace Conversion {
micron: () => Conversion.scaled('micro', 'meter'),
millimeter: () => Conversion.scaled('milli', 'meter'),
centimeter: () => Conversion.scaled('centi', 'meter'),
decimeter: () => Conversion.scaled('deci', 'meter'),
meter: () => Conversion.simple('\\text{m}', 'length'),
kilometer: () => Conversion.scaled('kilo', 'meter'),
inch: () => Conversion.relative('\\text{in}', 1 / 12, 'foot'),
Expand All @@ -106,10 +107,29 @@ export namespace Conversion {
mole: () => Conversion.simple('\\text{mol}', 'substance'),
candela: () => Conversion.simple('\\text{cd}', 'intensity'),
lumen: () => Conversion.relative('\\text{lm}', 4 * Math.PI, 'candela'),
milliliter: () => Conversion.scaled('milli', 'liter'),
liter: () => Conversion.complex('\\text{L}', { decimeter: 3 }),
gallon: () => Conversion.relative('\\text{gal}', 3.7854, 'liter'),
Newton: () => Conversion.complex('\\text{N}', { kilogram: 1, meter: 1, second: -2 }),
kiloNewton: () => Conversion.scaled('kilo', 'Newton'),
pound_force: () => Conversion.complex('\\text{lb}_{f}', { slug: 1, foot: 1, second: -2 }),
Joule: () => Conversion.complex('\\text{J}', { Newton: 1, meter: 1 }),
calorie: () => Conversion.relative('\\text{cal}', 1, 'Joule'),
Calorie: () => Conversion.relative('\\text{Cal}', 1000, 'calorie'),
WattHour: () => Conversion.complex('\\text{Wh}', { Watt: 1, hour: -1 }),
kiloWattHour: () => Conversion.scaled('kilo', 'WattHour'),
BritishThermalUnit: () => Conversion.relative('\\text{BTU}', 1055.056, 'Joule'),
Watt: () => Conversion.complex('\\text{W}', { Joule: 1, second: -1 }),
Pascal: () => Conversion.complex('\\text{Pa}', { Newton: 1, meter: -2 }),
kiloPascal: () => Conversion.scaled('kilo', 'Pascal'),
atmosphere: () => Conversion.relative('\\text{atm}', 101.325, 'kiloPascal'),
millibar: () => Conversion.scaled('milli', 'bar'),
bar: () => Conversion.relative('\\text{bar}', 100, 'kiloPascal'),
mmHg: () => Conversion.relative('\\text{mmHg}', 7.5, 'kiloPascal'),
pounds_per_square_inch: () => Conversion.complex('\\text{psi}', { pound_force: 1, inch: -2 }),
poise: () => Conversion.complex('\\text{P}', { gram: 1, centimeter: -1, second: -1 }),
centipoise: () => Conversion.scaled('centi', 'poise'),
stoke: () => Conversion.complex('\\text{St}', { centimeter: 2, second: -1 }),
centistoke: () => Conversion.scaled('centi', 'stoke'),
};
}
10 changes: 8 additions & 2 deletions packages/dimensional/src/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export namespace Unit {
// Time span/duration
| 'nanosecond' | 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'
// Length/distance
| 'nanometer' | 'micrometer' | 'micron' | 'millimeter' | 'centimeter' | 'meter' | 'kilometer' | 'inch' | 'foot' | 'yard' | 'mile'
| 'nanometer' | 'micrometer' | 'micron' | 'millimeter' | 'centimeter' | 'decimeter' | 'meter' | 'kilometer' | 'inch' | 'foot' | 'yard' | 'mile'
// Mass
| 'milligram' | 'gram' | 'kilogram' | 'tonne' | 'ounce' | 'pound_mass' | 'slug' | 'stone' | 'shortton'
// Current
Expand All @@ -23,12 +23,18 @@ export namespace Unit {
| 'mole'
// Luminous Intensity
| 'candela' | 'lumen'
// Volume
| 'milliliter' | 'liter' | 'gallon'
// Force
| 'Newton' | 'kiloNewton' | 'pound_force'
// Energy
| 'Joule'
| 'Joule' | 'calorie' | 'Calorie' | 'WattHour' | 'kiloWattHour' | 'BritishThermalUnit'
// Power
| 'Watt'
// Pressure
| 'Pascal' | 'kiloPascal' | 'atmosphere' | 'millibar' | 'bar' | 'mmHg' | 'pounds_per_square_inch'
// Viscosity
| 'poise' | 'centipoise' | 'stoke' | 'centistoke'
// Trailing semicolon
;
/**
Expand Down

0 comments on commit a508702

Please sign in to comment.