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

etraid_formats

v1.0.17

Published

ETRA I+D format helpers

Downloads

6

Readme

ETRA I+D Common Formats

Library for common formatting of dates and measurements accross different applications

Usage

Import

import Formats from 'etraid_formats';

Date-related formatting

Formats.locale('es');
console.log(Formats.date(new Date())); // 25/06/2018
console.log(Formats.time(new Date())); // 13:28:30
console.log(Formats.shorttime(new Date())); // 13:28
console.log(Formats.datetime(new Date())); // 25/06/2018 13:28:30
console.log(Formats.duration(moment.duration(123, 'second'))); // 2m 3s
console.log(Formats.duration(moment.duration(123, 'minute'))); // 2h 3m 0s
console.log(Formats.duration(moment.duration(123, 'hour'))); // 5d 3h 0m 0s
console.log(Formats.duration(moment.duration(123, 'day'))); // 123d 0h 0m 0s

Date-related formats

console.log(Formats.date_format()); // L
console.log(Formats.time_format()); // HH:mm:ss
console.log(Formats.shorttime_format()); // HH:mm
console.log(Formats.datetime_format()); // L HH:mm:ss
console.log(Formats.duration_format()); // d[d] h[h] m[m] s[s]

Measurements formatting

Formats.measurement(value, units, [factor], [decimals])

value: number to be formatted

units: units of the measurement

[factor]: optional; for those cases where the value is not given in the defined units, factor that shall be applied to convert it (see examples below)

[decimals]: optional; maximum number of decimals to round to (fewer can be used)

Defined measurements

| CATEGORY | MAGNITUDE | UNIT | |--------|--------|--------| | Energy | Active power | Formats.SYMBOLS.ENERGY.W | | Energy | Reactive power | Formats.SYMBOLS.ENERGY.var | | Energy | Apparent power | Formats.SYMBOLS.ENERGY.VA | | Energy | Voltage | Formats.SYMBOLS.ENERGY.V | | Energy | Current | Formats.SYMBOLS.ENERGY.A | | Energy | Frequency | Formats.SYMBOLS.ENERGY.Hz | | Energy | Active energy | Formats.SYMBOLS.ENERGY.kWh | | Energy | Reactive energy | Formats.SYMBOLS.ENERGY.kvarh | | Emissions | CO2 | Formats.SYMBOLS.EMISSIONS.CO2 | | Distance | Distance | Formats.SYMBOLS.DISTANCE.m | | Speed | Speed (m/s) | Formats.SYMBOLS.SPEED.m_s | | Speed | Speed (km/h) | Formats.SYMBOLS.SPEED.km_h | | Weight | Weight | Formats.SYMBOLS.WEIGHT.g | | Weather | Temperature (degree Celsius) | Formats.SYMBOLS.WEATHER.degC | | Weather | Temperature (degree Fahrenheit) | Formats.SYMBOLS.WEATHER.degF | | Weather | Temperature (Kelvin) | Formats.SYMBOLS.WEATHER.K | | Weather | Atmospheric pressure (mbar) | Formats.SYMBOLS.WEATHER.mbar | | Currency | Euro (€) | Formats.SYMBOLS.CURRENCY.EUR | | Currency | Pound sterling (£) | Formats.SYMBOLS.CURRENCY.GBP | | Currency | United States dollar ($) | Formats.SYMBOLS.CURRENCY.USD | | General | Percentage | Formats.SYMBOLS.GENERAL.PERCENTAGE | | General | Degree | Formats.SYMBOLS.GENERAL.DEGREE |

Energy-related measurements formatting

console.log(Formats.measurement(20000000, Formats.SYMBOLS.ENERGY.W)); // 20 MW
console.log(Formats.measurement(20000, Formats.SYMBOLS.ENERGY.var)); // 20 kvar
console.log(Formats.measurement(200, Formats.SYMBOLS.ENERGY.VA)); // 200 VA
console.log(Formats.measurement(0.2, Formats.SYMBOLS.ENERGY.W)); // 200 mW

Distance-related measurements formatting

console.log(Formats.measurement(20, Formats.SYMBOLS.DISTANCE.m, 1000)); // 20 km

Speed-related measurements formatting

console.log(Formats.measurement(20, Formats.SYMBOLS.SPEED.m_s)); // 20 m/s
console.log(Formats.measurement(20, Formats.SYMBOLS.SPEED.km_h)); // 20 km/h

Weight-related measurements formatting

console.log(Formats.measurement(20000, Formats.SYMBOLS.WEIGHT.g, 1000)); // 20 t

Weather-related measurements formatting

console.log(Formats.measurement(20, Formats.SYMBOLS.WEATHER.degC)); // 20 °C
console.log(Formats.measurement(20, Formats.SYMBOLS.WEATHER.degF)); // 20 °F
console.log(Formats.measurement(20, Formats.SYMBOLS.WEATHER.K)); // 20 K
console.log(Formats.measurement(20, Formats.SYMBOLS.WEATHER.mbar)); // 20 mbar

Emissions-related measurements formatting

// Please note it returns HTML code
console.log(Formats.measurement(20000, Formats.SYMBOLS.EMISSIONS.CO2, 1000)); // 20 t CO<sub>2</sub>

Currency-related measurements formatting

console.log(Formats.measurement(20, Formats.SYMBOLS.CURRENCY.EUR)); // 20 €
console.log(Formats.measurement(2000000, Formats.SYMBOLS.CURRENCY.EUR)); // 2 M€
console.log(Formats.measurement(20, Formats.SYMBOLS.CURRENCY.GBP)); // £20
console.log(Formats.measurement(2000000, Formats.SYMBOLS.CURRENCY.GBP)); // £2m
console.log(Formats.measurement(20, Formats.SYMBOLS.CURRENCY.USD)); // $20
console.log(Formats.measurement(2000000, Formats.SYMBOLS.CURRENCY.USD)); // $2m

Other measurements formatting

console.log(Formats.measurement(200, Formats.SYMBOLS.GENERAL.PERCENTAGE)); // 200%
console.log(Formats.measurement(200, Formats.SYMBOLS.GENERAL.DEGREE)); // 200°

Decimals and thousands formatting

Formats.locale('es');
console.log(Formats.measurement(20200.200, Formats.SYMBOLS.CURRENCY.EUR)); // 20.200,2 €
console.log(Formats.measurement(20200.200, Formats.SYMBOLS.CURRENCY.GBP)); // £20.200,2
console.log(Formats.measurement(20200.246, Formats.SYMBOLS.DISTANCE.m, 1000)); // 20.200,25 km

Formats.locale('en');
console.log(Formats.measurement(20200.200, Formats.SYMBOLS.CURRENCY.EUR)); // 20,200.2 €
console.log(Formats.measurement(20200.200, Formats.SYMBOLS.CURRENCY.GBP)); // £20,200.2
console.log(Formats.measurement(20200.246, Formats.SYMBOLS.DISTANCE.m, 1000)); // 20,200.25 km