Skip to content

Draft of a framework for material (physical) values and their units.

Notifications You must be signed in to change notification settings

Kyriosity/convert-smth

Repository files navigation

U(nit)Values, or physical values, for Typescript

This Angular project began in 2020 as a hobby dive of mine into Angular/Typescript. _i

It's all about making physical values (like temperature, mass) integrated in development and decently looking in UI.

So far it's not an overall solution but rather a draft of possible framework  _b

  _i  nevertheless i'm since 1990s in IT (from deep backend to far frontend) and for the recent decade my native language has been amazing C#
  _b  a big challenge asking for countless overlapping concepts and tons of well-tempered code

How it looks for user

Just ng build the only library in this project and ng serve the app. Navigate to Units.
Or/and look at commented snapshot of that demo

How it works for developer

Declaration

const theChallengerDeep = meter(10929) // deepest known point in the world ocean 
console.log(theChallengerDeep.value) // 10929
console.log(theChallengerDeep.unit === Meter) // true
console.log(theChallengerDeep.unit == Foot) // false

interface State {
    hightestElevation: len,
    recordHigh: temperature
}
const Alaska: State = { hightestElevation: foot(20310), recordHigh: fahrenheit(100) }
const Bavaria: State = { hightestElevation: meter(2962), recordHigh: celsius(40.3) }

Conversion of units

Easier than ABC but still "type safe".  _u

let bottle = liter(0.5)
const inUkWouldBe = bottle.to(ImperialPint)
const bottle2 = bottle.to() // use to clone
euroBottle.to(Meter) // this won't compile
euroBottle.unit = Liter // this either, even if the same unit

  _u  unit is immutable, since running conversion on it's setter won't be intuitive

Math operations

UValue exposes its value property that you can set/modify in the usual fashion:

const tempo = milesHour(90); tempo.value -= 20; tempo.value = 30 

When it takes more than one UValue this project offers the following syntax sugar:  _o

const plane = ton(45.5); const fuel = kilogram(15000); const unusedEquipment = kilogram(15 * 75)
plane.add(fuel).subtract(unusedEquipment) // plane is still in first set tons

const pets = kilogram(186.5)
const cargoTotal = ton(11.5).plus(kilogram(280)).plus(pound(9570)).plus(pets) // also tons
const takeoffWeight = plane.plus(cargoTotal).minus(pets)
// the crew rejected to transport pets cause the cargo bay isn't pressuresized

  _o  Both TS and JS do NOT facilitate overload of arithmetic ops (+, -, *, /). Nevertheless this must be a performance hit and a resulted in unit would be non-obvious

Presentation

Includes formatting, labeling, parsing, ng-pipe and is worth of a separate report.

Service

Actions can be avaialble through the service.

Predefined UValues

Read more

Units schemes

Read more

Further reading for project development

Dev: concepts
Dev: guidelines
Open points

About

Draft of a framework for material (physical) values and their units.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published