@@ -15,25 +15,35 @@ export class Fake {
15
15
}
16
16
17
17
/**
18
- * Generator method for combining faker methods based on string input.
18
+ * Generator for combining faker methods based on a static string input.
19
19
*
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()}`;``
22
23
*
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).
33
26
*
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:
35
28
*
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.
37
47
*
38
48
* @see faker.helpers.mustache() to use custom functions for resolution.
39
49
*
0 commit comments