Skip to content

Commit

Permalink
fix(types): update README and enhance code documentation
Browse files Browse the repository at this point in the history
Expanded the README for better clarity and usage examples. Also, provided in-depth documentation in code for a clearer understanding of function use and behavior. Import statements in example codes within function comments have been removed to avoid redundancy.
  • Loading branch information
hckhanh committed Mar 1, 2024
1 parent 65b4fdc commit 8ee1df2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 0 additions & 6 deletions src/format/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ function formatNumber(
*
* @example
* ```ts
* import { formatVnNumber } from '@hckhanh/vn-number'
*
* formatVnNumber('19990000') // or formatVnNumber(19990000)
* // output: 19.990.000
* ```
Expand All @@ -58,8 +56,6 @@ export function formatVnNumber(
*
* @example
* ```ts
* import { formatVnCurrency } from '@hckhanh/vn-number'
*
* formatVnCurrency('19990000') // or formatVnCurrency(19990000)
* // output: 19.990.000 ₫
* ```
Expand All @@ -84,8 +80,6 @@ export function formatVnCurrency(
*
* @example
* ```ts
* import { formatVnPercent } from '@hckhanh/vn-number'
*
* formatVnPercent('0.99') // or formatVnPercent(0.99)
* // output: 99%
* ```
Expand Down
15 changes: 15 additions & 0 deletions src/read/NumberReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 0 additions & 2 deletions src/read/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* ```
Expand Down

0 comments on commit 8ee1df2

Please sign in to comment.