Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jedwatson/randomkey
Lightweight node.js lib for generating random string keys
https://github.com/jedwatson/randomkey
Last synced: 6 days ago
JSON representation
Lightweight node.js lib for generating random string keys
- Host: GitHub
- URL: https://github.com/jedwatson/randomkey
- Owner: JedWatson
- License: mit
- Created: 2015-07-15T05:54:58.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-02T01:51:11.000Z (over 7 years ago)
- Last Synced: 2024-11-02T08:51:35.406Z (13 days ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 10
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Randomkey
Lightweight node.js lib for generating random strings.
You can specify the length and character set to use.
If you specify length as an array `[min, max]` a number in the range will be
used.The character set defaults to:
```
0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz
```Several character sets are provided as properties of the function:
* `default`: `0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz`
* `upper`: `ABCDEFGHIJKLMNOPQRSTUVWXTZ`
* `lower`: `abcdefghijklmnopqrstuvwxtz`
* `alphanumeric`: `0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ`
* `numbers`: `0123456789`
* `safe`: `2346789ABCDEFGHJKLMNPRTUVWXTZ`## Usage
```
npm install --save randomkey
```### randomkey(len, chars)
```
var rk = require('randomkey');// generate a 10 character key using the default character set
var key = rk(10);// generate a 6 character key using only the characters `a`, `b` and `c`
var abc = rk(6, 'abc');// generate a 16 character key using the "safe" character set:
var safe = rk(16, rk.safe);// generate a key between 5 and 10 characters long with the default characters:
var variableLength = rk([5,10]);