aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-04-08 19:57:29 +0200
committerGitHub <[email protected]>2022-04-08 19:57:29 +0200
commit753ab66ff5e2fe0d622c4c1722f5213be1ab0315 (patch)
tree937daaaa5d56bca12a6ee473ed25a538c0f68440 /src
parent3b5a21f3aae52f263f2c91e763fcee613092166c (diff)
downloadfaker-753ab66ff5e2fe0d622c4c1722f5213be1ab0315.tar.xz
faker-753ab66ff5e2fe0d622c4c1722f5213be1ab0315.zip
chore: use consistent method calls (#817)
Diffstat (limited to 'src')
-rw-r--r--src/address.ts6
-rw-r--r--src/commerce.ts6
-rw-r--r--src/company.ts15
-rw-r--r--src/datatype.ts23
-rw-r--r--src/finance.ts4
-rw-r--r--src/helpers.ts16
-rw-r--r--src/image.ts26
-rw-r--r--src/internet.ts12
-rw-r--r--src/lorem.ts16
-rw-r--r--src/name.ts8
-rw-r--r--src/random.ts14
-rw-r--r--src/system.ts9
12 files changed, 67 insertions, 88 deletions
diff --git a/src/address.ts b/src/address.ts
index 5c862f5c..83fa675b 100644
--- a/src/address.ts
+++ b/src/address.ts
@@ -128,7 +128,7 @@ export class Address {
if (zipRange) {
return String(this.faker.datatype.number(zipRange));
}
- return this.faker.address.zipCode();
+ return this.zipCode();
}
/**
@@ -228,7 +228,7 @@ export class Address {
*/
streetName(): string {
let result: string;
- let suffix = this.faker.address.streetSuffix();
+ let suffix = this.streetSuffix();
if (suffix !== '') {
suffix = ' ' + suffix;
}
@@ -498,7 +498,7 @@ export class Address {
): [string, string] {
// If there is no coordinate, the best we can do is return a random GPS coordinate.
if (coordinate === undefined) {
- return [this.faker.address.latitude(), this.faker.address.longitude()];
+ return [this.latitude(), this.longitude()];
}
radius = radius || 10.0;
diff --git a/src/commerce.ts b/src/commerce.ts
index 79c485b2..a94d7b85 100644
--- a/src/commerce.ts
+++ b/src/commerce.ts
@@ -46,11 +46,11 @@ export class Commerce {
*/
productName(): string {
return (
- this.faker.commerce.productAdjective() +
+ this.productAdjective() +
' ' +
- this.faker.commerce.productMaterial() +
+ this.productMaterial() +
' ' +
- this.faker.commerce.product()
+ this.product()
);
}
diff --git a/src/company.ts b/src/company.ts
index e0d4721f..67d70199 100644
--- a/src/company.ts
+++ b/src/company.ts
@@ -1,15 +1,10 @@
import type { Faker } from '.';
-import type { Fake } from './fake';
-
-let f: Fake['fake'];
/**
* Module to generate company related entries.
*/
export class Company {
constructor(private readonly faker: Faker) {
- f = this.faker.fake;
-
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Company.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
@@ -49,7 +44,7 @@ export class Company {
format = this.faker.datatype.number(formats.length - 1);
}
- return f(formats[format]);
+ return this.faker.fake(formats[format]);
}
/**
@@ -59,7 +54,7 @@ export class Company {
* faker.company.companySuffix() // 'and Sons'
*/
companySuffix(): string {
- return this.faker.random.arrayElement(this.faker.company.suffixes());
+ return this.faker.random.arrayElement(this.suffixes());
}
/**
@@ -69,7 +64,7 @@ export class Company {
* faker.company.catchPhrase() // 'Upgradable systematic flexibility'
*/
catchPhrase(): string {
- return f(
+ return this.faker.fake(
'{{company.catchPhraseAdjective}} {{company.catchPhraseDescriptor}} {{company.catchPhraseNoun}}'
);
}
@@ -81,7 +76,9 @@ export class Company {
* faker.company.bs() // 'cultivate synergistic e-markets'
*/
bs(): string {
- return f('{{company.bsBuzz}} {{company.bsAdjective}} {{company.bsNoun}}');
+ return this.faker.fake(
+ '{{company.bsBuzz}} {{company.bsAdjective}} {{company.bsNoun}}'
+ );
}
/**
diff --git a/src/datatype.ts b/src/datatype.ts
index 50bcb17f..7e4a3cc1 100644
--- a/src/datatype.ts
+++ b/src/datatype.ts
@@ -92,7 +92,7 @@ export class Datatype {
if (opts.precision == null) {
opts.precision = 0.01;
}
- return this.faker.datatype.number(opts);
+ return this.number(opts);
}
/**
@@ -121,7 +121,7 @@ export class Datatype {
max = Date.UTC(2100, 0);
}
- return new Date(this.faker.datatype.number({ min, max }));
+ return new Date(this.number({ min, max }));
}
/**
@@ -147,9 +147,7 @@ export class Datatype {
let returnString = '';
for (let i = 0; i < length; i++) {
- returnString += String.fromCharCode(
- this.faker.datatype.number(charCodeOption)
- );
+ returnString += String.fromCharCode(this.number(charCodeOption));
}
return returnString;
@@ -164,7 +162,7 @@ export class Datatype {
uuid(): string {
const RFC4122_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
const replacePlaceholders = (placeholder) => {
- const random = this.faker.datatype.number({ min: 0, max: 15 });
+ const random = this.number({ min: 0, max: 15 });
const value = placeholder === 'x' ? random : (random & 0x3) | 0x8;
return value.toString(16);
};
@@ -178,7 +176,7 @@ export class Datatype {
* faker.datatype.boolean() // false
*/
boolean(): boolean {
- return !!this.faker.datatype.number(1);
+ return !!this.number(1);
}
/**
@@ -258,9 +256,7 @@ export class Datatype {
const returnObject: Record<string, string | number> = {};
properties.forEach((prop) => {
- returnObject[prop] = this.faker.datatype.boolean()
- ? this.faker.datatype.string()
- : this.faker.datatype.number();
+ returnObject[prop] = this.boolean() ? this.string() : this.number();
});
return JSON.stringify(returnObject);
@@ -277,9 +273,7 @@ export class Datatype {
*/
array(length = 10): Array<string | number> {
return Array.from<string | number>({ length }).map(() =>
- this.faker.datatype.boolean()
- ? this.faker.datatype.string()
- : this.faker.datatype.number()
+ this.boolean() ? this.string() : this.number()
);
}
@@ -297,8 +291,7 @@ export class Datatype {
*/
bigInt(value?: string | number | bigint | boolean): bigint {
if (value === undefined) {
- value =
- Math.floor(this.faker.datatype.number() * 99999999999) + 10000000000;
+ value = Math.floor(this.number() * 99999999999) + 10000000000;
}
return BigInt(value);
diff --git a/src/finance.ts b/src/finance.ts
index 2d1da8cc..ea4174d6 100644
--- a/src/finance.ts
+++ b/src/finance.ts
@@ -416,8 +416,8 @@ export class Finance {
const amount = transaction.amount;
const transactionType = transaction.type;
const company = transaction.business;
- const card = this.faker.finance.mask();
- const currency = this.faker.finance.currencyCode();
+ const card = this.mask();
+ const currency = this.currencyCode();
return (
transactionType +
' transaction at ' +
diff --git a/src/helpers.ts b/src/helpers.ts
index e451eaab..5b26bd9d 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -295,8 +295,8 @@ export class Helpers {
return sum % 10;
};
- string = this.faker.helpers.regexpStyleStringParse(string); // replace [4-9] with a random number in range etc...
- string = this.faker.helpers.replaceSymbolWithNumber(string, symbol); // replace ### with random numbers
+ string = this.regexpStyleStringParse(string); // replace [4-9] with a random number in range etc...
+ string = this.replaceSymbolWithNumber(string, symbol); // replace ### with random numbers
const numberList = string
.replace(/\D/g, '')
@@ -364,7 +364,7 @@ export class Helpers {
repetitions = this.faker.datatype.number({ min: min, max: max });
string =
string.slice(0, token.index) +
- this.faker.helpers.repeatString(token[1], repetitions) +
+ this.repeatString(token[1], repetitions) +
string.slice(token.index + token[0].length);
token = string.match(RANGE_REP_REG);
}
@@ -374,7 +374,7 @@ export class Helpers {
repetitions = parseInt(token[2]);
string =
string.slice(0, token.index) +
- this.faker.helpers.repeatString(token[1], repetitions) +
+ this.repeatString(token[1], repetitions) +
string.slice(token.index + token[0].length);
token = string.match(REP_REG);
}
@@ -444,7 +444,7 @@ export class Helpers {
if (Array.isArray(source)) {
const set = new Set<T>(source);
const array = Array.from(set);
- return this.faker.helpers.shuffle(array).splice(0, length);
+ return this.shuffle(array).splice(0, length);
}
const set = new Set<T>();
try {
@@ -559,9 +559,9 @@ export class Helpers {
},
],
accountHistory: [
- this.faker.helpers.createTransaction(),
- this.faker.helpers.createTransaction(),
- this.faker.helpers.createTransaction(),
+ this.createTransaction(),
+ this.createTransaction(),
+ this.createTransaction(),
],
};
}
diff --git a/src/image.ts b/src/image.ts
index fc8eaf15..2f4444ab 100644
--- a/src/image.ts
+++ b/src/image.ts
@@ -127,7 +127,7 @@ export class Image {
* faker.image.abstract(1234, 2345, true) // 'http://loremflickr.com/1234/2345/abstract?56789'
*/
abstract(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'abstract', randomize);
+ return this.imageUrl(width, height, 'abstract', randomize);
}
/**
@@ -143,7 +143,7 @@ export class Image {
* faker.image.animals(1234, 2345, true) // 'http://loremflickr.com/1234/2345/animals?56789'
*/
animals(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'animals', randomize);
+ return this.imageUrl(width, height, 'animals', randomize);
}
/**
@@ -159,7 +159,7 @@ export class Image {
* faker.image.business(1234, 2345, true) // 'http://loremflickr.com/1234/2345/business?56789'
*/
business(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'business', randomize);
+ return this.imageUrl(width, height, 'business', randomize);
}
/**
@@ -175,7 +175,7 @@ export class Image {
* faker.image.cats(1234, 2345, true) // 'http://loremflickr.com/1234/2345/cats?56789'
*/
cats(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'cats', randomize);
+ return this.imageUrl(width, height, 'cats', randomize);
}
/**
@@ -191,7 +191,7 @@ export class Image {
* faker.image.city(1234, 2345, true) // 'http://loremflickr.com/1234/2345/city?56789'
*/
city(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'city', randomize);
+ return this.imageUrl(width, height, 'city', randomize);
}
/**
@@ -207,7 +207,7 @@ export class Image {
* faker.image.food(1234, 2345, true) // 'http://loremflickr.com/1234/2345/food?56789'
*/
food(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'food', randomize);
+ return this.imageUrl(width, height, 'food', randomize);
}
/**
@@ -223,7 +223,7 @@ export class Image {
* faker.image.nightlife(1234, 2345, true) // 'http://loremflickr.com/1234/2345/nightlife?56789'
*/
nightlife(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'nightlife', randomize);
+ return this.imageUrl(width, height, 'nightlife', randomize);
}
/**
@@ -239,7 +239,7 @@ export class Image {
* faker.image.fashion(1234, 2345, true) // 'http://loremflickr.com/1234/2345/fashion?56789'
*/
fashion(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'fashion', randomize);
+ return this.imageUrl(width, height, 'fashion', randomize);
}
/**
@@ -255,7 +255,7 @@ export class Image {
* faker.image.people(1234, 2345, true) // 'http://loremflickr.com/1234/2345/people?56789'
*/
people(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'people', randomize);
+ return this.imageUrl(width, height, 'people', randomize);
}
/**
@@ -271,7 +271,7 @@ export class Image {
* faker.image.nature(1234, 2345, true) // 'http://loremflickr.com/1234/2345/nature?56789'
*/
nature(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'nature', randomize);
+ return this.imageUrl(width, height, 'nature', randomize);
}
/**
@@ -287,7 +287,7 @@ export class Image {
* faker.image.sports(1234, 2345, true) // 'http://loremflickr.com/1234/2345/sports?56789'
*/
sports(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'sports', randomize);
+ return this.imageUrl(width, height, 'sports', randomize);
}
/**
@@ -303,7 +303,7 @@ export class Image {
* faker.image.technics(1234, 2345, true) // 'http://loremflickr.com/1234/2345/technics?56789'
*/
technics(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'technics', randomize);
+ return this.imageUrl(width, height, 'technics', randomize);
}
/**
@@ -319,7 +319,7 @@ export class Image {
* faker.image.transport(1234, 2345, true) // 'http://loremflickr.com/1234/2345/transport?56789'
*/
transport(width?: number, height?: number, randomize?: boolean): string {
- return this.faker.image.imageUrl(width, height, 'transport', randomize);
+ return this.imageUrl(width, height, 'transport', randomize);
}
/**
diff --git a/src/internet.ts b/src/internet.ts
index 08ac2e91..d7ab3f89 100644
--- a/src/internet.ts
+++ b/src/internet.ts
@@ -56,7 +56,7 @@ export class Internet {
this.faker.definitions.internet.free_email
);
let localPart: string = this.faker.helpers.slugify(
- this.faker.internet.userName(firstName, lastName)
+ this.userName(firstName, lastName)
);
if (options?.allowSpecialCharacters) {
const usernameChars: string[] = '._-'.split('');
@@ -172,9 +172,7 @@ export class Internet {
* faker.internet.url() // 'https://remarkable-hackwork.info'
*/
url(): string {
- return (
- this.faker.internet.protocol() + '://' + this.faker.internet.domainName()
- );
+ return this.protocol() + '://' + this.domainName();
}
/**
@@ -184,11 +182,7 @@ export class Internet {
* faker.internet.domainName() // 'slow-timer.info'
*/
domainName(): string {
- return (
- this.faker.internet.domainWord() +
- '.' +
- this.faker.internet.domainSuffix()
- );
+ return this.domainWord() + '.' + this.domainSuffix();
}
/**
diff --git a/src/lorem.ts b/src/lorem.ts
index fc5470c5..103dd6a7 100644
--- a/src/lorem.ts
+++ b/src/lorem.ts
@@ -47,7 +47,7 @@ export class Lorem {
words(num: number = 3): string {
const words: string[] = [];
for (let i = 0; i < num; i++) {
- words.push(this.faker.lorem.word());
+ words.push(this.word());
}
return words.join(' ');
}
@@ -66,7 +66,7 @@ export class Lorem {
wordCount = this.faker.datatype.number({ min: 3, max: 10 });
}
- const sentence = this.faker.lorem.words(wordCount);
+ const sentence = this.words(wordCount);
return sentence.charAt(0).toUpperCase() + sentence.slice(1) + '.';
}
@@ -79,7 +79,7 @@ export class Lorem {
* faker.lorem.slug() // 'dolores-illo-est'
*/
slug(wordCount?: number): string {
- const words = this.faker.lorem.words(wordCount);
+ const words = this.words(wordCount);
return this.faker.helpers.slugify(words);
}
@@ -103,7 +103,7 @@ export class Lorem {
}
const sentences: string[] = [];
for (sentenceCount; sentenceCount > 0; sentenceCount--) {
- sentences.push(this.faker.lorem.sentence());
+ sentences.push(this.sentence());
}
return sentences.join(separator);
}
@@ -118,9 +118,7 @@ export class Lorem {
* faker.lorem.paragraph() // 'Animi possimus nemo consequuntur ut ea et tempore unde qui. Quis corporis esse occaecati.'
*/
paragraph(sentenceCount: number = 3): string {
- return this.faker.lorem.sentences(
- sentenceCount + this.faker.datatype.number(3)
- );
+ return this.sentences(sentenceCount + this.faker.datatype.number(3));
}
/**
@@ -149,7 +147,7 @@ export class Lorem {
paragraphs(paragraphCount: number = 3, separator: string = '\n'): string {
const paragraphs: string[] = [];
for (paragraphCount; paragraphCount > 0; paragraphCount--) {
- paragraphs.push(this.faker.lorem.paragraph());
+ paragraphs.push(this.paragraph());
}
return paragraphs.join(separator);
}
@@ -202,6 +200,6 @@ export class Lorem {
if (lineCount == null) {
lineCount = this.faker.datatype.number({ min: 1, max: 5 });
}
- return this.faker.lorem.sentences(lineCount, '\n');
+ return this.sentences(lineCount, '\n');
}
}
diff --git a/src/name.ts b/src/name.ts
index a4b86c16..b96eb8db 100644
--- a/src/name.ts
+++ b/src/name.ts
@@ -205,20 +205,20 @@ export class Name {
normalizeGender(gender, 'findName') ??
this.faker.random.arrayElement(['female', 'male']);
- firstName = firstName || this.faker.name.firstName(normalizedGender);
- lastName = lastName || this.faker.name.lastName(normalizedGender);
+ firstName = firstName || this.firstName(normalizedGender);
+ lastName = lastName || this.lastName(normalizedGender);
switch (variant) {
// TODO @Shinigami92 2022-03-21: Add possibility to have a prefix together with a suffix
case 0:
- prefix = this.faker.name.prefix(gender);
+ prefix = this.prefix(gender);
if (prefix) {
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.faker.name.suffix();
+ suffix = this.suffix();
if (suffix) {
return firstName + ' ' + lastName + ' ' + suffix;
}
diff --git a/src/random.ts b/src/random.ts
index 448cf4f8..667b7c89 100644
--- a/src/random.ts
+++ b/src/random.ts
@@ -209,7 +209,7 @@ export class Random {
field = 'value'
): K | T[K] {
const array: Array<keyof T> = Object.keys(object);
- const key = this.faker.random.arrayElement(array);
+ const key = this.arrayElement(array);
return field === 'key' ? (key as K) : (object[key] as T[K]);
}
@@ -323,12 +323,12 @@ export class Random {
do {
// randomly pick from the many faker methods that can generate words
- const randomWordMethod = this.faker.random.arrayElement(wordMethods);
+ const randomWordMethod = this.arrayElement(wordMethods);
result = randomWordMethod();
} while (!result || bannedChars.some((char) => result.includes(char)));
- return this.faker.random.arrayElement(result.split(' '));
+ return this.arrayElement(result.split(' '));
}
/**
@@ -348,7 +348,7 @@ export class Random {
}
for (let i = 0; i < count; i++) {
- words.push(this.faker.random.word());
+ words.push(this.word());
}
return words.join(' ');
@@ -382,7 +382,7 @@ export class Random {
* faker.random.locale() // 'el'
*/
locale(): string {
- return this.faker.random.arrayElement(Object.keys(this.faker.locales));
+ return this.arrayElement(Object.keys(this.faker.locales));
}
/**
@@ -457,7 +457,7 @@ export class Random {
charsArray = arrayRemove(charsArray, options.bannedChars);
}
for (let i = 0; i < options.count; i++) {
- wholeString += this.faker.random.arrayElement(charsArray);
+ wholeString += this.arrayElement(charsArray);
}
return options.upcase ? wholeString.toUpperCase() : wholeString;
@@ -534,7 +534,7 @@ export class Random {
}
for (let i = 0; i < count; i++) {
- wholeString += this.faker.random.arrayElement(charsArray);
+ wholeString += this.arrayElement(charsArray);
}
return wholeString;
diff --git a/src/system.ts b/src/system.ts
index c5b052c0..16ddd876 100644
--- a/src/system.ts
+++ b/src/system.ts
@@ -55,8 +55,7 @@ export class System {
*/
fileName(): string {
let str = this.faker.random.words();
- str =
- str.toLowerCase().replace(/\W/g, '_') + '.' + this.faker.system.fileExt();
+ str = str.toLowerCase().replace(/\W/g, '_') + '.' + this.fileExt();
return str;
}
@@ -71,7 +70,7 @@ export class System {
commonFileName(ext?: string): string {
let str = this.faker.random.words();
str = str.toLowerCase().replace(/\W/g, '_');
- str += '.' + (ext || this.faker.system.commonFileExt());
+ str += '.' + (ext || this.commonFileExt());
return str;
}
@@ -104,9 +103,7 @@ export class System {
* faker.system.commonFileExt() // 'gif'
*/
commonFileExt(): string {
- return this.faker.system.fileExt(
- this.faker.random.arrayElement(commonMimeTypes)
- );
+ return this.fileExt(this.faker.random.arrayElement(commonMimeTypes));
}
/**