summaryrefslogtreecommitdiff
path: root/src/node_modules/chance/docs/basics/template.md
blob: 96ba86032d7d8d50ef7e3df658df0ceeb61e3262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# template

Return a random string matching the given template.

```js
// usage
chance.template('{AA####}')
=> 'ZQ7803'
chance.template('{Aa}-{##}')
=> 'Vr-78'
chance.template('{####}:{####}:{####}')
=> '1628:5987:7803'
```

The template consists of any number of "character replacement" and "character
literal" sequences. A "character replacement" sequence starts with a left
brace, has any number of special replacement characters, and ends with a right
brace. A character literal can be any character except a brace or a backslash.
A literal brace or backslash character can be included in the output by
escaping with a backslash.

The following replacement characters can be used in a replacement sequence:

   * "#": a random digit
   * "a": a random lower case letter
   * "A": a random upper case letter