aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2024-11-12 09:15:03 +0100
committerGitHub <[email protected]>2024-11-12 09:15:03 +0100
commitcb4b77c04f4d4a706819a6f34ff8378afec6523e (patch)
tree5553bdcf0d965e6aa81bd4ccb5e1218dcfa7ae35
parent9abaed1061b5fa9dc9f93822162610105a788296 (diff)
downloadfaker-cb4b77c04f4d4a706819a6f34ff8378afec6523e.tar.xz
faker-cb4b77c04f4d4a706819a6f34ff8378afec6523e.zip
refactor(finance): deprecate maskedNumber for removal (#3201)
-rw-r--r--src/modules/finance/index.ts23
-rw-r--r--test/modules/__snapshots__/finance.spec.ts.snap6
-rw-r--r--test/modules/finance.spec.ts3
3 files changed, 26 insertions, 6 deletions
diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts
index 0e9a6883..656872b7 100644
--- a/src/modules/finance/index.ts
+++ b/src/modules/finance/index.ts
@@ -1,4 +1,5 @@
import { FakerError } from '../../errors/faker-error';
+import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';
import type { BitcoinAddressFamilyType, BitcoinNetworkType } from './bitcoin';
import {
@@ -202,6 +203,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber(3) // '(...342)'
*
* @since 8.0.0
+ *
+ * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(length?: number): string;
/**
@@ -219,6 +222,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
*
* @since 8.0.0
+ *
+ * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(options?: {
/**
@@ -256,6 +261,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
*
* @since 8.0.0
+ *
+ * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(
optionsOrLength?:
@@ -297,6 +304,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
*
* @since 8.0.0
+ *
+ * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(
options:
@@ -322,6 +331,14 @@ export class FinanceModule extends ModuleBase {
ellipsis?: boolean;
} = {}
): string {
+ deprecated({
+ deprecated: 'faker.finance.maskedNumber()',
+ proposed:
+ "faker.finance.iban().replace(/(?<=.{4})\\w(?=.{2})/g, '*') or a similar approach",
+ since: '9.3.0',
+ until: '10.0.0',
+ });
+
if (typeof options === 'number') {
options = { length: options };
}
@@ -952,7 +969,7 @@ 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'
+ * // 'invoice transaction at Kilback - Durgan using card ending with ************4316 for UAH 783.82 in account ***16168663'
*
* @since 5.1.0
*/
@@ -961,9 +978,9 @@ export class FinanceModule extends ModuleBase {
const company = this.faker.company.name();
const transactionType = this.transactionType();
const account = this.accountNumber();
- const card = this.maskedNumber();
+ 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 `${transactionType} transaction at ${company} using card ending with ${card} for ${currency} ${amount} in account ***${account}`;
}
}
diff --git a/test/modules/__snapshots__/finance.spec.ts.snap b/test/modules/__snapshots__/finance.spec.ts.snap
index 1312820a..5ac691cf 100644
--- a/test/modules/__snapshots__/finance.spec.ts.snap
+++ b/test/modules/__snapshots__/finance.spec.ts.snap
@@ -84,7 +84,7 @@ exports[`finance > 42 > pin > with length option 1`] = `"3975110867"`;
exports[`finance > 42 > routingNumber 1`] = `"397511082"`;
-exports[`finance > 42 > transactionDescription 1`] = `"deposit transaction at Reynolds, Miller and Crist using card ending with ***(...1135) for KES 374.54 in account ***08670982"`;
+exports[`finance > 42 > transactionDescription 1`] = `"deposit transaction at Reynolds, Miller and Crist using card ending with ************4719 for LYD 374.54 in account ***08670982"`;
exports[`finance > 42 > transactionType 1`] = `"invoice"`;
@@ -172,7 +172,7 @@ exports[`finance > 1211 > pin > with length option 1`] = `"9829667368"`;
exports[`finance > 1211 > routingNumber 1`] = `"982966738"`;
-exports[`finance > 1211 > transactionDescription 1`] = `"payment transaction at Fahey, Zieme and Osinski using card ending with ***(...8825) for CRC 928.52 in account ***73687684"`;
+exports[`finance > 1211 > transactionDescription 1`] = `"payment transaction at Fahey, Zieme and Osinski using card ending with ***************2758 for HNL 928.52 in account ***73687684"`;
exports[`finance > 1211 > transactionType 1`] = `"withdrawal"`;
@@ -260,6 +260,6 @@ exports[`finance > 1337 > pin > with length option 1`] = `"2124352971"`;
exports[`finance > 1337 > routingNumber 1`] = `"212435298"`;
-exports[`finance > 1337 > transactionDescription 1`] = `"invoice transaction at Gottlieb - Koelpin using card ending with ***(...9477) for HUF 262.02 in account ***52971361"`;
+exports[`finance > 1337 > transactionDescription 1`] = `"invoice transaction at Gottlieb - Koelpin using card ending with *********6413 for JMD 262.02 in account ***52971361"`;
exports[`finance > 1337 > transactionType 1`] = `"invoice"`;
diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts
index ee19b17a..eab50d94 100644
--- a/test/modules/finance.spec.ts
+++ b/test/modules/finance.spec.ts
@@ -158,6 +158,7 @@ describe('finance', () => {
describe('maskedNumber()', () => {
it('should return contain parenthesis, ellipsis and have a length of 4 by default', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
const actual = faker.finance.maskedNumber();
expect(actual).toMatch(/\(\.{3}\d{4}\)/);
@@ -165,6 +166,7 @@ describe('finance', () => {
it('should set a default length', () => {
const expected = 4; // default account mask length
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
const mask = faker.finance.maskedNumber({
parens: false,
ellipsis: false,
@@ -179,6 +181,7 @@ describe('finance', () => {
it('should set a specified length', () => {
const expected = faker.number.int({ min: 1, max: 20 });
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
const mask = faker.finance.maskedNumber({
length: expected,
parens: false,