0.4.0 • Published 6 years ago
@exomath/unitscript v0.4.0
Quick Start
Input
./example.unitjs
const length = 10 ft
const width = 5 ft
const height = 2 ft
export const volume = length * width * height
const density = 483.84 lbm / ft^3
export const mass = volume * densityNode
const fs = require('fs')
const compile = require('unitscript').compile
const unitjs = fs.readFileSync('./example.unitjs')
const { js, dim } = compile(unitjs)
fs.writeFileSync(./example.js, js)
fs.writeFileSync(./example.dimjs, JSON.stringify(dim))Output
./example.js
const length = 3.048
const width = 1.524
const height = 0.6096
export const volume = length * width * height
const density = 7750.37331885687
export const mass = volume * density./example.dimjs
{
"length": [0, 1, 0, 0, 0, 0, 0, 0],
"width": [0, 1, 0, 0, 0, 0, 0, 0],
"height": [0, 1, 0, 0, 0, 0, 0, 0],
"volume": [0, 3, 0, 0, 0, 0, 0, 0],
"density": [1, -3, 0, 0, 0, 0, 0, 0],
"mass": [1, 0, 0, 0, 0, 0, 0, 0]
}which is represented by the dimensional analysis table:
| Symbol | M | L | T | I | Θ | J | N | A |
|---|---|---|---|---|---|---|---|---|
length | 1 | |||||||
width | 1 | |||||||
height | 1 | |||||||
volume | 3 | |||||||
density | 1 | -3 | ||||||
mass | 1 |
which specifies the dimensional exponents for the dimensions:
| Dimension | Description | Base Unit |
|---|---|---|
| M | Mass | kilogram (kg) |
| L | Length | meter (m) |
| T | Time | second (s) |
| I | Electric current | ampere (A) |
| Θ | Absolute temperature | kelvin (K) |
| J | Luminous intensity | candela (cd) |
| N | Amount of substance | mole (mol) |
| A | Angle | radian (rad) |
Installation
NPM
$ npm i @exomath/unitscriptYarn
$ yarn add @exomath/unitscript