diff options
| author | ST-DDT <[email protected]> | 2023-11-23 20:03:32 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-23 20:03:32 +0100 |
| commit | 9b00fe9f7353df50c67966141a5f024ec9b95208 (patch) | |
| tree | 685ac4468b0e89855ef5f8fe45f299f2b3416080 /src/modules | |
| parent | aff0f8022d30a132a6945efac44c22688b5fb5b8 (diff) | |
| download | faker-9b00fe9f7353df50c67966141a5f024ec9b95208.tar.xz faker-9b00fe9f7353df50c67966141a5f024ec9b95208.zip | |
infra(unicorn): prefer-code-point (#2509)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/finance/iban.ts | 2 | ||||
| -rw-r--r-- | src/modules/helpers/index.ts | 20 | ||||
| -rw-r--r-- | src/modules/internet/index.ts | 8 | ||||
| -rw-r--r-- | src/modules/string/index.ts | 2 |
4 files changed, 18 insertions, 14 deletions
diff --git a/src/modules/finance/iban.ts b/src/modules/finance/iban.ts index 8b3f78c4..d639404c 100644 --- a/src/modules/finance/iban.ts +++ b/src/modules/finance/iban.ts @@ -1408,7 +1408,7 @@ const iban: Iban = { pattern100: ['001', '002', '003', '004', '005', '006', '007', '008', '009'], toDigitString: (str) => str.replace(/[A-Z]/gi, (match) => - String(match.toUpperCase().charCodeAt(0) - 55) + String((match.toUpperCase().codePointAt(0) ?? Number.NaN) - 55) ), }; diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 3f121a41..aaf0e231 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -458,7 +458,9 @@ export class SimpleHelpersModule extends SimpleModuleBase { while (range != null) { if (range[0].includes('-')) { // handle ranges - const rangeMinMax = range[0].split('-').map((x) => x.charCodeAt(0)); + const rangeMinMax = range[0] + .split('-') + .map((x) => x.codePointAt(0) ?? Number.NaN); min = rangeMinMax[0]; max = rangeMinMax[1]; // throw error if min larger than max @@ -469,12 +471,12 @@ export class SimpleHelpersModule extends SimpleModuleBase { for (let i = min; i <= max; i++) { if ( isCaseInsensitive && - Number.isNaN(Number(String.fromCharCode(i))) + Number.isNaN(Number(String.fromCodePoint(i))) ) { - const ch = String.fromCharCode(i); + const ch = String.fromCodePoint(i); rangeCodes.push( - ch.toUpperCase().charCodeAt(0), - ch.toLowerCase().charCodeAt(0) + ch.toUpperCase().codePointAt(0) ?? Number.NaN, + ch.toLowerCase().codePointAt(0) ?? Number.NaN ); } else { rangeCodes.push(i); @@ -484,11 +486,11 @@ export class SimpleHelpersModule extends SimpleModuleBase { // handle non-ranges if (isCaseInsensitive && Number.isNaN(Number(range[0]))) { rangeCodes.push( - range[0].toUpperCase().charCodeAt(0), - range[0].toLowerCase().charCodeAt(0) + range[0].toUpperCase().codePointAt(0) ?? Number.NaN, + range[0].toLowerCase().codePointAt(0) ?? Number.NaN ); } else { - rangeCodes.push(range[0].charCodeAt(0)); + rangeCodes.push(range[0].codePointAt(0) ?? Number.NaN); } } @@ -540,7 +542,7 @@ export class SimpleHelpersModule extends SimpleModuleBase { } const generatedString = this.multiple( - () => String.fromCharCode(this.arrayElement(rangeCodes)), + () => String.fromCodePoint(this.arrayElement(rangeCodes)), { count: repetitions } ).join(''); diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 8367825f..395266fb 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -660,13 +660,15 @@ export class InternetModule extends ModuleBase { return charMapping[char]; } - if (char.charCodeAt(0) < 0x80) { + const charCode = char.codePointAt(0) ?? Number.NaN; + + if (charCode < 0x80) { // Keep ASCII characters return char; } // Final fallback return the Unicode char code value for Chinese, Japanese, Korean etc, base-36 encoded - return char.charCodeAt(0).toString(36); + return charCode.toString(36); }) .join(''); result = result.toString().replace(/'/g, ''); @@ -1495,7 +1497,7 @@ export class InternetModule extends ModuleBase { } const n = this.faker.number.int(94) + 33; - let char = String.fromCharCode(n); + let char = String.fromCodePoint(n); if (memorable) { char = char.toLowerCase(); } diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index 4240a6f1..6428153d 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -674,7 +674,7 @@ export class StringModule extends SimpleModuleBase { let returnString = ''; while (returnString.length < length) { - returnString += String.fromCharCode( + returnString += String.fromCodePoint( this.faker.number.int(charCodeOption) ); } |
