Initial import with skill sheet working
This commit is contained in:
26
node_modules/@seald-io/nedb/lib/customUtils.js
generated
vendored
Executable file
26
node_modules/@seald-io/nedb/lib/customUtils.js
generated
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Utility functions that need to be reimplemented for each environment.
|
||||
* This is the version for Node.js
|
||||
* @module customUtilsNode
|
||||
* @private
|
||||
*/
|
||||
const crypto = require('crypto')
|
||||
|
||||
/**
|
||||
* Return a random alphanumerical string of length len
|
||||
* There is a very small probability (less than 1/1,000,000) for the length to be less than len
|
||||
* (il the base64 conversion yields too many pluses and slashes) but
|
||||
* that's not an issue here
|
||||
* The probability of a collision is extremely small (need 3*10^12 documents to have one chance in a million of a collision)
|
||||
* See http://en.wikipedia.org/wiki/Birthday_problem
|
||||
* @param {number} len
|
||||
* @return {string}
|
||||
* @alias module:customUtilsNode.uid
|
||||
*/
|
||||
const uid = len => crypto.randomBytes(Math.ceil(Math.max(8, len * 2)))
|
||||
.toString('base64')
|
||||
.replace(/[+/]/g, '')
|
||||
.slice(0, len)
|
||||
|
||||
// Interface
|
||||
module.exports.uid = uid
|
Reference in New Issue
Block a user