Helpers
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.{{$helpers.replaceSymbols('##??**')}}
and {{$helpers.fromRegExp('[A-Z0-9]{4}-[A-Z0-9]{4}')}}
.arrayElement
Name | Type | Default | Description |
---|---|---|---|
array | T[] | The array to pick the value from. |
arrayElements
Name | Type | Default | Description |
---|---|---|---|
array | T[] | The array to pick the value from. | |
max | number | The maximum number of elements to pick. | |
min | number | The minimum number of elements to pick. |
fromRegExp
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
Name | Type | Default | Description |
---|---|---|---|
pattern | string | RegExp | The template string/RegExp to generate a matching string for. |
#{10,5}
. If an invalid quantifier symbol is passed in.
rangeToNumber
Name | Type | Default | Description |
---|---|---|---|
max | number | The maximum value for the range. | |
min | number | The minimum value for the range. |
replaceCreditCardSymbols
Name | Type | Default | Description |
---|---|---|---|
string | string | '6453-####-####-####-###L' | The credit card format pattern. |
symbol | string | '#' | The symbol to replace with a digit. |
replaceSymbols
#
will be replaced with a digit (0
- 9
).?
will be replaced with an upper letter ('A' - 'Z')*
will be replaced with either a digit or letter.Name | Type | Default | Description |
---|---|---|---|
string | string | | The template string to parse. |
slugify
) are replaced by hyphens (-
) and most non word characters except for dots and hyphens will be removed.Name | Type | Default | Description |
---|---|---|---|
string | string | | The input to slugify. |