@chain1/utils
v1.0.0
Published
Utility functions for chain wallet app
Maintainers
Readme
@chain1/stok-utils
Utility functions for STOK chain wallet app.
Installation
npm install @chain1/stok-utils
# or
yarn add @chain1/stok-utilsUsage
Format Utils
import { formatDisplayAmount, formatAmount } from '@chain1/stok-utils';
// Format Korean Won (no decimals)
formatDisplayAmount(1000000, 'krw'); // "1,000,000"
// Format USD (with decimals)
formatDisplayAmount(1000.50, 'usd'); // "1,000.50"
// Small amounts (< 1) show up to 6 decimals
formatDisplayAmount(0.000123, 'usd'); // "0.000123"Date Utils
import { formatDate, getTodayTimeRange, isToday } from '@chain1/stok-utils';
// Format dates
formatDate('2025-01-10T12:30:00Z'); // "2025-01-10 12:30"
formatDate('2025-01-10T12:30:00Z', 'korean'); // "2025년 01월 10일 12:30"
formatDate('2025-01-10T12:30:00Z', 'short'); // "01/10 12:30"
// Get today's time range
const { startTime, endTime } = getTodayTimeRange();
// Check if date is today
isToday(new Date()); // trueAPI
formatDisplayAmount(amount, currency)
Formats amount with thousand separators based on currency.
amount(number|string): Amount to formatcurrency(string): Currency code ('krw', 'usd', 'cny', etc.)- Returns: Formatted string
formatDate(isoDateString, format)
Formats ISO date string to readable format.
isoDateString(string): ISO date stringformat(string): Format type ('default', 'korean', 'short', 'time', 'date', 'korean-date')- Returns: Formatted date string
getTodayTimeRange()
Gets start and end time of today.
- Returns: Object with
{ startTime, endTime }as ISO strings
isToday(date)
Checks if date is today.
date(string|Date): Date to check- Returns: Boolean
License
MIT
