You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
607 B
24 lines
607 B
5 years ago
|
var random = require('./random')
|
||
|
var format = require('./format')
|
||
|
|
||
|
/**
|
||
|
* Low-level function to change alphabet and ID size.
|
||
|
*
|
||
|
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||
|
* will not be secure.
|
||
|
*
|
||
|
* @param {string} alphabet Symbols to be used in ID.
|
||
|
* @param {number} size The number of symbols in ID.
|
||
|
*
|
||
|
* @return {string} Unique ID.
|
||
|
*
|
||
|
* @example
|
||
|
* var generate = require('nanoid/generate')
|
||
|
* model.id = generate('0123456789абвгдеё', 5) //=> "8ё56а"
|
||
|
*
|
||
|
* @name generate
|
||
|
*/
|
||
|
module.exports = function (alphabet, size) {
|
||
|
return format(random, alphabet, size)
|
||
|
}
|