UNPKG

jinbi-utils

Version:

这是一个实用工具库,包含了多个常用的功能模块。以下是各个模块的详细说明:

109 lines (84 loc) 2.86 kB
import { toThousands, convertCurrency, formatFloat, ceil, floor } from '../../src'; describe('toThousands', () => { test(`toThousands('') 返回 '-'`, () => { expect(toThousands('')).toBe('-'); }) test(`toThousands('', '|') 返回 '|'`, () => { expect(toThousands('', '|')).toBe('|'); }) test(`toThousands(123) 返回 '123'`, () => { expect(toThousands(123)).toBe('123'); }) test(`toThousands(12323) 返回 '12,323'`, () => { expect(toThousands(12323)).toBe('12,323'); }) test(`toThousands('12323.12') 返回 '12,323.12'`, () => { expect(toThousands('12323.12')).toBe('12,323.12'); }) }); describe('convertCurrency', () => { test(`convertCurrency() 返回 ''`, () => { expect(convertCurrency()).toBe(''); }) test(`convertCurrency('') 返回 ''`, () => { expect(convertCurrency('-')).toBe('零元整'); }) test(`convertCurrency(1999999999999999) 返回 ''`, () => { const value = '1999999999999999'; expect(convertCurrency(value)).toBe(value); }) test(`convertCurrency(0.012) 返回 '壹分贰毫'`, () => { expect(convertCurrency('0.012')).toBe('壹分贰毫'); }) test(`convertCurrency(0) 返回 '零元整'`, () => { expect(convertCurrency('0')).toBe('零元整'); }) test(`convertCurrency(12.12) 返回 '壹拾贰元壹角贰分'`, () => { expect(convertCurrency('12.12')).toBe('壹拾贰元壹角贰分'); }) test(`convertCurrency(1234567809) 返回 '壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰零玖元整'`, () => { expect(convertCurrency('1234567809')).toBe('壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰零玖元整'); }) }); describe('formatFloat', () => { test(`formatFloat('NaN') 返回 ''`, () => { expect(formatFloat('NaN')).toBe(''); }) test(`formatFloat('1.2345') 返回 '1.23'`, () => { expect(formatFloat('1.2345')).toBe('1.23'); }) test(`formatFloat('1.2345') 返回 '1.235'`, () => { expect(formatFloat('1.2345', 3)).toBe('1.235'); }) test(`formatFloat('1', 3) 返回 '1.000'`, () => { expect(formatFloat('1', 3)).toBe('1.000'); }) }); describe('ceil', () => { test(`ceil('') 返回 ''`, () => { expect(ceil('')).toBe(''); }) test(`ceil('1.23') 返回 2`, () => { expect(ceil('1.23')).toBe(2); }) test(`ceil('1.234', 2) 返回 1.24`, () => { expect(ceil('1.234', 2)).toBe(1.24); }) test(`ceil('1.230', 2) 返回 1.23`, () => { expect(ceil('1.230', 2)).toBe(1.23); }) }); describe('floor', () => { test(`floor('') 返回 ''`, () => { expect(floor('')).toBe(''); }) test(`floor('1.23') 返回 1`, () => { expect(floor('1.23')).toBe(1); }) test(`floor('1.234', 2) 返回 1.23`, () => { expect(floor('1.234', 2)).toBe(1.23); }) test(`floor('1.230', 2) 返回 1.23`, () => { expect(floor('1.230', 2)).toBe(1.23); }) });