Skip to content

Commit 4198723

Browse files
authored
Merge branch 'main' into readme-import
2 parents 930a4ca + 7afd8c5 commit 4198723

File tree

7 files changed

+89
-54
lines changed

7 files changed

+89
-54
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@
9595
"@types/validator": "~13.7.2",
9696
"@typescript-eslint/eslint-plugin": "~5.17.0",
9797
"@typescript-eslint/parser": "~5.17.0",
98-
"@vitest/ui": "~0.7.12",
98+
"@vitest/ui": "~0.8.0",
9999
"c8": "~7.11.0",
100100
"conventional-changelog-cli": "~2.2.2",
101-
"cypress": "~9.5.2",
101+
"cypress": "~9.5.3",
102102
"esbuild": "~0.14.28",
103103
"eslint": "~8.12.0",
104104
"eslint-config-prettier": "~8.5.0",
@@ -122,7 +122,7 @@
122122
"validator": "~13.7.0",
123123
"vite": "~2.8.6",
124124
"vitepress": "~0.22.3",
125-
"vitest": "~0.7.12"
125+
"vitest": "~0.8.0"
126126
},
127127
"packageManager": "[email protected]",
128128
"engines": {

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/apidoc/parameterDefaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class DefaultParameterAwareSerializer extends SerializerComponent<Reflect
6666
return instance instanceof Reflection;
6767
}
6868

