Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/temp-module-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const ALLOWED_MODULES = new Set([
'DatabaseModule',
'DatatypeModule',
'DateModule',
'FinanceModule',
'FoodModule',
'GitModule',
'HackerModule',
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/finance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Currency } from '../modules/finance';
import type { Currency } from '../modules/finance/currency';
import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to finance.
Expand Down
13 changes: 4 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,20 @@ export type { DatabaseModule } from './modules/database';
export type { DatatypeModule } from './modules/datatype';
export type { DateModule, SimpleDateModule } from './modules/date';
export type {
BitcoinAddressFamilyType,
BitcoinNetworkType,
Currency,
FinanceModule,
VatNumberCountryCode,
} from './modules/finance';
export {
BitcoinAddressFamily,
BitcoinNetwork,
} from './modules/finance/_bitcoin';
export type {
BitcoinAddressFamilyType,
BitcoinNetworkType,
} from './modules/finance/_bitcoin';
export { BitcoinAddressFamily, BitcoinNetwork } from './modules/finance';
export type { FoodModule } from './modules/food';
export type { GitModule } from './modules/git';
export type { HackerModule } from './modules/hacker';
export type { HelpersModule, SimpleHelpersModule } from './modules/helpers';
export type { ImageModule } from './modules/image';
export { IPv4Network } from './modules/internet';
export type { IPv4NetworkType, InternetModule } from './modules/internet';
export type { InternetModule, IPv4NetworkType } from './modules/internet';
export type { LocationModule, SimpleLocationModule } from './modules/location';
export type { LoremModule } from './modules/lorem';
export type { MedicalModule } from './modules/medical';
Expand Down
72 changes: 0 additions & 72 deletions src/modules/finance/_bitcoin.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ interface Iban {
toDigitString: (str: string) => string;
}

const iban: Iban = {
/**
* The internal data required to generate IBANs.
*
* @internal
*/
export const ibanLib: Iban = {
alpha: [
'A',
'B',
Expand Down Expand Up @@ -1422,5 +1427,3 @@ const iban: Iban = {
String((match.toUpperCase().codePointAt(0) ?? Number.NaN) - 55)
),
};

export default iban;
21 changes: 21 additions & 0 deletions src/modules/finance/account-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { FakerCore } from '../../core';
import { arrayElement } from '../helpers/array-element';

/**
* Generates a random account name.
*
* @param fakerCore The FakerCore to use.
*
* @example
* accountName(fakerCore) // 'Personal Loan Account'
*
* @since 11.0.0
*
* @experimental
*/
export function accountName(fakerCore: FakerCore): string {
return [
arrayElement(fakerCore, fakerCore.locale.finance.account_type),
'Account',
].join(' ');
}
118 changes: 118 additions & 0 deletions src/modules/finance/account-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import type { FakerCore } from '../../core';
import { numeric } from '../string/numeric';

/**
* Generates a random account number.
*
* @param fakerCore The FakerCore to use.
* @param length The length of the account number. Defaults to `8`.
*
* @see stringNumeric(fakerCore): For generating the number with greater control.
*
* @example
* accountNumber(fakerCore) // '92842238'
* accountNumber(fakerCore, 5) // '32564'
*
* @since 11.0.0
*
* @experimental
*/
export function accountNumber(fakerCore: FakerCore, length?: number): string;
/**
* Generates a random account number.
*
* @param fakerCore The FakerCore to use.
* @param options An options object.
* @param options.length The length of the account number. Defaults to `8`.
*
* @see stringNumeric(fakerCore): For generating the number with greater control.
*
* @example
* accountNumber(fakerCore) // '92842238'
* accountNumber(fakerCore, { length: 5 }) // '32564'
*
* @since 11.0.0
*
* @experimental
*/
export function accountNumber(
fakerCore: FakerCore,
options?: {
/**
* The length of the account number.
*
* @default 8
*/
length?: number;
}
): string;
/**
* Generates a random account number.
*
* @param fakerCore The FakerCore to use.
* @param optionsOrLength An options object or the length of the account number.
* @param optionsOrLength.length The length of the account number. Defaults to `8`.
*
* @see stringNumeric(fakerCore): For generating the number with greater control.
*
* @example
* accountNumber(fakerCore) // '92842238'
* accountNumber(fakerCore, 5) // '28736'
* accountNumber(fakerCore, { length: 5 }) // '32564'
*
* @since 11.0.0
*
* @experimental
*/
export function accountNumber(
fakerCore: FakerCore,
optionsOrLength?:
| number
| {
/**
* The length of the account number.
*
* @default 8
*/
length?: number;
}
): string;
/**
* Generates a random account number.
*
* @param fakerCore The FakerCore to use.
* @param options An options object or the length of the account number.
* @param options.length The length of the account number. Defaults to `8`.
*
* @see stringNumeric(fakerCore): For generating the number with greater control.
*
* @example
* accountNumber(fakerCore) // '92842238'
* accountNumber(fakerCore, 5) // '28736'
* accountNumber(fakerCore, { length: 5 }) // '32564'
*
* @since 11.0.0
*
* @experimental
*/
export function accountNumber(
fakerCore: FakerCore,
options:
| number
| {
/**
* The length of the account number.
*
* @default 8
*/
length?: number;
} = {}
): string {
if (typeof options === 'number') {
options = { length: options };
}

const { length = 8 } = options;

return numeric(fakerCore, { length, allowLeadingZeros: true });
}
82 changes: 82 additions & 0 deletions src/modules/finance/amount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type { FakerCore } from '../../core';
import { float } from '../number/float';

/**
* Generates a random amount between the given bounds (inclusive).
*
* @param fakerCore The FakerCore to use.
* @param options An options object.
* @param options.min The lower bound for the amount. Defaults to `0`.
* @param options.max The upper bound for the amount. Defaults to `1000`.
* @param options.dec The number of decimal places for the amount. Defaults to `2`.
* @param options.symbol The symbol used to prefix the amount. Defaults to `''`.
* @param options.autoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`.
*
* @see numberFloat(fakerCore): For generating the amount with greater control.
*
* @example
* amount(fakerCore) // '617.87'
* amount(fakerCore, { min: 5, max: 10 }) // '5.53'
* amount(fakerCore, { min: 5, max: 10, dec: 0 }) // '8'
* amount(fakerCore, { min: 5, max: 10, dec: 2, symbol: '$' }) // '$5.85'
* amount(fakerCore, { min: 5, max: 10, dec: 5, symbol: '', autoFormat: true }) // '9,75067'
*
* @since 11.0.0
*
* @experimental
*/
export function amount(
fakerCore: FakerCore,
options: {
/**
* The lower bound for the amount.
*
* @default 0
*/
min?: number;
/**
* The upper bound for the amount.
*
* @default 1000
*/
max?: number;
/**
* The number of decimal places for the amount.
*
* @default 2
*/
dec?: number;
/**
* The symbol used to prefix the amount.
*
* @default ''
*/
symbol?: string;
/**
* If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`.
*
* @default false
*/
autoFormat?: boolean;
} = {}
): string {
const {
autoFormat = false,
dec = 2,
max = 1000,
min = 0,
symbol = '',
} = options;

const randValue = float(fakerCore, {
max,
min,
fractionDigits: dec,
});

const formattedString = autoFormat
? randValue.toLocaleString(undefined, { minimumFractionDigits: dec })
: randValue.toFixed(dec);

return symbol + formattedString;
}
Loading
Loading