1.0.0 • Published 9 months ago

@neuledge/units v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Units Constants

This package provides set of constants for commonly used units such as DAY_MS and SIZE_MB.

Install

Install the package:

yarn add @neuledge/units

Usage

Import the constants you need and reference them in your code:

import { DAY_MS, SIZE_MB } from '@neuledge/units';

const MAX_FILE_SIZE = 10 * SIZE_MB;
const MAX_FILE_AGE = 30 * DAY_MS;

Available constants

ConstantValue
SECOND_MS1000
MINUTE_MS60e3
HOUR_MS3600e3
DAY_MS86400000
WEEK_MS7 * DAY_MS
YEAR_MS365 * DAY_MS
SIZE_KB1024
SIZE_MB1024 * SIZE_KB
SIZE_GB1024 * SIZE_MB
SLUG_REGEXP/^[\da-z]+(?:-[\da-z]+)*$/
VAR_NAME_REGEXP/^[_a-z]\w*$/i

Available helper functions

FunctionDescription
roundCurrencyRounds a number to 2 decimal places
formatDigitsFormats a number with padding digits
isNonNullableChecks if a value is not null or undefined
elapsedTimeStrReturns a string representation of elapsed time
formatSlugReturns a slug representation of a string
awaitTimeoutReturns a promise that resolves after a given timeout
rejectTimeoutReturns a promise that rejects after a given timeout