0.4.0 • Published 4 years ago

@exomath/unitscript v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

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 * density

Node

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:

SymbolMLTIΘJNA
length1
width1
height1
volume3
density1-3
mass1

which specifies the dimensional exponents for the dimensions:

DimensionDescriptionBase Unit
MMasskilogram (kg)
LLengthmeter (m)
TTimesecond (s)
IElectric currentampere (A)
ΘAbsolute temperaturekelvin (K)
JLuminous intensitycandela (cd)
NAmount of substancemole (mol)
AAngleradian (rad)

Installation

NPM

$ npm i @exomath/unitscript

Yarn

$ yarn add @exomath/unitscript
0.5.0

4 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago