Files
izyim-mockapi/node_modules/nanoid/index.browser.js
T
2018-08-09 11:15:09 +08:00

23 lines
615 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
if (process.env.NODE_ENV !== 'production') {
if (typeof self === 'undefined' || (!self.crypto && !self.msCrypto)) {
throw new Error(
'Your browser does not have secure random generator. ' +
'If you dont need unpredictable IDs, you can use nanoid/non-secure.'
)
}
}
var crypto = self.crypto || self.msCrypto
var url = '_~getRandomVcryp0123456789bfhijklqsuvwxzABCDEFGHIJKLMNOPQSTUWXYZ'
module.exports = function (size) {
size = size || 21
var id = ''
var bytes = crypto.getRandomValues(new Uint8Array(size))
while (0 < size--) {
id += url[bytes[size] & 63]
}
return id
}