diff --git a/README.md b/README.md index 1aeaf37..6969922 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,51 @@ -# vn-number +# vn-number 🇻🇳 -A bunch of utility functions that work with number in Vietnamese language +🛠 A bunch of utility functions that work with number in 🇻🇳 Vietnamese language ## Features -- [Zero dependency](https://jsr.io/@hckhanh/vn-number/dependencies) -- Edge runtime built-in support [![Publish](https://github.com/hckhanh/vn-number/actions/workflows/publish.yml/badge.svg)](https://github.com/hckhanh/vn-number/actions/workflows/publish.yml) +- [Zero dependencies](https://jsr.io/@hckhanh/vn-number/dependencies) +- Built-in support for Edge runtime +- Typesafe with TypeScript +- Fully documented ## Functions -- Read Vietnamese number (một triệu hai trăm năm mươi nghìn) -- Format number in Vietnamese format (1.250.000) -- Format VN currency (VND) (1.250.000 ₫) -- Format percentage in Vietnamese format (99,1%) +### Read Vietnamese number (một triệu hai trăm năm mươi nghìn) + +```ts +import { readVnNumber } from '@hckhanh/vn-number' + +const result = readVnNumber(1250000) +console.log(result) // một triệu hai trăm năm mươi nghìn +``` + +### Format number in Vietnamese format (1.250.000) + +```ts +import { formatVnNumber } from '@hckhanh/vn-number' + +const result = formatVnNumber(1250000) +console.log(result) // 1.250.000 +``` + +### Format VN currency (VND) (1.250.000 ₫) + +```ts +import { formatVnCurrency } from '@hckhanh/vn-number' + +const result = formatVnCurrency(1250000) +console.log(result) // 1.250.000 ₫ +``` + +### Format percentage in Vietnamese format (99,1%) + +```ts +import { formatVnPercent } from '@hckhanh/vn-number' + +const result = formatVnPercent(0.991) +console.log(result) // 99,1% +``` ## Release Notes diff --git a/src/format/number.ts b/src/format/number.ts index 7438c25..ca89fb1 100644 --- a/src/format/number.ts +++ b/src/format/number.ts @@ -35,8 +35,6 @@ function formatNumber( * * @example * ```ts - * import { formatVnNumber } from '@hckhanh/vn-number' - * * formatVnNumber('19990000') // or formatVnNumber(19990000) * // output: 19.990.000 * ``` @@ -58,8 +56,6 @@ export function formatVnNumber( * * @example * ```ts - * import { formatVnCurrency } from '@hckhanh/vn-number' - * * formatVnCurrency('19990000') // or formatVnCurrency(19990000) * // output: 19.990.000 ₫ * ``` @@ -84,8 +80,6 @@ export function formatVnCurrency( * * @example * ```ts - * import { formatVnPercent } from '@hckhanh/vn-number' - * * formatVnPercent('0.99') // or formatVnPercent(0.99) * // output: 99% * ``` diff --git a/src/read/NumberReader.ts b/src/read/NumberReader.ts index 7fc7d38..eb68925 100644 --- a/src/read/NumberReader.ts +++ b/src/read/NumberReader.ts @@ -4,10 +4,25 @@ import Million from './Million.ts' import Billion from './Billion.ts' import { InvalidNumberTypeError } from './Utils.ts' +/** + * Type of number + */ enum NumberType { + /** + * Number of the first group (100.000.000.xxx) + */ Numbers, + /** + * Number in the thousand group (100.000.xxx.000) + */ Thousand, + /** + * Number in the million group (100.xxx.000.000) + */ Million, + /** + * Number in the billion group (xxx.000.000.000) + */ Billion } diff --git a/src/read/index.ts b/src/read/index.ts index ef61818..4ab08bf 100644 --- a/src/read/index.ts +++ b/src/read/index.ts @@ -6,8 +6,6 @@ import NumberReader from './NumberReader.ts' * * @example * ```ts - * import { readVnNumber } from '@hckhanh/vn-number' - * * readVnNumber('19990000') // or readVnNumber(19990000) * // output: mười chín triệu chín trăm chín mươi nghìn * ```