1 | # node-randomstring
|
2 |
|
3 | [![Build Status](https://travis-ci.org/klughammer/node-randomstring.svg?branch=master)](https://travis-ci.org/klughammer/node-randomstring) [![Download Stats](https://img.shields.io/npm/dm/randomstring.svg)](https://github.com/klughammer/node-randomstring)
|
4 |
|
5 | Library to help you create random strings.
|
6 |
|
7 | ## Installation
|
8 |
|
9 | To install randomstring, use [npm](http://github.com/npm/npm):
|
10 |
|
11 | ```
|
12 | npm install randomstring
|
13 | ```
|
14 |
|
15 | ## Usage
|
16 |
|
17 | ```javascript
|
18 | var randomstring = require("randomstring");
|
19 |
|
20 | randomstring.generate();
|
21 | // >> "XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT"
|
22 |
|
23 | randomstring.generate(7);
|
24 | // >> "xqm5wXX"
|
25 |
|
26 | randomstring.generate({
|
27 | length: 12,
|
28 | charset: 'alphabetic'
|
29 | });
|
30 | // >> "AqoTIzKurxJi"
|
31 |
|
32 | randomstring.generate({
|
33 | charset: 'abc'
|
34 | });
|
35 | // >> "accbaabbbbcccbccccaacacbbcbbcbbc"
|
36 |
|
37 | randomstring.generate({
|
38 | charset: ['numeric', '!']
|
39 | });
|
40 | // >> "145132!87663611567!2486211!07856"
|
41 |
|
42 | randomstring.generate({
|
43 | charset: 'abc'
|
44 | }, cb);
|
45 | // >> "cb(generatedString) {}"
|
46 |
|
47 | ```
|
48 |
|
49 | ## API
|
50 |
|
51 | `randomstring.`
|
52 |
|
53 | - `generate(options, cb)`
|
54 | - `options`
|
55 | - `length` - the length of the random string. (default: 32) [OPTIONAL]
|
56 | - `readable` - exclude poorly readable chars: 0OIl. (default: false) [OPTIONAL]
|
57 | - `charset` - define the character set for the string. (default: 'alphanumeric') [OPTIONAL]
|
58 | - `alphanumeric` - [0-9 a-z A-Z]
|
59 | - `alphabetic` - [a-z A-Z]
|
60 | - `numeric` - [0-9]
|
61 | - `hex` - [0-9 a-f]
|
62 | - `binary` - [01]
|
63 | - `octal` - [0-7]
|
64 | - `custom` - any given characters
|
65 | - `[]` - An array of any above
|
66 | - `capitalization` - define whether the output should be lowercase / uppercase only. (default: null) [OPTIONAL]
|
67 | - `lowercase`
|
68 | - `uppercase`
|
69 | - `cb` - Optional. If provided uses async version of `crypto.randombytes`
|
70 |
|
71 | ## Command Line Usage
|
72 |
|
73 | $ npm install -g randomstring
|
74 |
|
75 | $ randomstring
|
76 | > sKCx49VgtHZ59bJOTLcU0Gr06ogUnDJi
|
77 |
|
78 | $ randomstring 7
|
79 | > CpMg433
|
80 |
|
81 | $ randomstring length=24 charset=github readable
|
82 | > hthbtgiguihgbuttuutubugg
|
83 |
|
84 | ## Tests
|
85 |
|
86 | ```
|
87 | npm install
|
88 | npm test
|
89 | ```
|
90 |
|
91 | ## LICENSE
|
92 |
|
93 | node-randomstring is licensed under the MIT license.
|