diff options
| author | Shinigami <[email protected]> | 2024-02-18 23:56:40 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-18 23:56:40 +0100 |
| commit | 52b8992cbf960e001336d59b83c610845ff35860 (patch) | |
| tree | c71db76f3f955a74be4cbcbaa56df77375cb4531 /src | |
| parent | ec5609b18c79ea9fc8183ae78e917801e6a8a3f4 (diff) | |
| download | faker-52b8992cbf960e001336d59b83c610845ff35860.tar.xz faker-52b8992cbf960e001336d59b83c610845ff35860.zip | |
infra(unicorn): prefer-string-replace-all (#2653)
Diffstat (limited to 'src')
| -rw-r--r-- | src/modules/color/index.ts | 2 | ||||
| -rw-r--r-- | src/modules/finance/iban.ts | 2 | ||||
| -rw-r--r-- | src/modules/finance/index.ts | 2 | ||||
| -rw-r--r-- | src/modules/git/index.ts | 2 | ||||
| -rw-r--r-- | src/modules/helpers/index.ts | 8 | ||||
| -rw-r--r-- | src/modules/helpers/luhn-check.ts | 2 | ||||
| -rw-r--r-- | src/modules/internet/index.ts | 14 | ||||
| -rw-r--r-- | src/modules/location/index.ts | 4 | ||||
| -rw-r--r-- | src/modules/string/index.ts | 4 | ||||
| -rw-r--r-- | src/modules/system/index.ts | 5 |
10 files changed, 24 insertions, 21 deletions
diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index a9b39377..67344597 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -89,7 +89,7 @@ function toBinary(values: number[]): string { const buffer = new ArrayBuffer(4); new DataView(buffer).setFloat32(0, value); const bytes = new Uint8Array(buffer); - return toBinary([...bytes]).replace(/ /g, ''); + return toBinary([...bytes]).replaceAll(' ', ''); } return (value >>> 0).toString(2).padStart(8, '0'); diff --git a/src/modules/finance/iban.ts b/src/modules/finance/iban.ts index d639404c..b730d365 100644 --- a/src/modules/finance/iban.ts +++ b/src/modules/finance/iban.ts @@ -1407,7 +1407,7 @@ const iban: Iban = { pattern10: ['01', '02', '03', '04', '05', '06', '07', '08', '09'], pattern100: ['001', '002', '003', '004', '005', '006', '007', '008', '009'], toDigitString: (str) => - str.replace(/[A-Z]/gi, (match) => + str.replaceAll(/[A-Z]/gi, (match) => String((match.toUpperCase().codePointAt(0) ?? Number.NaN) - 55) ), }; diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index a19595d3..4013f99f 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -850,7 +850,7 @@ export class FinanceModule extends ModuleBase { format = this.faker.helpers.arrayElement(formats); } - format = format.replace(/\//g, ''); + format = format.replaceAll('/', ''); return this.faker.helpers.replaceCreditCardSymbols(format); } diff --git a/src/modules/git/index.ts b/src/modules/git/index.ts index 89ab4799..15cd21a3 100644 --- a/src/modules/git/index.ts +++ b/src/modules/git/index.ts @@ -94,7 +94,7 @@ export class GitModule extends ModuleBase { const email = this.faker.internet.email({ firstName, lastName }); // Normalize user according to https://github.com/libgit2/libgit2/issues/5342 - user = user.replace(/^[.,:;"\\']|[<>\n]|[.,:;"\\']$/g, ''); + user = user.replaceAll(/^[.,:;"\\']|[<>\n]|[.,:;"\\']$/g, ''); lines.push( `Author: ${user} <${email}>`, diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 635b3e09..73728f78 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -228,9 +228,9 @@ export class SimpleHelpersModule extends SimpleModuleBase { slugify(string: string = ''): string { return string .normalize('NFKD') //for example è decomposes to as e + ̀ - .replace(/[\u0300-\u036F]/g, '') // removes combining marks - .replace(/ /g, '-') // replaces spaces with hyphens - .replace(/[^\w.-]+/g, ''); // removes all non-word characters except for dots and hyphens + .replaceAll(/[\u0300-\u036F]/g, '') // removes combining marks + .replaceAll(' ', '-') // replaces spaces with hyphens + .replaceAll(/[^\w.-]+/g, ''); // removes all non-word characters except for dots and hyphens } /** @@ -797,7 +797,7 @@ export class SimpleHelpersModule extends SimpleModuleBase { let value = data[p]; if (typeof value === 'string') { // escape $, source: https://stackoverflow.com/a/6969486/6897682 - value = value.replace(/\$/g, '$$$$'); + value = value.replaceAll('$', '$$$$'); str = str.replace(re, value); } else { str = str.replace(re, value); diff --git a/src/modules/helpers/luhn-check.ts b/src/modules/helpers/luhn-check.ts index 42fbe1a5..fd7d54cc 100644 --- a/src/modules/helpers/luhn-check.ts +++ b/src/modules/helpers/luhn-check.ts @@ -24,7 +24,7 @@ export function luhnCheckValue(str: string): number { * @param str The string to generate the checksum for. */ function luhnChecksum(str: string): number { - str = str.replace(/[\s-]/g, ''); + str = str.replaceAll(/[\s-]/g, ''); let sum = 0; let alternate = false; for (let i = str.length - 1; i >= 0; i--) { diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 94851a53..86b03098 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -276,7 +276,7 @@ export class InternetModule extends ModuleBase { let localPart: string = this.userName({ firstName, lastName }); // Strip any special characters from the local part of the email address // This could happen if invalid chars are passed in manually in the firstName/lastName - localPart = localPart.replace(/[^A-Za-z0-9._+-]+/g, ''); + localPart = localPart.replaceAll(/[^A-Za-z0-9._+-]+/g, ''); // The local part of an email address is limited to 64 chars per RFC 3696 // We limit to 50 chars to be more realistic @@ -291,7 +291,7 @@ export class InternetModule extends ModuleBase { } // local parts may not contain two or more consecutive . characters - localPart = localPart.replace(/\.{2,}/g, '.'); + localPart = localPart.replaceAll(/\.{2,}/g, '.'); // local parts may not start with or end with a . character localPart = localPart.replace(/^\./, ''); @@ -661,7 +661,7 @@ export class InternetModule extends ModuleBase { // First remove simple accents etc result = result .normalize('NFKD') //for example è decomposes to as e + ̀ - .replace(/[\u0300-\u036F]/g, ''); // removes combining marks + .replaceAll(/[\u0300-\u036F]/g, ''); // removes combining marks result = [...result] .map((char) => { @@ -681,8 +681,8 @@ export class InternetModule extends ModuleBase { return charCode.toString(36); }) .join(''); - result = result.toString().replace(/'/g, ''); - result = result.replace(/ /g, ''); + result = result.toString().replaceAll("'", ''); + result = result.replaceAll(' ', ''); return result; } @@ -844,8 +844,8 @@ export class InternetModule extends ModuleBase { break; } - result = result.toString().replace(/'/g, ''); - result = result.replace(/ /g, ''); + result = result.toString().replaceAll("'", ''); + result = result.replaceAll(' ', ''); return result; } diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 0c94317b..54766d8a 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -178,7 +178,7 @@ export class LocationModule extends ModuleBase { buildingNumber(): string { return this.faker.helpers .arrayElement(this.faker.definitions.location.building_number) - .replace(/#+/g, (m) => + .replaceAll(/#+/g, (m) => this.faker.string.numeric({ length: m.length, allowLeadingZeros: false, @@ -274,7 +274,7 @@ export class LocationModule extends ModuleBase { secondaryAddress(): string { return this.faker.helpers .arrayElement(this.faker.definitions.location.secondary_address) - .replace(/#+/g, (m) => + .replaceAll(/#+/g, (m) => this.faker.string.numeric({ length: m.length, allowLeadingZeros: false, diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index 6428153d..8b3cbd26 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -692,8 +692,8 @@ export class StringModule extends SimpleModuleBase { */ uuid(): string { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' - .replace(/x/g, () => this.faker.number.hex({ min: 0x0, max: 0xf })) - .replace(/y/g, () => this.faker.number.hex({ min: 0x8, max: 0xb })); + .replaceAll('x', () => this.faker.number.hex({ min: 0x0, max: 0xf })) + .replaceAll('y', () => this.faker.number.hex({ min: 0x8, max: 0xb })); } /** diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts index 52fc14f5..ee0d2600 100644 --- a/src/modules/system/index.ts +++ b/src/modules/system/index.ts @@ -72,7 +72,10 @@ export class SystemModule extends ModuleBase { ): string { const { extensionCount = 1 } = options; - const baseName = this.faker.word.words().toLowerCase().replace(/\W/g, '_'); + const baseName = this.faker.word + .words() + .toLowerCase() + .replaceAll(/\W/g, '_'); const extensionsStr = this.faker.helpers .multiple(() => this.fileExt(), { count: extensionCount }) |
