Package Exports
- @maptimy/platform-formatters
- @maptimy/platform-formatters/lib/index.js
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 (@maptimy/platform-formatters) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@maptimy/platform-formatters
A platform-agnostic library for formatting distances and durations in a localized way. Currently supports Web and React Native platforms.
Installation
npm install @maptimy/platform-formatters
Usage
Duration Formatter
The duration formatter converts seconds into a human-readable format.
import { LocalizedDurationFormatter } from '@maptimy/platform-formatters';
const durationFormatter = LocalizedDurationFormatter();
durationFormatter.format(3665); // Output: "1h 1m 5s"
Distance Formatter
The distance formatter converts meters into localized distance strings in either meters or kilometers.
import { LocalizedDistanceFormatter } from '@maptimy/platform-formatters';
const distanceFormatter = LocalizedDistanceFormatter();
distanceFormatter.format(1500); // Output: "1.5km"
distanceFormatter.format(500); // Output: "500m"
License
BSD 3-Clause License. See LICENSE for details.