-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add currency related utility functions and update docs
- Loading branch information
Showing
58 changed files
with
259 additions
and
50 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
documentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToAUD.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: 'formatToAUD' | ||
title: 'formatToAUD' | ||
sidebar_label: 'formatToAUD' | ||
sidebar_position: 0 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToAUD } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A function for formatting a number or number-formatted string specifically to AUD. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
22 changes: 22 additions & 0 deletions
22
documentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToCAD.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: 'formatToCAD' | ||
title: 'formatToCAD' | ||
sidebar_label: 'formatToCAD' | ||
sidebar_position: 0 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToCAD } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A function for formatting a number or number-formatted string specifically to CAD. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
22 changes: 22 additions & 0 deletions
22
documentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToCNY.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: 'formatToCNY' | ||
title: 'formatToCNY' | ||
sidebar_label: 'formatToCNY' | ||
sidebar_position: 0 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToCNY } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A function for formatting a number or number-formatted string specifically to CNY. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
23 changes: 23 additions & 0 deletions
23
...mentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToCurrency.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
id: 'formatToCurrency' | ||
title: 'formatToCurrency' | ||
sidebar_label: 'formatToCurrency' | ||
sidebar_position: -1 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToCurrency } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A generic function for formatting a number or number-formatted string to any valid currency. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `currency: string` - Must be a valid ISO 4217 currency code as specified [here](https://en.wikipedia.org/wiki/ISO_4217#List_of_ISO_4217_currency_codes) | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
22 changes: 22 additions & 0 deletions
22
documentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToEUR.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: 'formatToEUR' | ||
title: 'formatToEUR' | ||
sidebar_label: 'formatToEUR' | ||
sidebar_position: 0 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToEUR } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A function for formatting a number or number-formatted string specifically to EUR. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
22 changes: 22 additions & 0 deletions
22
documentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToGBP.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: 'formatToGBP' | ||
title: 'formatToGBP' | ||
sidebar_label: 'formatToGBP' | ||
sidebar_position: 0 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToGBP } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A function for formatting a number or number-formatted string specifically to GBP. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
22 changes: 22 additions & 0 deletions
22
documentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToJPY.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: 'formatToJPY' | ||
title: 'formatToJPY' | ||
sidebar_label: 'formatToJPY' | ||
sidebar_position: 0 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToJPY } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A function for formatting a number or number-formatted string specifically to JPY. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
22 changes: 22 additions & 0 deletions
22
documentation/docs/api/03-Utilities/01-Functions/00-Currencies/formatToUSD.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: 'formatToUSD' | ||
title: 'formatToUSD' | ||
sidebar_label: 'formatToUSD' | ||
sidebar_position: 0 | ||
custom_edit_url: null | ||
--- | ||
|
||
`import { formatToUSD } from '@orfium/toolbox';` | ||
|
||
### Description | ||
|
||
A function for formatting a number or number-formatted string specifically to USD. | ||
|
||
### Parameters | ||
|
||
- `value: string | number` - If it's a string it must be expressing a number, otherwise you will get a runtime error | ||
- `options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'>` - An [`options`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) compliant object, excluding the properties `currency` and `style` | ||
|
||
### Return value | ||
|
||
Ƭ `string` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
| Name | Type | | ||
| :--------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `regularNavigation` | <code>[MenuItem](../Types/MenuItem)[]</code> | | ||
| `regularNavigation` | <code>[MenuItem](../04-Types/MenuItem)[]</code> | | ||
| `navigationHeader` | `string` | | ||
| `userIsAdmin?` | `boolean` _(default: `false`)_ | | ||
| `hideOrgSwitcher?` | `boolean` _(default: `false`)_ | | ||
| `adminNavigation?` | <code>[MenuItem](../Types/MenuItem)[]</code> | | ||
| `adminNavigation?` | <code>[MenuItem](../04-Types/MenuItem)[]</code> | | ||
| `adminNavigationHeader?` | `string` | | ||
| `adminNavigationURLSegment?` | `string` | | ||
| `adminButtonTooltipText?` | `string` | | ||
| `extras?` | <code>{ title: string; menuItems: ([Omit](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)<[MenuItem](../Types/MenuItem), 'children'\>)[] }[]</code> | | ||
| `extras?` | <code>{ title: string; menuItems: ([Omit](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)<[MenuItem](../04-Types/MenuItem), 'children'\>)[] }[]</code> | |
2 changes: 1 addition & 1 deletion
2
documentation/docs/api/_type-definitions/OrfiumProductsContextValue.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[`Product`](../Types/Product)`[] | null` | ||
[`Product`](../04-Types/Product)`[] | null` |
4 changes: 2 additions & 2 deletions
4
documentation/docs/api/_type-definitions/OrganizationsContextValue.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
| Name | Type | | ||
| :--------------------- | :--------------------------------------------------------------- | | ||
| `organizations` | <code>[Organization](../Types/Organization)[]</code> | | ||
| `selectedOrganization` | <code>[Organization](../Types/Organization)[] | null</code> | | ||
| `organizations` | <code>[Organization](../04-Types/Organization)[]</code> | | ||
| `selectedOrganization` | <code>[Organization](../04-Types/Organization)[] | null</code> | | ||
| `switchOrganization` | `(organisation: string) => void` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
| Name | Type | | ||
| :--------------- | :----------------------------------------------------------------------------------------- | | ||
| `path` | <code>string | string[]</code> | | ||
| `authorization?` | [`Authorization`](../Types/Authorization) | | ||
| `authorization?` | [`Authorization`](../04-Types/Authorization) | | ||
| `extraProps?` | `unknown` | | ||
| `component?` | <code>React.FunctionComponent<[RouteComponentProps](../Types/RouteComponentProps)\></code> | | ||
| `component?` | <code>React.FunctionComponent<[RouteComponentProps](../04-Types/RouteComponentProps)\></code> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
| Name | Type | | ||
| :-------------- | :---------------------------------------------------------------------------- | | ||
| `fallbackPaths` | <code>Partial<Record<[FallbackPath](../Types/FallbackPath), string\>\></code> | | ||
| `routes` | <code>[RouteItem](../Types/RouteItem)[]</code> | | ||
| `fallbackPaths` | <code>Partial<Record<[FallbackPath](../04-Types/FallbackPath), string\>\></code> | | ||
| `routes` | <code>[RouteItem](../04-Types/RouteItem)[]</code> | |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
export function formatToCurrency( | ||
value: number | string, | ||
currency = 'USD', | ||
options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'> | ||
) { | ||
if (typeof value === 'string' && isNaN(Number(value))) { | ||
throw 'A string value must be expressing a proper numeric value'; | ||
} | ||
|
||
return new Intl.NumberFormat('en-US', { | ||
...options, | ||
style: 'currency', | ||
currency: currency, | ||
// Per spec, Intl.NumberFormat.prototype.format can accept a string value, however TS is not allowing it. | ||
// Read this issue thread for more information: https://github.com/microsoft/TypeScript/issues/52124 | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
}).format(value); | ||
} | ||
export function formatToUSD( | ||
value: number | string, | ||
options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'> | ||
) { | ||
return formatToCurrency(value, 'USD', options); | ||
} | ||
|
||
export function formatToEUR( | ||
value: number | string, | ||
options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'> | ||
) { | ||
return formatToCurrency(value, 'EUR', options); | ||
} | ||
|
||
export function formatToGBP( | ||
value: number | string, | ||
options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'> | ||
) { | ||
return formatToCurrency(value, 'GBP', options); | ||
} | ||
|
||
export function formatToAUD( | ||
value: number | string, | ||
options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'> | ||
) { | ||
return formatToCurrency(value, 'AUD', options); | ||
} | ||
|
||
export function formatToCAD( | ||
value: number | string, | ||
options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'> | ||
) { | ||
return formatToCurrency(value, 'CAD', options); | ||
} | ||
|
||
export function formatToJPY( | ||
value: number | string, | ||
options?: Omit<Intl.NumberFormatOptions, 'currency' | 'style'> | ||
) { | ||
return formatToCurrency(value, 'JPY', options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters