Skip to content

Commit

Permalink
feat(finance): use fake patterns for transactionDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Dec 2, 2024
1 parent ecb5cb4 commit c7b2116
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/definitions/finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ export type FinanceDefinition = LocaleEntry<{
* Types of transactions (e.g. `deposit`).
*/
transaction_type: string[];

/**
* The pattern used to generate transaction descriptions.
*/
transaction_description_pattern: string[];
}>;
2 changes: 2 additions & 0 deletions src/locales/en/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type { FinanceDefinition } from '../../..';
import account_type from './account_type';
import credit_card from './credit_card';
import currency from './currency';
import transaction_description_pattern from './transaction_description_pattern';
import transaction_type from './transaction_type';

const finance: FinanceDefinition = {
account_type,
credit_card,
currency,
transaction_description_pattern,
transaction_type,
};

Expand Down
13 changes: 13 additions & 0 deletions src/locales/en/finance/transaction_description_pattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default [
'A {{finance.transactionType}} for {{finance.currencyCode}} {{finance.amount}} was made at {{company.name}} via card ending ****{{string.numeric(4)}} on account ***{{string.numeric(4)}}.',
'A {{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} occurred at {{company.name}} using a card ending in ****{{string.numeric(4)}} for account ***{{string.numeric(4)}}.',
'Payment of {{finance.currencyCode}} {{finance.amount}} for {{finance.transactionType}} at {{company.name}}, processed with card ending ****{{string.numeric(4)}} linked to account ***{{string.numeric(4)}}.',
'Transaction alert: {{finance.transactionType}} at {{company.name}} using card ending ****{{string.numeric(4)}} for an amount of {{finance.currencyCode}} {{finance.amount}} on account ***{{string.numeric(4)}}.',
'You made a {{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} at {{company.name}} using card ending in ****{{string.numeric(4)}} from account ***{{string.numeric(4)}}.',
'Your {{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} at {{company.name}} was successful. Charged via card ****{{string.numeric(4)}} to account ***{{string.numeric(4)}}.',
'{{finance.transactionType}} at {{company.name}} with a card ending in ****{{string.numeric(4)}} for {{finance.currencyCode}} {{finance.amount}} from account ***{{string.numeric(4)}}.',
'{{finance.transactionType}} confirmed at {{company.name}} for {{finance.currencyCode}} {{finance.amount}}, card ending in ****{{string.numeric(4)}} associated with account ***{{string.numeric(4)}}.',
'{{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} at {{company.name}} charged to account ending in {{string.numeric(4)}} using card ending in ****{{string.numeric(4)}}.',
'{{finance.transactionType}} processed at {{company.name}} for {{finance.currencyCode}} {{finance.amount}}, using card ending ****{{string.numeric(4)}}. Account: ***{{string.numeric(4)}}.',
'{{finance.transactionType}} transaction at {{company.name}} using card ending with ****{{string.numeric(4)}} for {{finance.currencyCode}} {{finance.amount}} in account ***{{string.numeric(4)}}.',
];
13 changes: 4 additions & 9 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,18 +969,13 @@ export class FinanceModule extends ModuleBase {
*
* @example
* faker.finance.transactionDescription()
* // 'invoice transaction at Kilback - Durgan using card ending with ************4316 for UAH 783.82 in account ***16168663'
* // 'payment transaction at Emard LLC using card ending with ****9187 for HNL 506.57 in account ***2584.'
*
* @since 5.1.0
*/
transactionDescription(): string {
const amount = this.amount();
const company = this.faker.company.name();
const transactionType = this.transactionType();
const account = this.accountNumber();
const card = this.creditCardNumber().replaceAll(/.(?=.{4})/g, '*');
const currency = this.currencyCode();

return `${transactionType} transaction at ${company} using card ending with ${card} for ${currency} ${amount} in account ***${account}`;
return this.faker.helpers.fake(
this.faker.definitions.finance.transaction_description_pattern
);
}
}

0 comments on commit c7b2116

Please sign in to comment.