Initial commit
[yaffs-website] / node_modules / randomatic / README.md
1 # randomatic [![NPM version](https://img.shields.io/npm/v/randomatic.svg?style=flat)](https://www.npmjs.com/package/randomatic) [![NPM monthly downloads](https://img.shields.io/npm/dm/randomatic.svg?style=flat)](https://npmjs.org/package/randomatic)  [![NPM total downloads](https://img.shields.io/npm/dt/randomatic.svg?style=flat)](https://npmjs.org/package/randomatic) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/randomatic.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/randomatic)
2
3 > Generate randomized strings of a specified length, fast. Only the length is necessary, but you can optionally generate patterns using any combination of numeric, alpha-numeric, alphabetical, special or custom characters.
4
5 ## Install
6
7 Install with [npm](https://www.npmjs.com/):
8
9 ```sh
10 $ npm install --save randomatic
11 ```
12
13 ## Usage
14
15 ```js
16 var randomize = require('randomatic');
17 ```
18
19 ## API
20
21 ```js
22 randomize(pattern, length, options);
23 ```
24
25 * `pattern` **{String}**: The pattern to use for randomizing
26 * `length` **{Object}**: The length of the string to generate
27
28 ### pattern
29
30 > The pattern to use for randomizing
31
32 Patterns can contain any combination of the below characters, specified in any order.
33
34 **Example:**
35
36 To generate a 10-character randomized string using all available characters:
37
38 ```js
39 randomize('*', 10);
40 //=>
41
42 randomize('Aa0!', 10);
43 //=>
44 ```
45
46 * `a`: Lowercase alpha characters (`abcdefghijklmnopqrstuvwxyz'`)
47 * `A`: Uppercase alpha characters (`ABCDEFGHIJKLMNOPQRSTUVWXYZ'`)
48 * `0`: Numeric characters (`0123456789'`)
49 * `!`: Special characters (`~!@#$%^&()_+-={}[];\',.`)
50 * `*`: All characters (all of the above combined)
51 * `?`: Custom characters (pass a string of custom characters to the options)
52
53 ### length
54
55 > the length of the string to generate
56
57 **Examples:**
58
59 * `randomize('A', 5)` will generate a 5-character, uppercase, alphabetical, randomized string, e.g. `KDJWJ`.
60 * `randomize('0', 2)` will generate a 2-digit random number
61 * `randomize('0', 3)` will generate a 3-digit random number
62 * `randomize('0', 12)` will generate a 12-digit random number
63 * `randomize('A0', 16)` will generate a 16-character, alpha-numeric randomized string
64
65 If `length` is left undefined, the length of the pattern in the first parameter will be used. For example:
66
67 * `randomize('00')` will generate a 2-digit random number
68 * `randomize('000')` will generate a 3-digit random number
69 * `randomize('0000')` will generate a 4-digit random number...
70 * `randomize('AAAAA')` will generate a 5-character, uppercase alphabetical random string...
71
72 These are just examples, [see the tests](./test.js) for more use cases and examples.
73
74 #### chars
75
76 Type: `String`
77
78 Default: `undefined`
79
80 Define a custom string to be randomized.
81
82 **Example:**
83
84 * `randomize('?', 20, {chars: 'jonschlinkert'})` will generate a 20-character randomized string from the letters contained in `jonschlinkert`.
85 * `randomize('?', {chars: 'jonschlinkert'})` will generate a 13-character randomized string from the letters contained in `jonschlinkert`.
86
87 ## Usage Examples
88
89 * `randomize('A', 4)` (_whitespace insenstive_) would result in randomized 4-digit uppercase letters, like, `ZAKH`, `UJSL`... etc.
90 * `randomize('AAAA')` is equivelant to `randomize('A', 4)`
91 * `randomize('AAA0')` and `randomize('AA00')` and `randomize('A0A0')` are equivelant to `randomize('A0', 4)`
92 * `randomize('aa')`: results in double-digit, randomized, lower-case letters (`abcdefghijklmnopqrstuvwxyz`)
93 * `randomize('AAA')`: results in triple-digit, randomized, upper-case letters (`ABCDEFGHIJKLMNOPQRSTUVWXYZ`)
94 * `randomize('0', 6)`: results in six-digit, randomized nubmers (`0123456789`)
95 * `randomize('!', 5)`: results in single-digit randomized, _valid_ non-letter characters (`~!@#$%^&()_+-={}[];\',.`)
96 * `randomize('A!a0', 9)`: results in nine-digit, randomized characters (any of the above)
97
98 _The order in which the characters are defined is insignificant._
99
100 ## About
101
102 ### Related projects
103
104 * [pad-left](https://www.npmjs.com/package/pad-left): Left pad a string with zeros or a specified string. Fastest implementation. | [homepage](https://github.com/jonschlinkert/pad-left "Left pad a string with zeros or a specified string. Fastest implementation.")
105 * [pad-right](https://www.npmjs.com/package/pad-right): Right pad a string with zeros or a specified string. Fastest implementation. | [homepage](https://github.com/jonschlinkert/pad-right "Right pad a string with zeros or a specified string. Fastest implementation.")
106 * [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string "Repeat the given string n times. Fastest implementation for repeating a string.")
107
108 ### Contributing
109
110 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
111
112 ### Contributors
113
114 | **Commits** | **Contributor**<br/> | 
115 | --- | --- |
116 | 36 | [jonschlinkert](https://github.com/jonschlinkert) |
117 | 1 | [TrySound](https://github.com/TrySound) |
118 | 1 | [paulmillr](https://github.com/paulmillr) |
119
120 ### Building docs
121
122 _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
123
124 To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
125
126 ```sh
127 $ npm install -g verb verb-generate-readme && verb
128 ```
129
130 ### Running tests
131
132 Install dev dependencies:
133
134 ```sh
135 $ npm install -d && npm test
136 ```
137
138 ### Author
139
140 **Jon Schlinkert**
141
142 * [github/jonschlinkert](https://github.com/jonschlinkert)
143 * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
144
145 ### License
146
147 Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
148 Released under the [MIT license](https://github.com/jonschlinkert/randomatic/blob/master/LICENSE).
149
150 ***
151
152 _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on November 24, 2016._