Apidog Docs
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
HomeLearning CenterSupport CenterAPI References
HomeLearning CenterSupport CenterAPI References
Discord Community
Slack Community
X / Twitter
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
  1. Learning Center
  • Back to home
  • Dynamic values Modules
  • Airline
  • Animal
  • Color
  • Commerce
  • Company
  • Database
  • Datatype
  • Date
  • Finance
  • Food
  • Git
  • Hacker
  • Helpers
  • Image
  • Internet
  • Location
  • Lorem
  • Music
  • Number
  • Person
  • Phone
  • Science
  • String
  • System
  • Vehicle
  • Word
  1. Learning Center

Helpers

Module with various helper methods providing basic (seed-dependent) operations useful for implementing faker methods.
Overview
A particularly helpful method is {{$helpers.arrayElement(['abc','123'])}} which returns a random element from an array. This is useful when adding custom data that Faker doesn't contain.
A number of methods can generate strings according to various patterns: {{$helpers.replaceSymbols('##??**')}} and {{$helpers.fromRegExp('[A-Z0-9]{4}-[A-Z0-9]{4}')}}.

arrayElement#

Returns random element from the given array.
Parameters
NameTypeDefaultDescription
arrayT[]The array to pick the value from.
Returns: T
Examples

arrayElements#

Returns a subset with random elements of the given array in random order.
Parameters
NameTypeDefaultDescription
arrayT[]The array to pick the value from.
maxnumberThe maximum number of elements to pick.
minnumberThe minimum number of elements to pick.
Returns: T
Examples

fromRegExp#

Generates a string matching the given regex like expressions.
This function doesn't provide full support of actual RegExp. Features such as grouping, anchors and character classes are not supported. If you are looking for a library that randomly generates strings based on RegExps, see randexp.js
Supported patterns:
x{times} => Repeat the x exactly times times.
x{min,max} => Repeat the x min to max times.
[x-y] => Randomly get a character between x and y (inclusive).
[x-y]{times} => Randomly get a character between x and y (inclusive) and repeat it times times.
[x-y]{min,max} => Randomly get a character between x and y (inclusive) and repeat it min to max times.
[^...] => Randomly get an ASCII number or letter character that is not in the given range. (e.g. [^0-9] will get a random non-numeric character).
[-...] => Include dashes in the range. Must be placed after the negate character ^ and before any character sets if used (e.g. [^-0-9] will not get any numeric characters or dashes).
/[x-y]/i => Randomly gets an uppercase or lowercase character between x and y (inclusive).
x? => Randomly decide to include or not include x.
[x-y]? => Randomly decide to include or not include characters between x and y (inclusive).
x* => Repeat x 0 or more times.
[x-y]* => Repeat characters between x and y (inclusive) 0 or more times.
x+ => Repeat x 1 or more times.
[x-y]+ => Repeat characters between x and y (inclusive) 1 or more times.
. => returns a wildcard ASCII character that can be any number, character or symbol. Can be combined with quantifiers as well.
Parameters
NameTypeDefaultDescription
patternstring | RegExpThe template string/RegExp to generate a matching string for.
Returns: string
Throws: If min value is more than max value in quantifier, e.g. #{10,5}. If an invalid quantifier symbol is passed in.
Examples

rangeToNumber#

Helper method that converts the given number or range to a number.
Parameters
NameTypeDefaultDescription
maxnumberThe maximum value for the range.
minnumberThe minimum value for the range.
Returns: number
Examples

replaceCreditCardSymbols#

Replaces the symbols and patterns in a credit card schema including Luhn checksum.
Parameters
NameTypeDefaultDescription
stringstring'6453-####-####-####-###L'The credit card format pattern.
symbolstring'#'The symbol to replace with a digit.
Returns: string
Examples

replaceSymbols#

Parses the given string symbol by symbols and replaces the placeholder appropriately.
# will be replaced with a digit (0 - 9).
? will be replaced with an upper letter ('A' - 'Z')
and * will be replaced with either a digit or letter.
Parameters
NameTypeDefaultDescription
stringstring The template string to parse.
Returns: string
Examples

slugify#

Slugifies the given string. For that all spaces ( ) are replaced by hyphens (-) and most non word characters except for dots and hyphens will be removed.
Parameters
NameTypeDefaultDescription
stringstring The input to slugify.
Returns: string
Examples

Previous
Hacker
Next
Image
Built with