UNPKG

@tdb/web

Version:

Common condiguration for serving a web-site and testing web-based UI components.

29 lines (27 loc) 675 B
var url = '_~getRandomVcryp0123456789bfhijklqsuvwxzABCDEFGHIJKLMNOPQSTUWXYZ' /** * Generate URL-friendly unique ID. This method use non-secure predictable * random generator. * * By default, ID will have 21 symbols to have a collision probability similar * to UUID v4. * * @param {number} [size=21] The number of symbols in ID. * * @return {string} Random string. * * @example * const nanoid = require('nanoid/non-secure') * model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqL" * * @name nonSecure * @function */ module.exports = function (size) { size = size || 21 var id = '' while (0 < size--) { id += url[Math.random() * 63 | 0] } return id }