UNPKG

idy

Version:

Generate random and potentially unique ids.

19 lines (18 loc) 437 B
"use strict"; /** * idy * Generates a random id and potentially unique. * * @name Idy * @function * @param {Number} length The id length (default: 10). * @return {String} The generated id. */ var idy = module.exports = function (length) { length = length || 10; var res = ""; do { res += Math.random().toString(35).substr(2, length); } while (res.length < length); return res.substring(0, length); };