npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oqton/utils-units

v1.2.1

Published

A library for parsing and formatting unit values.

Downloads

212

Readme

@oqton/utils-units

A library for formatting unit values.

Basic Usage

import { Area, EUR, getUnitDefinition } from '@oqton/utils-units';

console.log(Area.formatAsString(200)); // '200 mm²'
console.log(EUR.formatAsString(123.456)); // '€ 123.46'

console.log(getUnitDefinition('MILLIMETER/SECOND^2').formatAsString(200)); // '200 mm/s²'

API

Table of Contents

EUR

EUR Currency

CNY

CNY Currency

Units

All the supported units.

Amperes

Amps

Celsius

Degrees Celsius

Count

A counted event

Decibels

Sound Level

Degrees

Angle in degrees

DegreesSecond

Angular degrees per second

DegreesSecondSquared

Angular acceleration in degrees per second squared

Hertz

Frequency measured in cycles per second

Joules

A measurement of energy

Kilograms

Kilograms

Liters

Liters

LitersSecond

Liters per second

MicroRadians

Measurement of Tilt

Millimeters

Millimeters

MillimetersSecond

Millimeters per second

MillimetersSecondSquared

Acceleration in millimeters per second squared

Millimeter3D

A point in space identified by X, Y, and Z positions and represented by a space-delimited set of numbers each expressed in millimeters.

Newtons

Force in Newtons

NewtonMeters

Torque, a unit for force times distance.

Ohms

Measure of Electrical Resistance

Pascals

Pressure in Newtons per square meter

MegaPascals

Pressure in Newtons per square millimeter

PascalSeconds

Measurement of Viscosity

Percent

Percentage

FractionalPercent

Fractional percentage

PH

A measure of the acidity or alkalinity of a solution

RPM

Revolutions per minute

Seconds

A measurement of time.

SiemensMeter

A measurement of Electrical Conductivity

Volts

Volts

VoltAmperes

Volt-Ampere (VA)

VoltAmpereReactive

Volt-Ampere Reactive (VAR)

Watts

Watts

WattSeconds

Measurement of electrical energy, equal to one Joule

DateTime

An ISO formatted Date /Time

Milliseconds

A measurement of time

Other

Unknown Units

Length

Length

Area

Area

Volume

Volume

formatCurrencyAsTokens

Format a currency amount as tokens.

Parameters

Returns Array<FormatToken>

formatCurrencyAsString

Format a currency amount as string.

Parameters

Returns string

formatTimeAsTokens

Format a time as tokens.

Parameters

  • input (undefined | null | number | string | Date | Moment) The input to format.
  • precision TimePrecision The precision with which to format the input. (optional, default TIME_PRECISION.MINUTE)

Returns Array<FormatToken>

formatTimeAsString

Format a time as a string.

Parameters

  • input (undefined | null | number | string | Date | Moment) The input to format.
  • precision TimePrecision The precision with which to format the input. (optional, default TIME_PRECISION.MINUTE)

Returns string

formatDateTimeAsTokens

Format a date-time as tokens.

Parameters

  • input (undefined | null | number | string | Date | Moment) The input to format.
  • precision DateTimePrecision The precision with which to format the input. (optional, default TIME_PRECISION.MINUTE)

Returns Array<FormatToken>

formatDateTimeAsString

Format a date-time as a string.

Parameters

  • input (undefined | null | number | string | Date | Moment) The input to format.
  • precision DateTimePrecision The precision with which to format the input. (optional, default TIME_PRECISION.MINUTE)

Returns string

formatDateAsTokens

Format a date as tokens.

Parameters

  • input (undefined | null | number | string | Date | Moment) The input to format.
  • precision DateTimePrecision The precision with which to format the input. (optional, default DATE_TIME_PRECISION.DAY)

Returns Array<FormatToken>

formatDateAsString

Format a date as a string.

Parameters

  • input (undefined | null | number | string | Date | Moment) The input to format.
  • precision DateTimePrecision The precision with which to format the input. (optional, default DATE_TIME_PRECISION.DAY)

Returns string

formatDurationAsTokens

Format a duration as tokens.

Parameters

Returns Array<FormatToken>

formatDurationAsString

Format a duration as a string.

Parameters

Returns string

formatNumberAsTokens

Format a number as tokens.

Parameters

Returns Array<FormatToken>

formatNumberAsString

Format a number as a string.

Parameters

Returns string

formatPointAsTokens

Format a point as tokens.

Parameters

Returns Array<FormatToken>

formatPointAsString

Format a point as a string.

Parameters

Returns string

CurrencyUnitDefinition

Extends UnitDefinition

Currency Unit Definition.

Parameters

  • config CurrencyUnitDefinitionConfig

DateTimeUnitDefinition

Extends UnitDefinition

Date/Time Unit Definition.

DurationUnitDefinition

Extends UnitDefinition

Duration Unit Definition.

Parameters

  • config DurationUnitDefinitionConfig

NumberUnitDefinition

Extends UnitDefinition

Numeric Unit Definition.

Parameters

  • config NumberUnitDefinitionConfig

PercentUnitDefinition

Extends NumberUnitDefinition

Percentage Unit Definition.

PointUnitDefinition

Extends UnitDefinition

Point Unit Definition.