aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-10-21 08:58:18 +0200
committerGitHub <[email protected]>2023-10-21 06:58:18 +0000
commitf222448cabedee3e8ac4f64f8003df0954de2913 (patch)
treef78bc0a84b356f4a91292e33ee34b47c889f45db /src
parent85403819af2c47e4f9d24c66ca34c844a6151bdb (diff)
downloadfaker-f222448cabedee3e8ac4f64f8003df0954de2913.tar.xz
faker-f222448cabedee3e8ac4f64f8003df0954de2913.zip
infra(unicorn): prefer-number-properties (#2452)
Diffstat (limited to 'src')
-rw-r--r--src/modules/commerce/index.ts4
-rw-r--r--src/modules/date/index.ts2
-rw-r--r--src/modules/helpers/index.ts31
-rw-r--r--src/modules/helpers/luhn-check.ts2
4 files changed, 21 insertions, 18 deletions
diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts
index 2464af03..18147dcb 100644
--- a/src/modules/commerce/index.ts
+++ b/src/modules/commerce/index.ts
@@ -382,7 +382,7 @@ export class CommerceModule {
const [group, groupRules] =
this.faker.helpers.objectEntry(ISBN_LENGTH_RULES);
const element = this.faker.string.numeric(8);
- const elementValue = parseInt(element.slice(0, -1));
+ const elementValue = Number.parseInt(element.slice(0, -1));
const registrantLength = groupRules.find(
([rangeMaximum]) => elementValue <= rangeMaximum
@@ -401,7 +401,7 @@ export class CommerceModule {
let checksum = 0;
for (let i = 0; i < variant - 1; i++) {
const weight = variant === 10 ? i + 1 : i % 2 ? 3 : 1;
- checksum += weight * parseInt(isbn[i]);
+ checksum += weight * Number.parseInt(isbn[i]);
}
checksum = variant === 10 ? checksum % 11 : (10 - (checksum % 10)) % 10;
diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts
index 8f7efaae..e93be54d 100644
--- a/src/modules/date/index.ts
+++ b/src/modules/date/index.ts
@@ -16,7 +16,7 @@ function toDate(
fallback: () => Date
): Date {
date = new Date(date);
- if (isNaN(date.valueOf())) {
+ if (Number.isNaN(date.valueOf())) {
date = fallback();
}
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts
index 81007156..4c64be4e 100644
--- a/src/modules/helpers/index.ts
+++ b/src/modules/helpers/index.ts
@@ -62,11 +62,11 @@ function getRepetitionsBasedOnQuantifierParameters(
}
} else if (quantifierMin != null && quantifierMax != null) {
repetitions = faker.number.int({
- min: parseInt(quantifierMin),
- max: parseInt(quantifierMax),
+ min: Number.parseInt(quantifierMin),
+ max: Number.parseInt(quantifierMax),
});
} else if (quantifierMin != null && quantifierMax == null) {
- repetitions = parseInt(quantifierMin);
+ repetitions = Number.parseInt(quantifierMin);
}
return repetitions;
@@ -108,8 +108,8 @@ function legacyRegexpStringParse(
let repetitions: number;
let token = RANGE_REP_REG.exec(string);
while (token != null) {
- min = parseInt(token[2]);
- max = parseInt(token[3]);
+ min = Number.parseInt(token[2]);
+ max = Number.parseInt(token[3]);
// switch min and max
if (min > max) {
tmp = max;
@@ -128,7 +128,7 @@ function legacyRegexpStringParse(
// Deal with repeat `{num}`
token = REP_REG.exec(string);
while (token != null) {
- repetitions = parseInt(token[2]);
+ repetitions = Number.parseInt(token[2]);
string =
string.slice(0, token.index) +
token[1].repeat(repetitions) +
@@ -139,8 +139,8 @@ function legacyRegexpStringParse(
token = RANGE_REG.exec(string);
while (token != null) {
- min = parseInt(token[1]); // This time we are not capturing the char before `[]`
- max = parseInt(token[2]);
+ min = Number.parseInt(token[1]); // This time we are not capturing the char before `[]`
+ max = Number.parseInt(token[2]);
// switch min and max
if (min > max) {
tmp = max;
@@ -462,7 +462,7 @@ export class SimpleHelpersModule {
while (range != null) {
if (!range[0].includes('-')) {
// handle non-ranges
- if (isCaseInsensitive && isNaN(Number(range[0]))) {
+ if (isCaseInsensitive && Number.isNaN(Number(range[0]))) {
rangeCodes.push(
range[0].toUpperCase().charCodeAt(0),
range[0].toLowerCase().charCodeAt(0)
@@ -481,7 +481,10 @@ export class SimpleHelpersModule {
}
for (let i = min; i <= max; i++) {
- if (isCaseInsensitive && isNaN(Number(String.fromCharCode(i)))) {
+ if (
+ isCaseInsensitive &&
+ Number.isNaN(Number(String.fromCharCode(i)))
+ ) {
const ch = String.fromCharCode(i);
rangeCodes.push(
ch.toUpperCase().charCodeAt(0),
@@ -556,8 +559,8 @@ export class SimpleHelpersModule {
// Deal with quantifier ranges `{min,max}`
token = RANGE_REP_REG.exec(pattern);
while (token != null) {
- min = parseInt(token[2]);
- max = parseInt(token[3]);
+ min = Number.parseInt(token[2]);
+ max = Number.parseInt(token[3]);
// throw error if min larger than max
if (min > max) {
throw new FakerError('Numbers out of order in {} quantifier.');
@@ -575,7 +578,7 @@ export class SimpleHelpersModule {
// Deal with repeat `{num}`
token = REP_REG.exec(pattern);
while (token != null) {
- repetitions = parseInt(token[2]);
+ repetitions = Number.parseInt(token[2]);
pattern =
pattern.slice(0, token.index) +
token[1].repeat(repetitions) +
@@ -1046,7 +1049,7 @@ export class SimpleHelpersModule {
): T[keyof T] {
// ignore numeric keys added by TypeScript
const keys: Array<keyof T> = Object.keys(enumObject).filter((key) =>
- isNaN(Number(key))
+ Number.isNaN(Number(key))
);
const randomKey = this.arrayElement(keys);
return enumObject[randomKey];
diff --git a/src/modules/helpers/luhn-check.ts b/src/modules/helpers/luhn-check.ts
index 7d841878..ba68b41d 100644
--- a/src/modules/helpers/luhn-check.ts
+++ b/src/modules/helpers/luhn-check.ts
@@ -28,7 +28,7 @@ function luhnChecksum(str: string): number {
let sum = 0;
let alternate = false;
for (let i = str.length - 1; i >= 0; i--) {
- let n = parseInt(str.substring(i, i + 1));
+ let n = Number.parseInt(str.substring(i, i + 1));
if (alternate) {
n *= 2;
if (n > 9) {