Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@phensley/unit-converter

Package Overview
Dependencies
Maintainers
0
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@phensley/unit-converter

Conversions between CLDR units

latest
Source
npmnpm
Version
1.13.1
Version published
Weekly downloads
227
-52.41%
Maintainers
0
Weekly downloads
 
Created
Source

@phensley/unit-converter

@phensley/unit-converter min+gzip

General framework for converting between units. Includes pre-defined factors for conversion between CLDR units.

import { MathContext } from '@phensley/decimal';
import { LENGTH, UnitFactors } from '@phensley/unit-converter';

const factors = new UnitFactors(LENGTH);
const ctx: MathContext = { precision: 7 };
const dst = 'yard';
for (const unit of ['foot', 'mile']) {
  const fac = factors.get(unit, dst)!;
  for (const n of [1, 1.5, 2, 3, 4, 5, 6, 10]) {
    const r = fac.multiply(n, ctx);

    const a = `${n} ${unit}`.padStart(10);
    const b = `${r.toDecimal(ctx).toString()} ${dst}`.padEnd(14);
    const c = `${r.numerator()} \u00F7 ${r.denominator()} ${dst}`;
    console.log(`${a} == ${b}    ${c}`);
  }
  console.log();
}
    1 foot == 0.3333333 yard    12 ÷ 36 yard
  1.5 foot == 0.5 yard          18.0 ÷ 36 yard
    2 foot == 0.6666667 yard    24 ÷ 36 yard
    3 foot == 1 yard            36 ÷ 36 yard
    4 foot == 1.333333 yard     48 ÷ 36 yard
    5 foot == 1.666667 yard     60 ÷ 36 yard
    6 foot == 2 yard            72 ÷ 36 yard
   10 foot == 3.333333 yard     120 ÷ 36 yard

    1 mile == 1760 yard         63360 ÷ 36 yard
  1.5 mile == 2640 yard         95040.0 ÷ 36 yard
    2 mile == 3520 yard         126720 ÷ 36 yard
    3 mile == 5280 yard         190080 ÷ 36 yard
    4 mile == 7040 yard         253440 ÷ 36 yard
    5 mile == 8800 yard         316800 ÷ 36 yard
    6 mile == 10560 yard        380160 ÷ 36 yard
   10 mile == 17600 yard        633600 ÷ 36 yard

FAQs

Package last updated on 28 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts