Skip to content

Commit

Permalink
Add usage examples in number formatting functions
Browse files Browse the repository at this point in the history
Example usages for `formatVnNumber`, `formatVnCurrency` and `formatVnPercent` methods have been added to the code documentation. These examples provide clarification on how to use these number formatting functions, making it easier for other developers to understand their utility and implementation.
  • Loading branch information
hckhanh committed Feb 26, 2024
1 parent 5723fd1 commit a2aed2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckhanh/vn-number",
"version": "1.5.2",
"version": "1.5.3",
"exports": "./src/index.ts",
"exclude": [
".github/",
Expand Down
24 changes: 24 additions & 0 deletions src/format/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ function formatNumber(
/**
* Formats a number as a Vietnamese formatted number.
*
* @example
* ```ts
* import { formatVnNumber } from '@hckhanh/vn-number'
*
* formatVnNumber('19990000') // or formatVnNumber(19990000)
* // output: 19.990.000
* ```
*
* @param number The number to format.
* @param fallbackValue The fallback value to use if formatting fails. Default value is `0`
* @return The formatted number or the `fallbackValue` if formatting fails.
Expand All @@ -48,6 +56,14 @@ export function formatVnNumber(
/**
* Formats a value as Vietnamese Dong (VND) currency.
*
* @example
* ```ts
* import { formatVnCurrency } from '@hckhanh/vn-number'
*
* formatVnCurrency('19990000') // or formatVnCurrency(19990000)
* // output: 19.990.000 ₫
* ```
*
* @param money The value to format as VND currency.
* @param fallbackValue The fallback value to return if `money` is not a valid number. Default value is `0 ₫`
* @return The value formatted as VND currency, or the `fallbackValue` if `money` is not a valid number.
Expand All @@ -66,6 +82,14 @@ export function formatVnCurrency(
/**
* Formats a number or string representing value into a Vietnamese percentage format.
*
* @example
* ```ts
* import { formatVnPercent } from '@hckhanh/vn-number'
*
* formatVnPercent('0.99') // or formatVnPercent(0.99)
* // output: 99%
* ```
*
* @param value The value to format.
* @param fallbackValue The fallback value to use if the `value` is invalid or not provided.
*
Expand Down

0 comments on commit a2aed2e

Please sign in to comment.