Skip to content

Commit

Permalink
refactor(finance): simplify maskedNumber implementation (#2493)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Oct 28, 2023
1 parent fdafaa4 commit 3ab23b5
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,23 +350,17 @@ export class FinanceModule {
options = { length: options };
}

// set defaults
const { ellipsis, length = 4, parens } = options;

// create a template for length
let template = '';
let template = this.faker.string.numeric({ length });

for (let i = 0; i < length; i++) {
template = `${template}#`;
if (ellipsis) {
template = `...${template}`;
}

//prefix with ellipsis
template = ellipsis ? ['...', template].join('') : template;

template = parens ? ['(', template, ')'].join('') : template;

//generate random numbers
template = this.faker.helpers.replaceSymbolWithNumber(template);
if (parens) {
template = `(${template})`;
}

return template;
}
Expand Down

0 comments on commit 3ab23b5

Please sign in to comment.