Skip to content

Commit

Permalink
docs: update fake jsdocs (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Feb 6, 2022
1 parent bf0ec90 commit 3ec32a3
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/fake.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Faker } from '.';

/**
* Generator method for combining faker methods based on string input
* Generator method for combining faker methods based on string input.
*/
export class Fake {
constructor(private readonly faker: Faker) {
Expand All @@ -15,21 +15,30 @@ export class Fake {
}

/**
* Generator method for combining faker methods based on string input
* Generator method for combining faker methods based on string input.
*
* __Example:__
* This will check the given string for placeholders and replace them by calling the specified faker method.
* E.g. the input `Hi, my name is {{name.firstName}}!`,
* will use the `faker.name.firstName()` method to resolve the placeholder.
* It is also possible to combine static text with placeholders,
* since only the parts inside the double braces `{{placeholder}}` are replaced.
* The replacement process is repeated until all placeholders have been replaced by static text.
* It is also possible to provide the called method with additional parameters by adding parentheses.
* This method will first attempt to parse the parameters as json, if that isn't possible it will use them as string.
* E.g. `You can call me at {{phone.phoneNumber(+!# !## #### #####!)}}.`
* Currently it isn't possible to set more than a single parameter this way.
*
* ```
* console.log(faker.fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}'));
* // outputs: "Marks, Dean Sr."
* ```
* Please note that is NOT possible to use any non-faker methods or plain js script in there.
*
* This will interpolate the format string with the value of methods
* [name.lastName]{@link faker.name.lastName}, [name.firstName]{@link faker.name.firstName},
* and [name.suffix]{@link faker.name.suffix}
* @param str The format string that will get interpolated.
*
* @method faker.fake
* @param str
* @example
* faker.fake('{{name.lastName}}') // 'Barrows'
* faker.fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}') // 'Durgan, Noe MD'
* faker.fake('This is static test.') // 'This is static test.'
* faker.fake('Good Morning {{name.firstName}}!') // 'Good Morning Estelle!'
* faker.fake('You can call me at {{phone.phoneNumber(!## ### #####!)}}.') // 'You can call me at 202 555 973722.'
* faker.fake('I flipped the coin an got: {{random.arrayElement(["heads", "tails"])}}') // 'I flipped the coin an got: tails'
*/
fake(str: string): string {
// setup default response as empty string
Expand Down

0 comments on commit 3ec32a3

Please sign in to comment.