aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Kuczynski <[email protected]>2022-04-19 22:38:17 +0200
committerGitHub <[email protected]>2022-04-19 22:38:17 +0200
commit00b9d4be4bff3b3f64edf163768af71c99bceed1 (patch)
tree0fa0e76b036c11c38eea251a8c4d371875810eed
parentcb746cb466743a219c0e3845edb29527a06b0a35 (diff)
downloadfaker-00b9d4be4bff3b3f64edf163768af71c99bceed1.tar.xz
faker-00b9d4be4bff3b3f64edf163768af71c99bceed1.zip
chore: prefer string templates over string concatenation (#732)
-rw-r--r--.eslintrc.js1
-rw-r--r--scripts/apidoc/apiDocsWriter.ts6
-rw-r--r--scripts/apidoc/signature.ts33
-rw-r--r--scripts/generateLocales.ts9
-rw-r--r--scripts/verifyCommit.ts20
-rw-r--r--src/address.ts6
-rw-r--r--src/commerce.ts8
-rw-r--r--src/datatype.ts2
-rw-r--r--src/fake.ts4
-rw-r--r--src/finance.ts40
-rw-r--r--src/git.ts2
-rw-r--r--src/helpers.ts2
-rw-r--r--src/image.ts2
-rw-r--r--src/image_providers/lorempicsum.ts4
-rw-r--r--src/image_providers/lorempixel.ts2
-rw-r--r--src/image_providers/unsplash.ts4
-rw-r--r--src/internal/deprecated.ts2
-rw-r--r--src/internet.ts56
-rw-r--r--src/lorem.ts2
-rw-r--r--src/mersenne.ts4
-rw-r--r--src/name.ts8
-rw-r--r--src/system.ts13
-rw-r--r--src/utils/user-agent.ts51
-rw-r--r--test/all_functional.spec.ts8
-rw-r--r--test/finance_iban.spec.ts140
25 files changed, 203 insertions, 226 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
index 5423bc46..70b2861f 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -29,6 +29,7 @@ module.exports = defineConfig({
// We may want to use this in the future
'no-useless-escape': 'off',
eqeqeq: ['error', 'always', { null: 'ignore' }],
+ 'prefer-template': 'error',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/consistent-type-imports': 'error',
diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts
index f712e4aa..cb803499 100644
--- a/scripts/apidoc/apiDocsWriter.ts
+++ b/scripts/apidoc/apiDocsWriter.ts
@@ -64,7 +64,7 @@ export function writeApiDocsModulePage(
content = vitePressInFileOptions + formatMarkdown(content);
- writeFileSync(resolve(pathOutputDir, lowerModuleName + '.md'), content);
+ writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.md`), content);
}
/**
@@ -87,7 +87,7 @@ export function writeApiDocsDirectPage(methodName: string): void {
content = vitePressInFileOptions + formatMarkdown(content);
- writeFileSync(resolve(pathOutputDir, methodName + '.md'), content);
+ writeFileSync(resolve(pathOutputDir, `${methodName}.md`), content);
}
/**
@@ -111,7 +111,7 @@ export const ${lowerModuleName}: Method[] = ${JSON.stringify(
contentTs = formatTypescript(contentTs);
- writeFileSync(resolve(pathOutputDir, lowerModuleName + '.ts'), contentTs);
+ writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.ts`), contentTs);
}
/**
diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts
index 0341d7c0..704c4dad 100644
--- a/scripts/apidoc/signature.ts
+++ b/scripts/apidoc/signature.ts
@@ -29,7 +29,7 @@ export function prettifyMethodName(method: string): string {
export function toBlock(comment?: Comment): string {
return (
(comment?.shortText.trim() || 'Missing') +
- (comment?.text ? '\n\n' + comment.text : '')
+ (comment?.text ? `\n\n${comment.text}` : '')
);
}
@@ -116,11 +116,11 @@ export function analyzeSignature(
try {
let example = JSON.stringify(faker[moduleName][methodName]());
if (example.length > 50) {
- example = example.substring(0, 47) + '...';
+ example = `${example.substring(0, 47)}...`;
}
examples += `faker.${moduleName}.${methodName}()`;
- examples += (example ? ` // => ${example}` : '') + '\n';
+ examples += `${example ? ` // => ${example}` : ''}\n`;
} catch (error) {
// Ignore the error => hide the example call + result.
}
@@ -131,7 +131,7 @@ export function analyzeSignature(
.map((tag) => tag.text.trimEnd()) || [];
if (exampleTags.length > 0) {
- examples += exampleTags.join('\n').trim() + '\n';
+ examples += `${exampleTags.join('\n').trim()}\n`;
}
const seeAlsos =
@@ -140,13 +140,15 @@ export function analyzeSignature(
.map((t) => t.text.trim()) ?? [];
const prettyMethodName = prettifyMethodName(methodName);
+ const code = '```';
+
return {
name: methodName,
title: prettyMethodName,
description: mdToHtml(toBlock(signature.comment)),
parameters: parameters,
returns: typeToText(signature.type),
- examples: mdToHtml('```ts\n' + examples + '```'),
+ examples: mdToHtml(`${code}ts\n${examples}${code}`),
deprecated: signature.comment?.hasTag('deprecated') ?? false,
seeAlsos,
};
@@ -164,10 +166,10 @@ function analyzeParameter(parameter: ParameterReflection): {
let signatureText = '';
if (defaultValue) {
- signatureText = ' = ' + defaultValue;
+ signatureText = ` = ${defaultValue}`;
}
- const signature = declarationName + ': ' + typeToText(type) + signatureText;
+ const signature = `${declarationName}: ${typeToText(type)}${signatureText}`;
const parameters: MethodParameter[] = [
{
@@ -256,27 +258,28 @@ function declarationTypeToText(
switch (declaration.kind) {
case ReflectionKind.Method:
return signatureTypeToText(declaration.signatures[0]);
+
case ReflectionKind.Property:
return typeToText(declaration.type);
+
case ReflectionKind.TypeLiteral:
if (declaration.children?.length) {
if (short) {
// This is too long for the parameter table, thus we abbreviate this.
return '{ ... }';
}
- return (
- '{' +
- declaration.children
- .map((c) => `\n${c.name}: ${declarationTypeToText(c)}`)
- .join()
- .replace(/\n/g, '\n ') +
- '\n}'
- );
+
+ const list = declaration.children
+ .map((c) => ` ${c.name}: ${declarationTypeToText(c)}`)
+ .join(',\n');
+
+ return `{\n${list}\n}`;
} else if (declaration.signatures?.length) {
return signatureTypeToText(declaration.signatures[0]);
} else {
return declaration.toString();
}
+
default:
return declaration.toString();
}
diff --git a/scripts/generateLocales.ts b/scripts/generateLocales.ts
index f4c1f50d..38715b97 100644
--- a/scripts/generateLocales.ts
+++ b/scripts/generateLocales.ts
@@ -101,7 +101,7 @@ function generateLocaleFile(locale: string): void {
`;
content = format(content, prettierTsOptions);
- writeFileSync(resolve(pathLocale, locale + '.ts'), content);
+ writeFileSync(resolve(pathLocale, `${locale}.ts`), content);
}
function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
@@ -253,7 +253,7 @@ function updateLocaleFileHook(
localePath: string[]
): void {
if (filePath === 'never') {
- console.log(filePath + ' <-> ' + locale + ' @ ' + localePath.join(' -> '));
+ console.log(`${filePath} <-> ${locale} @ ${localePath.join(' -> ')}`);
}
}
@@ -285,13 +285,14 @@ for (const locale of locales) {
generateLocaleFile(locale);
// src/locales/**/index.ts
+ const separator = localeSeparator ? `\nseparator: '${localeSeparator}',` : '';
+
generateRecursiveModuleIndexes(
pathModules,
locale,
'LocaleDefinition',
1,
- `title: '${localeTitle}',` +
- (localeSeparator ? `\nseparator: '${localeSeparator}',` : '')
+ `title: '${localeTitle}',${separator}`
);
}
diff --git a/scripts/verifyCommit.ts b/scripts/verifyCommit.ts
index e2c4ae70..11f22ab4 100644
--- a/scripts/verifyCommit.ts
+++ b/scripts/verifyCommit.ts
@@ -18,16 +18,22 @@ const isMergeCommit = msg.startsWith('Merge remote-tracking-branch');
if (!isMergeCommit && !releaseRE.test(msg) && !commitRE.test(msg)) {
console.log();
+
console.error(
` ${colors.bgRed(colors.white(' ERROR '))} ${colors.red(
`invalid commit message format.`
- )}\n\n` +
- colors.red(
- ` Proper commit message format is required for automated changelog generation. Examples:\n\n`
- ) +
- ` ${colors.green(`feat: add 'comments' option`)}\n` +
- ` ${colors.green(`fix: handle events on blur (close #28)`)}\n\n` +
- colors.red(` See .github/commit-convention.md for more details.\n`)
+ )}
+
+ ${colors.red(
+ `Proper commit message format is required for automated changelog generation. Examples:`
+ )}
+
+ ${colors.green(`feat: add 'comments' option`)}
+ ${colors.green(`fix: handle events on blur (close #28)`)}
+
+ ${colors.red(`See .github/commit-convention.md for more details.`)}
+`
);
+
process.exit(1);
}
diff --git a/src/address.ts b/src/address.ts
index 83fa675b..e0fb6bf2 100644
--- a/src/address.ts
+++ b/src/address.ts
@@ -230,7 +230,7 @@ export class Address {
let result: string;
let suffix = this.streetSuffix();
if (suffix !== '') {
- suffix = ' ' + suffix;
+ suffix = ` ${suffix}`;
}
switch (this.faker.datatype.number(1)) {
@@ -381,7 +381,7 @@ export class Address {
.number({
min,
max,
- precision: parseFloat((0.0).toPrecision(precision) + '1'),
+ precision: parseFloat(`${(0.0).toPrecision(precision)}1`),
})
.toFixed(precision);
}
@@ -406,7 +406,7 @@ export class Address {
.number({
max: max,
min: min,
- precision: parseFloat((0.0).toPrecision(precision) + '1'),
+ precision: parseFloat(`${(0.0).toPrecision(precision)}1`),
})
.toFixed(precision);
}
diff --git a/src/commerce.ts b/src/commerce.ts
index a94d7b85..9d0a5731 100644
--- a/src/commerce.ts
+++ b/src/commerce.ts
@@ -45,13 +45,7 @@ export class Commerce {
* faker.commerce.productName() // 'Incredible Soft Gloves'
*/
productName(): string {
- return (
- this.productAdjective() +
- ' ' +
- this.productMaterial() +
- ' ' +
- this.product()
- );
+ return `${this.productAdjective()} ${this.productMaterial()} ${this.product()}`;
}
/**
diff --git a/src/datatype.ts b/src/datatype.ts
index 29a4950b..90211b69 100644
--- a/src/datatype.ts
+++ b/src/datatype.ts
@@ -243,7 +243,7 @@ export class Datatype {
]);
}
- return '0x' + wholeString;
+ return `0x${wholeString}`;
}
/**
diff --git a/src/fake.ts b/src/fake.ts
index d478d01e..4a22e2ff 100644
--- a/src/fake.ts
+++ b/src/fake.ts
@@ -89,11 +89,11 @@ export class Fake {
const parts = method.split('.');
if (this.faker[parts[0]] == null) {
- throw new FakerError('Invalid module: ' + parts[0]);
+ throw new FakerError(`Invalid module: ${parts[0]}`);
}
if (this.faker[parts[0]][parts[1]] == null) {
- throw new FakerError('Invalid method: ' + parts[0] + '.' + parts[1]);
+ throw new FakerError(`Invalid method: ${parts[0]}.${parts[1]}`);
}
// assign the function from the module.function namespace
diff --git a/src/finance.ts b/src/finance.ts
index ea4174d6..2214088d 100644
--- a/src/finance.ts
+++ b/src/finance.ts
@@ -96,7 +96,7 @@ export class Finance {
let template = '';
for (let i = 0; i < length; i++) {
- template = template + '#';
+ template = `${template}#`;
}
//prefix with ellipsis
@@ -332,7 +332,7 @@ export class Finance {
: this.faker.random.arrayElement(iban.formats);
if (!ibanFormat) {
- throw new FakerError('Country code ' + countryCode + ' not supported.');
+ throw new FakerError(`Country code ${countryCode} not supported.`);
}
let s = '';
@@ -387,20 +387,21 @@ export class Finance {
bic(): string {
const vowels = ['A', 'E', 'I', 'O', 'U'];
const prob = this.faker.datatype.number(100);
- return (
- this.faker.helpers.replaceSymbols('???') +
- this.faker.random.arrayElement(vowels) +
- this.faker.random.arrayElement(iban.iso3166) +
- this.faker.helpers.replaceSymbols('?') +
- '1' +
- (prob < 10
+
+ return [
+ this.faker.helpers.replaceSymbols('???'),
+ this.faker.random.arrayElement(vowels),
+ this.faker.random.arrayElement(iban.iso3166),
+ this.faker.helpers.replaceSymbols('?'),
+ '1',
+ prob < 10
? this.faker.helpers.replaceSymbols(
- '?' + this.faker.random.arrayElement(vowels) + '?'
+ `?${this.faker.random.arrayElement(vowels)}?`
)
: prob < 40
? this.faker.helpers.replaceSymbols('###')
- : '')
- );
+ : '',
+ ].join('');
}
/**
@@ -418,18 +419,7 @@ export class Finance {
const company = transaction.business;
const card = this.mask();
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/src/git.ts b/src/git.ts
index 6c82e48d..94144043 100644
--- a/src/git.ts
+++ b/src/git.ts
@@ -42,7 +42,7 @@ export class Git {
branch(): string {
const noun = this.faker.hacker.noun().replace(' ', '-');
const verb = this.faker.hacker.verb().replace(' ', '-');
- return noun + '-' + verb;
+ return `${noun}-${verb}`;
}
/**
diff --git a/src/helpers.ts b/src/helpers.ts
index 5b26bd9d..be3ce8f5 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -481,7 +481,7 @@ export class Helpers {
return '';
}
for (const p in data) {
- const re = new RegExp('{{' + p + '}}', 'g');
+ const re = new RegExp(`{{${p}}}`, 'g');
const value = data[p];
if (typeof value === 'string') {
str = str.replace(re, value);
diff --git a/src/image.ts b/src/image.ts
index 2f4444ab..8aeab602 100644
--- a/src/image.ts
+++ b/src/image.ts
@@ -104,7 +104,7 @@ export class Image {
}
let url = `${protocol}loremflickr.com/${width}/${height}`;
if (category != null) {
- url += '/' + category;
+ url += `/${category}`;
}
if (randomize) {
diff --git a/src/image_providers/lorempicsum.ts b/src/image_providers/lorempicsum.ts
index 9fed741e..f28b1e8f 100644
--- a/src/image_providers/lorempicsum.ts
+++ b/src/image_providers/lorempicsum.ts
@@ -104,7 +104,7 @@ export class LoremPicsum {
let url = 'https://picsum.photos';
if (seed) {
- url += '/seed/' + seed;
+ url += `/seed/${seed}`;
}
url += `/${width}/${height}`;
@@ -114,7 +114,7 @@ export class LoremPicsum {
}
if (grayscale) {
- return url + '?grayscale';
+ return `${url}?grayscale`;
}
if (blur) {
diff --git a/src/image_providers/lorempixel.ts b/src/image_providers/lorempixel.ts
index 310ba45a..914f1066 100644
--- a/src/image_providers/lorempixel.ts
+++ b/src/image_providers/lorempixel.ts
@@ -67,7 +67,7 @@ export class Lorempixel {
let url = `https://lorempixel.com/${width}/${height}`;
if (category != null) {
- url += '/' + category;
+ url += `/${category}`;
}
if (randomize) {
diff --git a/src/image_providers/unsplash.ts b/src/image_providers/unsplash.ts
index dd8abd37..994b2a04 100644
--- a/src/image_providers/unsplash.ts
+++ b/src/image_providers/unsplash.ts
@@ -59,7 +59,7 @@ export class Unsplash {
let url = 'https://source.unsplash.com';
if (category != null) {
- url += '/category/' + category;
+ url += `/category/${category}`;
}
url += `/${width}x${height}`;
@@ -67,7 +67,7 @@ export class Unsplash {
if (keyword != null) {
const keywordFormat = /^([A-Za-z0-9].+,[A-Za-z0-9]+)$|^([A-Za-z0-9]+)$/;
if (keywordFormat.test(keyword)) {
- url += '?' + keyword;
+ url += `?${keyword}`;
}
}
diff --git a/src/internal/deprecated.ts b/src/internal/deprecated.ts
index 7f20c24f..ab67b60a 100644
--- a/src/internal/deprecated.ts
+++ b/src/internal/deprecated.ts
@@ -25,5 +25,5 @@ export function deprecated(opts: DeprecatedOptions): void {
message += `. Please use ${opts.proposed} instead`;
}
- console.warn(message + '.');
+ console.warn(`${message}.`);
}
diff --git a/src/internet.ts b/src/internet.ts
index 7e9b72a4..fa4ae6e8 100644
--- a/src/internet.ts
+++ b/src/internet.ts
@@ -67,9 +67,11 @@ export class Internet {
this.faker.random.arrayElement(
this.faker.definitions.internet.free_email
);
+
let localPart: string = this.faker.helpers.slugify(
this.userName(firstName, lastName)
);
+
if (options?.allowSpecialCharacters) {
const usernameChars: string[] = '._-'.split('');
const specialChars: string[] = ".!#$%&'*+-/=?^_`{|}~".split('');
@@ -78,6 +80,7 @@ export class Internet {
this.faker.random.arrayElement(specialChars)
);
}
+
return `${localPart}@${provider}`;
}
@@ -184,7 +187,7 @@ export class Internet {
* faker.internet.url() // 'https://remarkable-hackwork.info'
*/
url(): string {
- return this.protocol() + '://' + this.domainName();
+ return `${this.protocol()}://${this.domainName()}`;
}
/**
@@ -194,7 +197,7 @@ export class Internet {
* faker.internet.domainName() // 'slow-timer.info'
*/
domainName(): string {
- return this.domainWord() + '.' + this.domainSuffix();
+ return `${this.domainWord()}.${this.domainSuffix()}`;
}
/**
@@ -218,7 +221,7 @@ export class Internet {
* faker.internet.domainWord() // 'weird-cytoplasm'
*/
domainWord(): string {
- return (this.faker.word.adjective() + '-' + this.faker.word.noun())
+ return `${this.faker.word.adjective()}-${this.faker.word.noun()}`
.replace(/([\\~#&*{}/:<>?|\"'])/gi, '')
.replace(/\s/g, '-')
.replace(/-{2,}/g, '-')
@@ -316,41 +319,34 @@ export class Internet {
}
/**
- * Generates a random css hex color code.
+ * Generates a random css hex color code in aesthetically pleasing color palette.
*
- * @param baseRed255 The optional base red. Used for aesthetically pleasing color palettes. Supports values between `0` and `255`. Defaults to `0`.
- * @param baseGreen255 The optional base green. Used for aesthetically pleasing color palettes. Supports values between `0` and `255`. Defaults to `0`.
- * @param baseBlue255 The optional base blue. Used for aesthetically pleasing color palettes. Supports values between `0` and `255`. Defaults to `0`.
+ * Based on
+ * http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette
+ *
+ * @param redBase The optional base red in range between `0` and `255`. Defaults to `0`.
+ * @param greenBase The optional base green in range between `0` and `255`. Defaults to `0`.
+ * @param blueBase The optional base blue in range between `0` and `255`. Defaults to `0`.
*
* @example
* faker.internet.color() // '#30686e'
* faker.internet.color(100, 100, 100) // '#4e5f8b'
*/
color(
- baseRed255: number = 0,
- baseGreen255: number = 0,
- baseBlue255: number = 0
+ redBase: number = 0,
+ greenBase: number = 0,
+ blueBase: number = 0
): string {
- // based on awesome response : http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette
- const red = Math.floor((this.faker.datatype.number(256) + baseRed255) / 2);
- const green = Math.floor(
- (this.faker.datatype.number(256) + baseGreen255) / 2
- );
- const blue = Math.floor(
- (this.faker.datatype.number(256) + baseBlue255) / 2
- );
- const redStr = red.toString(16);
- const greenStr = green.toString(16);
- const blueStr = blue.toString(16);
- return (
- '#' +
- (redStr.length === 1 ? '0' : '') +
- redStr +
- (greenStr.length === 1 ? '0' : '') +
- greenStr +
- (blueStr.length === 1 ? '0' : '') +
- blueStr
- );
+ const colorFromBase = (base: number): string =>
+ Math.floor((this.faker.datatype.number(256) + base) / 2)
+ .toString(16)
+ .padStart(2, '0');
+
+ const red = colorFromBase(redBase);
+ const green = colorFromBase(greenBase);
+ const blue = colorFromBase(blueBase);
+
+ return `#${red}${green}${blue}`;
}
/**
diff --git a/src/lorem.ts b/src/lorem.ts
index 103dd6a7..14cc2f6b 100644
--- a/src/lorem.ts
+++ b/src/lorem.ts
@@ -67,7 +67,7 @@ export class Lorem {
}
const sentence = this.words(wordCount);
- return sentence.charAt(0).toUpperCase() + sentence.slice(1) + '.';
+ return `${sentence.charAt(0).toUpperCase() + sentence.slice(1)}.`;
}
/**
diff --git a/src/mersenne.ts b/src/mersenne.ts
index 21f52f6c..c8f531f2 100644
--- a/src/mersenne.ts
+++ b/src/mersenne.ts
@@ -48,7 +48,7 @@ export class Mersenne {
seed(S: number): void {
if (typeof S !== 'number') {
throw new FakerError(
- 'seed(S) must take numeric argument; is ' + typeof S
+ `seed(S) must take numeric argument; is ${typeof S}`
);
}
@@ -64,7 +64,7 @@ export class Mersenne {
seed_array(A: number[]): void {
if (typeof A !== 'object') {
throw new FakerError(
- 'seed_array(A) must take array of numbers; is ' + typeof A
+ `seed_array(A) must take array of numbers; is ${typeof A}`
);
}
diff --git a/src/name.ts b/src/name.ts
index b96eb8db..41a6075a 100644
--- a/src/name.ts
+++ b/src/name.ts
@@ -213,18 +213,18 @@ export class Name {
case 0:
prefix = this.prefix(gender);
if (prefix) {
- return prefix + ' ' + firstName + ' ' + lastName;
+ return `${prefix} ${firstName} ${lastName}`;
}
// TODO @Shinigami92 2022-01-21: Not sure if this fallthrough is wanted
// eslint-disable-next-line no-fallthrough
case 1:
suffix = this.suffix();
if (suffix) {
- return firstName + ' ' + lastName + ' ' + suffix;
+ return `${firstName} ${lastName} ${suffix}`;
}
}
- return firstName + ' ' + lastName;
+ return `${firstName} ${lastName}`;
}
/**
@@ -309,7 +309,7 @@ export class Name {
* faker.name.jobTitle() // 'Global Accounts Engineer'
*/
jobTitle(): string {
- return this.jobDescriptor() + ' ' + this.jobArea() + ' ' + this.jobType();
+ return `${this.jobDescriptor()} ${this.jobArea()} ${this.jobType()}`;
}
/**
diff --git a/src/system.ts b/src/system.ts
index 16ddd876..05d0bf44 100644
--- a/src/system.ts
+++ b/src/system.ts
@@ -54,9 +54,9 @@ export class System {
* faker.system.fileName() // 'self_enabling_accountability_toys.kpt'
*/
fileName(): string {
- let str = this.faker.random.words();
- str = str.toLowerCase().replace(/\W/g, '_') + '.' + this.fileExt();
- return str;
+ const str = this.faker.random.words().toLowerCase().replace(/\W/g, '_');
+
+ return `${str}.${this.fileExt()}`;
}
/**
@@ -68,10 +68,9 @@ export class System {
* faker.system.commonFileName('txt') // 'global_borders_wyoming.txt'
*/
commonFileName(ext?: string): string {
- let str = this.faker.random.words();
- str = str.toLowerCase().replace(/\W/g, '_');
- str += '.' + (ext || this.commonFileExt());
- return str;
+ const str = this.faker.random.words().toLowerCase().replace(/\W/g, '_');
+
+ return `${str}.${ext || this.commonFileExt()}`;
}
/**
diff --git a/src/utils/user-agent.ts b/src/utils/user-agent.ts
index 7f7e8cbb..5ff18c2a 100644
--- a/src/utils/user-agent.ts
+++ b/src/utils/user-agent.ts
@@ -267,23 +267,19 @@ export function generate(faker: Faker): string {
firefox(arch: Arch): string {
//https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
const firefox_ver = `${rnd(5, 15)}${randomRevision(2)}`,
- gecko_ver = 'Gecko/20100101 Firefox/' + firefox_ver,
+ gecko_ver = `Gecko/20100101 Firefox/${firefox_ver}`,
proc = randomProc(arch),
os_ver =
arch === 'win'
- ? '(Windows NT ' + version_string.nt() + (proc ? `; ${proc}` : '')
+ ? `(Windows NT ${version_string.nt()}${proc ? `; ${proc}` : ''}`
: arch === 'mac'
? `(Macintosh; ${proc} Mac OS X ${version_string.osx()}`
: `(X11; Linux ${proc}`;
- return (
- 'Mozilla/5.0 ' +
- os_ver +
- '; rv:' +
- firefox_ver.slice(0, -2) +
- ') ' +
- gecko_ver
- );
+ return `Mozilla/5.0 ${os_ver}; rv:${firefox_ver.slice(
+ 0,
+ -2
+ )}) ${gecko_ver}`;
},
iexplorer(): string {
@@ -299,18 +295,13 @@ export function generate(faker: Faker): string {
//http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx
return `Mozilla/5.0 (compatible; MSIE ${ver}.0; Windows NT ${version_string.nt()}; Trident/${version_string.trident()}${
- rnd(0, 1) === 1 ? '; .NET CLR ' + version_string.net() : ''
+ rnd(0, 1) === 1 ? `; .NET CLR ${version_string.net()}` : ''
})`;
},
opera(arch: Arch): string {
//http://www.opera.com/docs/history/
- const presto_ver =
- ' Presto/' +
- version_string.presto() +
- ' Version/' +
- version_string.presto2() +
- ')',
+ const presto_ver = ` Presto/${version_string.presto()} Version/${version_string.presto2()})`,
os_ver =
arch === 'win'
? `(Windows NT ${version_string.nt()}; U; ${randomLang()}${presto_ver}`
@@ -329,18 +320,9 @@ export function generate(faker: Faker): string {
? `(Macintosh; ${randomProc('mac')} Mac OS X ${version_string.osx(
'_'
)} rv:${rnd(2, 6)}.0; ${randomLang()}) `
- : '(Windows; U; Windows NT ' + version_string.nt() + ')';
+ : `(Windows; U; Windows NT ${version_string.nt()})`;
- return (
- 'Mozilla/5.0 ' +
- os_ver +
- 'AppleWebKit/' +
- safari +
- ' (KHTML, like Gecko) Version/' +
- ver +
- ' Safari/' +
- safari
- );
+ return `Mozilla/5.0 ${os_ver}AppleWebKit/${safari} (KHTML, like Gecko) Version/${ver} Safari/${safari}`;
},
chrome(arch: Arch): string {
@@ -351,19 +333,10 @@ export function generate(faker: Faker): string {
'_'
)}) `
: arch === 'win'
- ? '(Windows; U; Windows NT ' + version_string.nt() + ')'
+ ? `(Windows; U; Windows NT ${version_string.nt()})`
: `(X11; Linux ${randomProc(arch)}`;
- return (
- 'Mozilla/5.0 ' +
- os_ver +
- ' AppleWebKit/' +
- safari +
- ' (KHTML, like Gecko) Chrome/' +
- version_string.chrome() +
- ' Safari/' +
- safari
- );
+ return `Mozilla/5.0 ${os_ver} AppleWebKit/${safari} (KHTML, like Gecko) Chrome/${version_string.chrome()} Safari/${safari}`;
},
};
diff --git a/test/all_functional.spec.ts b/test/all_functional.spec.ts
index a307e1fc..756749af 100644
--- a/test/all_functional.spec.ts
+++ b/test/all_functional.spec.ts
@@ -85,11 +85,11 @@ describe('functional tests', () => {
};
if (isWorkingLocaleForMethod(module, meth, locale)) {
- it(meth + '()', testAssertion);
+ it(`${meth}()`, testAssertion);
} else {
// TODO ST-DDT 2022-03-28: Remove once there are no more failures
// We expect a failure here to ensure we remove the exclusions when fixed
- it.fails(meth + '()', testAssertion);
+ it.fails(`${meth}()`, testAssertion);
}
});
});
@@ -104,11 +104,11 @@ describe('faker.fake functional tests', () => {
Object.keys(modules).forEach((module) => {
describe(module, () => {
modules[module].forEach((meth) => {
- it(meth + '()', () => {
+ it(`${meth}()`, () => {
faker.locale = locale;
// TODO ST-DDT 2022-03-28: Use random seed once there are no more failures
faker.seed(1);
- const result = faker.fake('{{' + module + '.' + meth + '}}');
+ const result = faker.fake(`{{${module}.${meth}}}`);
expect(result).toBeTypeOf('string');
});
diff --git a/test/finance_iban.spec.ts b/test/finance_iban.spec.ts
index c777e797..64de0504 100644
--- a/test/finance_iban.spec.ts
+++ b/test/finance_iban.spec.ts
@@ -49,27 +49,31 @@ describe('finance_iban', () => {
expect(
iban.substring(0, 2),
- iban.substring(0, 2) +
- ' must contains only characters in GE IBAN ' +
- ibanFormatted
+ `${iban.substring(
+ 0,
+ 2
+ )} must contains only characters in GE IBAN ${ibanFormatted}`
).match(/^[A-Z]{2}$/);
expect(
iban.substring(2, 4),
- iban.substring(2, 4) +
- ' must contains only digit in GE IBAN ' +
- ibanFormatted
+ `${iban.substring(
+ 2,
+ 4
+ )} must contains only digit in GE IBAN ${ibanFormatted}`
).match(/^\d{2}$/);
expect(
iban.substring(4, 6),
- iban.substring(4, 6) +
- ' must contains only characters in GE IBAN ' +
- ibanFormatted
+ `${iban.substring(
+ 4,
+ 6
+ )} must contains only characters in GE IBAN ${ibanFormatted}`
).match(/^[A-Z]{2}$/);
expect(
iban.substring(6, 24),
- iban.substring(6, 24) +
- ' must contains only characters in GE IBAN ' +
- ibanFormatted
+ `${iban.substring(
+ 6,
+ 24
+ )} must contains only characters in GE IBAN ${ibanFormatted}`
).match(/^\d{16}$/);
expect(
@@ -105,27 +109,31 @@ describe('finance_iban', () => {
expect(
iban.substring(0, 2),
- iban.substring(0, 2) +
- ' must contains only characters in PK IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 0,
+ 2
+ )} must contains only characters in PK IBAN ${ibanFormated}`
).match(/^[A-Z]{2}$/);
expect(
iban.substring(2, 4),
- iban.substring(2, 4) +
- ' must contains only digit in PK IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 2,
+ 4
+ )} must contains only digit in PK IBAN ${ibanFormated}`
).match(/^\d{2}$/);
expect(
iban.substring(4, 8),
- iban.substring(4, 8) +
- ' must contains only characters in PK IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 4,
+ 8
+ )} must contains only characters in PK IBAN ${ibanFormated}`
).match(/^[A-Z]{4}$/);
expect(
iban.substring(8, 24),
- iban.substring(8, 24) +
- ' must contains only digits in PK IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 8,
+ 24
+ )} must contains only digits in PK IBAN ${ibanFormated}`
).match(/^\d{16}$/);
expect(
@@ -167,43 +175,43 @@ describe('finance_iban', () => {
expect(
iban.substring(0, 2),
- 'Country Code:' +
- iban.substring(0, 2) +
- ' must contains only characters in PK IBAN ' +
- ibanFormated
+ `Country Code:${iban.substring(
+ 0,
+ 2
+ )} must contains only characters in PK IBAN ${ibanFormated}`
).match(/^[A-Z]{2}$/);
expect(
iban.substring(2, 4),
- 'Control key:' +
- iban.substring(2, 4) +
- ' must contains only digit in PK IBAN ' +
- ibanFormated
+ `Control key:${iban.substring(
+ 2,
+ 4
+ )} must contains only digit in PK IBAN ${ibanFormated}`
).match(/^\d{2}$/);
expect(
iban.substring(4, 9),
- 'Swift Bank Code:' +
- iban.substring(4, 9) +
- ' must contains only digits in PK IBAN ' +
- ibanFormated
+ `Swift Bank Code:${iban.substring(
+ 4,
+ 9
+ )} must contains only digits in PK IBAN ${ibanFormated}`
).match(/^\d{5}$/);
expect(
iban.substring(9, 10),
- 'National Digit:' +
- iban.substring(9, 10) +
- ' must contains only digits in PK IBAN ' +
- ibanFormated
+ `National Digit:${iban.substring(
+ 9,
+ 10
+ )} must contains only digits in PK IBAN ${ibanFormated}`
).match(/^\d{1}$/);
expect(
iban.substring(10, 26),
- 'Account Code:' +
- iban.substring(10, 26) +
- ' must contains only digits in PK IBAN ' +
- ibanFormated
+ `Account Code:${iban.substring(
+ 10,
+ 26
+ )} must contains only digits in PK IBAN ${ibanFormated}`
).match(/^\d{16}$/);
expect(
iban.substring(2, 26),
- 'No character after TR ' + ibanFormated
+ `No character after TR ${ibanFormated}`
).match(/^\d{24}$/);
expect(
@@ -237,27 +245,31 @@ describe('finance_iban', () => {
expect(
iban.substring(0, 2),
- iban.substring(0, 2) +
- ' must contains only characters in AZ IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 0,
+ 2
+ )} must contains only characters in AZ IBAN ${ibanFormated}`
).match(/^[A-Z]{2}$/);
expect(
iban.substring(2, 4),
- iban.substring(2, 4) +
- ' must contains only digit in AZ IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 2,
+ 4
+ )} must contains only digit in AZ IBAN ${ibanFormated}`
).match(/^\d{2}$/);
expect(
iban.substring(4, 8),
- iban.substring(4, 8) +
- ' must contains only characters in AZ IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 4,
+ 8
+ )} must contains only characters in AZ IBAN ${ibanFormated}`
).match(/^[A-Z]{4}$/);
expect(
iban.substring(8, 28),
- iban.substring(8, 28) +
- ' must contains 20 characters in AZ IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 8,
+ 28
+ )} must contains 20 characters in AZ IBAN ${ibanFormated}`
).match(/^\d{20}$/);
expect(
@@ -292,16 +304,18 @@ describe('finance_iban', () => {
expect(
iban.substring(0, 2),
- iban.substring(0, 2) +
- "must start with 'CR' in CR IBAN " +
- ibanFormated
+ `${iban.substring(
+ 0,
+ 2
+ )}must start with 'CR' in CR IBAN ${ibanFormated}`
).to.eq('CR');
expect(
iban.substring(2, 22),
- iban.substring(2, 22) +
- ' must contains only digit in AZ IBAN ' +
- ibanFormated
+ `${iban.substring(
+ 2,
+ 22
+ )} must contains only digit in AZ IBAN ${ibanFormated}`
).match(/^\d{20}$/);
expect(