1.0.12 • Published 1 year ago

unit-simple v1.0.12

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
1 year ago

Simple Unit (implémentation Typescript)

Utilisation

Utilisation des unités transformées :

const m: Unit = new FundamentalUnit()
const km: Unit = m.scaleMultiply(1000)
const cm: Unit = m.scaleDivide(100)
const cmToKm: UnitConverter = cm.getConverterTo​(km)

cmToKm.convert(3) // 0.00003
cmToKm.inverse().convert(0.00003) // 3

Utilisation des unités dérivées :

const m: Unit = new FundamentalUnit()
const km: Unit = m.scaleMultiply(1000)
const km2: Unit = new DerivedUnit(km.factor(2))
const cm: Unit = m.scaleDivide(100)
const cm2: Unit = new DerivedUnit(cm.factor(2))
const km2Tocm2: UnitConverter = km2.getConverterTo​(cm2)

km2Tocm2.convert(3) // 30000000000
km2Tocm2.inverse().convert(30000000000) // 3

Utilisation des unités dérivées en combinant les dimensions :

const m: Unit = new FundamentalUnit()
const kg: Unit = new FundamentalUnit()
const g: Unit = kg.scaleDivide(1000)
const ton: Unit = kg.scaleMultiply(1000)
const gPerM2: Unit = new DerivedUnit(g, m.factor(-2))
const km: Unit = m.scaleMultiply(1000)
const tonPerKm2: Unit = new DerivedUnit(ton, km.factor(-2))
const cm: Unit = m.scaleDivide(100)
const tonPerCm2: Unit = new DerivedUnit(ton, cm.factor(-2))
const gPerM2ToTonPerKm2: UnitConverter = gPerM2.getConverterTo​(tonPerKm2)
const gPerM2ToTonPerCm2: UnitConverter = gPerM2.getConverterTo​(tonPerCm2)


gPerM2ToTonPerKm2.convert(1) // 1
gPerM2ToTonPerKm2.inverse().convert(3) // 3
gPerM2ToTonPerCm2.convert(1) // 1e-4
gPerM2ToTonPerCm2.convert(3) // 3e-10
gPerM2ToTonPerCm2.offset() // 0.0
gPerM2ToTonPerCm2.scale() // 1e-10
gPerM2ToTonPerCm2.inverse().offset() // -0.0
gPerM2ToTonPerCm2.inverse().convert(3e-10) // 3

Utilisation des températures (conversions affines et linéaires) :

const k: Unit = new FundamentalUnit()
const c: Unit = k.shift(273.15)
const kToC: UnitConverter = k.getConverterTo​(c)

kToC.convert(0) // -273.15
kToC.inverse().convert(0) // 273.15

// en combinaison avec d'autres unités, les conversions d'unités de températures doivent devenir linéaires
const m: Unit = new FundamentalUnit()
const cPerM: Unit = new DerivedUnit(c, m.factor(-1))
const kPerM: Unit = new DerivedUnit(k, m.factor(-1))
const kPerMToCPerM: UnitConverter = kPerM.getConverterTo​(cPerM)

kPerMToCPerM.convert(3) // 3
kPerMToCPerM.inverse().convert(3) // 3

Développement

Résolution des dépendances :

npm install

Compilation et tests :

npm run build

Test seuls :

npm run test
1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.0

1 year ago