UNPKG

ice.fo.utils

Version:

38 lines (28 loc) 924 B
export function checkIsNumber (value) { if (typeof value == 'number') { return true } if (typeof value == 'string') { // eslint-disable-next-line no-self-compare return +value === +value } return false } export function formatTextNumber (value, decimal = 0, emptyValue = '0') { if (!value) { return emptyValue } value = `${value}` const hasEndDot = (decimal && value.endsWith('.')) || '' const num = !decimal ? parseInt(value) : parseFloat(value) return num.toLocaleString(undefined, { maximumFractionDigits: decimal }) + (hasEndDot && '.') } export function formatTextCurrency (value, prefix = '₩ ', suffix = '') { const textNumber = formatTextNumber(value) return `${prefix}${textNumber}${suffix}` } export function randomInt (from = 0, to = 100) { const min = Math.ceil(from) const max = Math.floor(to) return Math.floor(Math.random() * (max - min + 1)) + min }