UNPKG

2.12 kBMarkdownView Raw
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
5Library to help you create random strings.
6
7## Installation
8
9To install randomstring, use [npm](http://github.com/npm/npm):
10
11```
12npm install randomstring
13```
14
15## Usage
16
17```javascript
18var randomstring = require("randomstring");
19
20randomstring.generate();
21// >> "XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT"
22
23randomstring.generate(7);
24// >> "xqm5wXX"
25
26randomstring.generate({
27 length: 12,
28 charset: 'alphabetic'
29});
30// >> "AqoTIzKurxJi"
31
32randomstring.generate({
33 charset: 'abc'
34});
35// >> "accbaabbbbcccbccccaacacbbcbbcbbc"
36
37randomstring.generate({
38 charset: ['numeric', '!']
39});
40// >> "145132!87663611567!2486211!07856"
41
42randomstring.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```
87npm install
88npm test
89```
90
91## LICENSE
92
93node-randomstring is licensed under the MIT license.