69-
supports(item: unknown): boolean {
69+
supports(): boolean {
7070
return true;
7171
}
7272

src/fake.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,35 @@ export class Fake {
1515
}
1616

1717
/**
18-
* Generator method for combining faker methods based on string input.
18+
* Generator for combining faker methods based on a static string input.
1919
*
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.).
20+
* Note: We recommend using string template literals instead of `fake()`,
21+
* which are faster and strongly typed (if you are using TypeScript),
22+
* e.g. ``const address = `${faker.address.zipCode()} ${faker.address.city()}`;``
2223
*
23-
* It checks the given string for placeholders and replace them by calling the specified faker method.
24-
* E.g. the input `Hi, my name is {{name.firstName}}!`,
25-
* will use the `faker.name.firstName()` method to resolve the placeholder.
26-
* It is also possible to combine static text with placeholders,
27-
* since only the parts inside the double braces `{{placeholder}}` are replaced.
28-
* The replacement process is repeated until all placeholders have been replaced by static text.
29-
* It is also possible to provide the called method with additional parameters by adding parentheses.
30-
* This method will first attempt to parse the parameters as json, if that isn't possible it will use them as string.
31-
* E.g. `You can call me at {{phone.phoneNumber(+!# !## #### #####!)}}.`
32-
* Currently it isn't possible to set more than a single parameter this way.
24+
* This method is useful if you have to build a random string from a static, non-executable source
25+
* (e.g. string coming from a user, stored in a database or a file).
3326
*
34-
* Please note that is NOT possible to use any non-faker methods or plain js script in there.
27+
* It checks the given string for placeholders and replaces them by calling faker methods:
3528
*
36-
* @param str The format string that will get interpolated. May not be empty.
29+
* ```js
30+
* const hello = faker.fake('Hi, my name is {{name.firstName}} {{name.lastName}}!')
31+
* ```
32+
*
33+
* This would use the `faker.name.firstName()` and `faker.name.lastName()` method to resolve the placeholders respectively.
34+
*
35+
* It is also possible to provide parameters. At first, they will be parsed as json,
36+
* and if that isn't possible, we will fall back to string:
37+
*
38+
* ```js
39+
* const message = faker.fake(`You can call me at {{phone.phoneNumber(+!# !## #### #####!)}}.')
40+
* ```
41+
*
42+
* Currently it is not possible to set more than a single parameter.
43+
*
44+
* It is also NOT possible to use any non-faker methods or plain javascript in such templates.
45+
*
46+
* @param str The template string that will get interpolated. Must not be empty.
3747
*
3848
* @see faker.helpers.mustache() to use custom functions for resolution.
3949
*

src/system.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ export class System {
175175
* Returns a file path.
176176
*
177177
* @example
178-
* faker.system.filePath() // '/usr/local/src/money.rmp.dotx'
178+
* faker.system.filePath() // '/usr/local/src/money.dotx'
179179
*/
180+
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file.
180181
filePath(): string {
181-
return `${this.faker.system.directoryPath()}/${this.faker.system.fileName()}.${this.faker.system.fileExt()}`;
182+
return `${this.directoryPath()}/${this.fileName()}`;
182183
}
183184

184185
/**

src/word.ts

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ export class Word {
1616

1717
/**
1818
* Returns an adjective of random or optionally specified length.
19-
* If specified length is unresolvable, returns random adjective.
2019
*
21-
* @param length The optional length of word to return.
20+
* @param length Expected adjective length. If specified length is unresolvable, returns adjective of a random length.
21+
*
22+
* @example
23+
* faker.word.adjective() // 'pungent'
24+
* faker.word.adjective(5) // 'slimy'
25+
* faker.word.adjective(100) // 'complete'
2226
*/
2327
adjective(length?: number): string {
2428
let wordList = this.faker.definitions.word.adjective;
@@ -38,9 +42,13 @@ export class Word {
3842

3943
/**
4044
* Returns an adverb of random or optionally specified length.
41-
* If specified length is unresolvable, returns random adverb.
4245
*
43-
* @param length The optional length of word to return.
46+
* @param length Expected adverb length. If specified length is unresolvable, returns adverb of a random length.
47+
*
48+
* @example
49+
* faker.word.adverb() // 'quarrelsomely'
50+
* faker.word.adverb(5) // 'madly'
51+
* faker.word.adverb(100) // 'sadly'
4452
*/
4553
adverb(length?: number): string {
4654
let wordList = this.faker.definitions.word.adverb;
@@ -60,9 +68,13 @@ export class Word {
6068

6169
/**
6270
* Returns a conjunction of random or optionally specified length.
63-
* If specified length is unresolvable, returns random conjunction.
6471
*
65-
* @param length The optional length of word to return.
72+
* @param length Expected conjunction length. If specified length is unresolvable, returns conjunction of a random length.
73+
*
74+
* @example
75+
* faker.word.conjunction() // 'in order that'
76+
* faker.word.conjunction(5) // 'since'
77+
* faker.word.conjunction(100) // 'as long as'
6678
*/
6779
conjunction(length?: number): string {
6880
let wordList = this.faker.definitions.word.conjunction;
@@ -82,9 +94,13 @@ export class Word {
8294

8395
/**
8496
* Returns an interjection of random or optionally specified length.
85-
* If specified length is unresolvable, returns random interjection.
8697
*
87-
* @param length The optional length of word to return.
98+
* @param length Expected interjection length. If specified length is unresolvable, returns interjection of a random length.
99+
*
100+
* @example
101+
* faker.word.interjection() // 'gah'
102+
* faker.word.interjection(5) // 'fooey'
103+
* faker.word.interjection(100) // 'yowza'
88104
*/
89105
interjection(length?: number): string {
90106
let wordList = this.faker.definitions.word.interjection;
@@ -104,9 +120,13 @@ export class Word {
104120

105121
/**
106122
* Returns a noun of random or optionally specified length.
107-
* If specified length is unresolvable, returns random noun.
108123
*
109-
* @param length The optional length of word to return.
124+
* @param length Expected noun length. If specified length is unresolvable, returns noun of a random length.
125+
*
126+
* @example
127+
* faker.word.noun() // 'external'
128+
* faker.word.noun(5) // 'front'
129+
* faker.word.noun(100) // 'care'
110130
*/
111131
noun(length?: number): string {
112132
let wordList = this.faker.definitions.word.noun;
@@ -126,9 +146,13 @@ export class Word {
126146

127147
/**
128148
* Returns a preposition of random or optionally specified length.
129-
* If specified length is unresolvable, returns random preposition.
130149
*
131-
* @param length The optional length of word to return.
150+
* @param length Expected preposition length. If specified length is unresolvable, returns preposition of a random length.
151+
*
152+
* @example
153+
* faker.word.preposition() // 'without'
154+
* faker.word.preposition(5) // 'abaft'
155+
* faker.word.preposition(100) // 'an'
132156
*/
133157
preposition(length?: number): string {
134158
let wordList = this.faker.definitions.word.preposition;
@@ -148,9 +172,13 @@ export class Word {
148172

149173
/**
150174
* Returns a verb of random or optionally specified length.
151-
* If specified length is unresolvable, returns random verb.
152175
*
153-
* @param length The optional length of word to return.
176+
* @param length Expected verb length. If specified length is unresolvable, returns verb of a random length.
177+
*
178+
* @example
179+
* faker.word.verb() // 'act'
180+
* faker.word.verb(5) // 'tinge'
181+
* faker.word.verb(100) // 'mess'
154182
*/
155183
verb(length?: number): string {
156184
let wordList = this.faker.definitions.word.verb;

test/system.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const seededRuns = [
1515
fileType: 'image',
1616
fileExt: 'chm',
1717
directoryPath: '/opt/bin',
18-
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file.
19-
filePath: '/opt/bin/directives_savings_computer.qwd.jade',
18+
filePath: '/opt/bin/directives_savings_computer.qwd',
2019
semver: '3.7.9',
2120
},
2221
},
@@ -31,8 +30,7 @@ const seededRuns = [
3130
fileType: 'font',
3231
fileExt: 'gxt',
3332
directoryPath: '/Library',
34-
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file.
35-
filePath: '/Library/bike_kiribati.kpr.ez3',
33+
filePath: '/Library/bike_kiribati.kpr',
3634
semver: '2.5.1',
3735
},
3836
},
@@ -47,8 +45,7 @@ const seededRuns = [
4745
fileType: 'x-shader',
4846
fileExt: 'opml',
4947
directoryPath: '/var/log',
50-
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file.
51-
filePath: '/var/log/forward_frozen.swf.fcdt',
48+
filePath: '/var/log/forward_frozen.swf',
5249
semver: '9.4.8',
5350
},
5451
},
@@ -104,7 +101,6 @@ describe('system', () => {
104101
'jpeg',
105102
'm2a',
106103
'm2v',
107-
'm3a',
108104
'mp4',
109105
'mp4v',
110106
'mpeg',
@@ -118,7 +114,7 @@ describe('system', () => {
118114
expect(
119115
extList,
120116
`generated common file ext should be one of [${extList.join(
121-
','
117+
', '
122118
)}]. Got "${fileExt}".`
123119
).include(fileExt);
124120
});

0 commit comments

Comments
 (0)