diff options
| author | Matt Mayer <[email protected]> | 2023-02-27 06:17:03 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-27 00:17:03 +0100 |
| commit | 59157a429a1bcde3f78bd9009f6de02358365ba2 (patch) | |
| tree | ca173c137294eeba503bfdcf06359bb15ddf1c1c /src/modules | |
| parent | 11a5f51ddb4ab1163d770c4b12f5fe4711b8e11d (diff) | |
| download | faker-59157a429a1bcde3f78bd9009f6de02358365ba2.tar.xz faker-59157a429a1bcde3f78bd9009f6de02358365ba2.zip | |
feat(finance): currency object (#1809)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/finance/index.ts | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 8db5bfce..84b42077 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -3,6 +3,26 @@ import { FakerError } from '../../errors/faker-error'; import iban from './iban'; /** + * The possible definitions related to currency entries. + */ +export interface Currency { + /** + * The full name for the currency (e.g. `US Dollar`). + */ + name: string; + + /** + * The code/short text/abbreviation for the currency (e.g. `USD`). + */ + code: string; + + /** + * The symbol for the currency (e.g. `$`). + */ + symbol: string; +} + +/** * Module to generate finance related entries. */ export class FinanceModule { @@ -573,6 +593,25 @@ export class FinanceModule { } /** + * Returns a random currency object, containing `code`, `name `and `symbol` properties. + * + * @see + * faker.finance.currencyCode() + * faker.finance.currencyName() + * faker.finance.currencySymbol() + * + * @example + * faker.finance.currency() // { code: 'USD', name: 'US Dollar', symbol: '$' } + * + * @since 8.0.0 + */ + currency(): Currency { + return this.faker.helpers.arrayElement( + this.faker.definitions.finance.currency + ); + } + + /** * Returns a random currency code. * (The short text/abbreviation for the currency (e.g. `US Dollar` -> `USD`)) * @@ -582,9 +621,7 @@ export class FinanceModule { * @since 2.0.1 */ currencyCode(): string { - return this.faker.helpers.objectValue( - this.faker.definitions.finance.currency - )['code']; + return this.currency().code; } /** @@ -596,9 +633,7 @@ export class FinanceModule { * @since 2.0.1 */ currencyName(): string { - return this.faker.helpers.objectKey( - this.faker.definitions.finance.currency - ) as string; + return this.currency().name; } /** @@ -612,9 +647,7 @@ export class FinanceModule { currencySymbol(): string { let symbol: string; while (!symbol) { - symbol = this.faker.helpers.objectValue( - this.faker.definitions.finance.currency - )['symbol']; + symbol = this.currency().symbol; } return symbol; |
