Generator for combining faker methods based on a static string input.

Note: We recommend using string template literals instead of fake(), which are faster and strongly typed (if you are using TypeScript), e.g. const address = `${faker.address.zipCode()} ${faker.address.city()}`;

This method is useful if you have to build a random string from a static, non-executable source (e.g. string coming from a user, stored in a database or a file).

It checks the given string for placeholders and replaces them by calling faker methods:

const hello = faker.fake('Hi, my name is {{name.firstName}} {{name.lastName}}!')

This would use the faker.name.firstName() and faker.name.lastName() method to resolve the placeholders respectively.

It is also possible to provide parameters. At first, they will be parsed as json, and if that isn't possible, we will fall back to string:

const message = faker.fake(`You can call me at {{phone.phoneNumber(+!# !## #### #####!)}}.')

Currently it is not possible to set more than a single parameter.

It is also NOT possible to use any non-faker methods or plain javascript in such templates.



The template string that will get interpolated. Must not be empty.

Returns: string

faker.fake(str: string): string
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: {{helpers.arrayElement(["heads", "tails"])}}') // 'I flipped the coin an got: tails'