Package Exports
- @formatjs/intl-utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@formatjs/intl-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Intl Utils
Provide i18n utilities.
API
selectUnit
This function determines the best fit
unit based on a specific set of customizable thresholds.
function selectUnit(
from: Date | number,
to: Date | number = Date.now(),
thresholds = DEFAULT_THRESHOLDS
): { value: number; unit: Unit };
where thresholds
has the shape of:
interface Threshold {
second: number;
minute: number;
hour: number;
}
day
, week
, quarter
& year
are based on calendar, thus not customizable.
Example:
import { selectUnit } from '@formatjs/intl-utils';
selectUnit(Date.now() - 1000); // { value: -1, unit: 'second' }
selectUnit(Date.now() - 44000); // { value: -44, unit: 'second' }
selectUnit(Date.now() - 50000); // { value: 1, unit: 'minute' }