Skip to content

Commit f029a7d

Browse files
authored
Merge branch 'main' into test/fix-all-functional-tests
2 parents 23c17ee + 814880b commit f029a7d

File tree

5 files changed

+59
-55
lines changed

5 files changed

+59
-55
lines changed

src/fake.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export class Fake {
1717
/**
1818
* Generator method for combining faker methods based on string input.
1919
*
20-
* This will check the given string for placeholders and replace them by calling the specified faker method.
20+
* Note: If you just want to create a string on the fly, we recommend using string template literals instead.
21+
* This method is useful if you wish to choose a random format from a non-executable source or persistent storage (json etc.).
22+
*
23+
* It checks the given string for placeholders and replace them by calling the specified faker method.
2124
* E.g. the input `Hi, my name is {{name.firstName}}!`,
2225
* will use the `faker.name.firstName()` method to resolve the placeholder.
2326
* It is also possible to combine static text with placeholders,

src/git.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ export class Git {
6161
*/
6262
commitEntry(options: { merge?: boolean } = {}): string {
6363
// TODO @Shinigami92 2022-01-11: We may want to make it configurable to use just `\n` instead of `\r\n`
64-
let entry = 'commit {{git.commitSha}}\r\n';
64+
let entry = `commit ${this.commitSha()}\r\n`;
6565

6666
if (options.merge || this.faker.datatype.number({ min: 0, max: 4 }) === 0) {
67-
entry += 'Merge: {{git.shortSha}} {{git.shortSha}}\r\n';
67+
entry += `Merge: ${this.shortSha()}} ${this.shortSha()}\r\n`;
6868
}
6969

70-
entry +=
71-
'Author: {{name.firstName}} {{name.lastName}} <{{internet.email}}>\r\n';
72-
entry += 'Date: ' + this.faker.date.recent().toString() + '\r\n';
73-
entry += '\r\n\xa0\xa0\xa0\xa0{{git.commitMessage}}\r\n';
70+
entry += `Author: ${this.faker.name.firstName()} ${this.faker.name.lastName()} <${this.faker.internet.email()}>\r\n`;
71+
entry += `Date: ${this.faker.date.recent().toString()}\r\n`;
72+
entry += `\r\n\xa0\xa0\xa0\xa0${this.commitMessage()}\r\n`;
7473

75-
return this.faker.fake(entry);
74+
return entry;
7675
}
7776

7877
/**
@@ -82,8 +81,7 @@ export class Git {
8281
* faker.git.commitMessage() // 'reboot cross-platform driver'
8382
*/
8483
commitMessage(): string {
85-
const format = '{{hacker.verb}} {{hacker.adjective}} {{hacker.noun}}';
86-
return this.faker.fake(format);
84+
return `${this.faker.hacker.verb()} ${this.faker.hacker.adjective()} ${this.faker.hacker.noun()}`;
8785
}
8886

8987
/**

src/lorem.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,19 @@ export class Lorem {
175175
* // Dolor tempora iusto.'
176176
*/
177177
text(): string {
178-
const loremMethods = [
179-
'lorem.word',
180-
'lorem.words',
181-
'lorem.sentence',
182-
'lorem.sentences',
183-
'lorem.paragraph',
184-
'lorem.paragraphs',
185-
'lorem.lines',
178+
const methods: Array<keyof Lorem> = [
179+
'word',
180+
'words',
181+
'sentence',
182+
'sentences',
183+
'paragraph',
184+
'paragraphs',
185+
'lines',
186186
];
187-
const randomLoremMethod = this.faker.random.arrayElement(loremMethods);
188-
return this.faker.fake(`{{${randomLoremMethod}}}`);
187+
188+
const method = this.faker.random.arrayElement(methods);
189+
190+
return `${this[method]()}`;
189191
}
190192

191193
/**

src/random.ts

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -244,37 +244,37 @@ export class Random {
244244
*/
245245
word(): string {
246246
const wordMethods = [
247-
'commerce.department',
248-
'commerce.productName',
249-
'commerce.productAdjective',
250-
'commerce.productMaterial',
251-
'commerce.product',
252-
'commerce.color',
253-
254-
'company.catchPhraseAdjective',
255-
'company.catchPhraseDescriptor',
256-
'company.catchPhraseNoun',
257-
'company.bsAdjective',
258-
'company.bsBuzz',
259-
'company.bsNoun',
260-
'address.streetSuffix',
261-
'address.county',
262-
'address.country',
263-
'address.state',
264-
265-
'finance.accountName',
266-
'finance.transactionType',
267-
'finance.currencyName',
268-
269-
'hacker.noun',
270-
'hacker.verb',
271-
'hacker.adjective',
272-
'hacker.ingverb',
273-
'hacker.abbreviation',
274-
275-
'name.jobDescriptor',
276-
'name.jobArea',
277-
'name.jobType',
247+
this.faker.commerce.department,
248+
this.faker.commerce.productName,
249+
this.faker.commerce.productAdjective,
250+
this.faker.commerce.productMaterial,
251+
this.faker.commerce.product,
252+
this.faker.commerce.color,
253+
254+
this.faker.company.catchPhraseAdjective,
255+
this.faker.company.catchPhraseDescriptor,
256+
this.faker.company.catchPhraseNoun,
257+
this.faker.company.bsAdjective,
258+
this.faker.company.bsBuzz,
259+
this.faker.company.bsNoun,
260+
this.faker.address.streetSuffix,
261+
this.faker.address.county,
262+
this.faker.address.country,
263+
this.faker.address.state,
264+
265+
this.faker.finance.accountName,
266+
this.faker.finance.transactionType,
267+
this.faker.finance.currencyName,
268+
269+
this.faker.hacker.noun,
270+
this.faker.hacker.verb,
271+
this.faker.hacker.adjective,
272+
this.faker.hacker.ingverb,
273+
this.faker.hacker.abbreviation,
274+
275+
this.faker.name.jobDescriptor,
276+
this.faker.name.jobArea,
277+
this.faker.name.jobType,
278278
];
279279

280280
const bannedChars = [
@@ -302,11 +302,14 @@ export class Random {
302302
'-',
303303
];
304304
let result: string;
305+
305306
do {
306307
// randomly pick from the many faker methods that can generate words
307308
const randomWordMethod = this.faker.random.arrayElement(wordMethods);
308-
result = this.faker.fake('{{' + randomWordMethod + '}}');
309+
310+
result = randomWordMethod();
309311
} while (bannedChars.some((char) => result.includes(char)));
312+
310313
return this.faker.random.arrayElement(result.split(' '));
311314
}
312315

src/system.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ export class System {
178178
* faker.system.filePath() // '/usr/local/src/money.rmp.dotx'
179179
*/
180180
filePath(): string {
181-
return this.faker.fake(
182-
'{{system.directoryPath}}/{{system.fileName}}.{{system.fileExt}}'
183-
);
181+
return `${this.faker.system.directoryPath()}/${this.faker.system.fileName()}.${this.faker.system.fileExt()}`;
184182
}
185183

186184
/**

0 commit comments

Comments
 (0)