Spaces:
Runtime error
Runtime error
Download masteringModule/node_modules/secure-random-string/lib/secure-random-string.js from SE-09/HapticsProject: direct link, hf CLI and curl.
- Browser
- Download file 904 Bytes
-
https://huggingface.co/spaces/SE-09/HapticsProject/resolve/refs%2Fpr%2F32/masteringModule/node_modules/secure-random-string/lib/secure-random-string.js
- Command line
-
hf download hf://spaces/SE-09/HapticsProject@refs/pr/32/masteringModule/node_modules/secure-random-string/lib/secure-random-string.js
-
curl -L -o secure-random-string.js https://huggingface.co/spaces/SE-09/HapticsProject/resolve/refs%2Fpr%2F32/masteringModule/node_modules/secure-random-string/lib/secure-random-string.js
904 Bytes
| var crypto = require('crypto'); | |
| function srs(options, cb) { | |
| if (typeof(options) === 'function') { | |
| cb = options; | |
| options = {}; | |
| } else { | |
| options = options || {}; | |
| } | |
| var length = options['length'] || 32; | |
| var alphanumeric = options['alphanumeric'] || false; | |
| // async path | |
| if (cb) { | |
| crypto.randomBytes(length, function(err, buf) { | |
| if (err) { | |
| return cb(err); | |
| } | |
| return cb(null, _finish(buf)); | |
| }); | |
| } | |
| // sync path | |
| else { | |
| return _finish(crypto.randomBytes(length)); | |
| } | |
| function _finish(buf) { | |
| var string = buf.toString('base64'); | |
| if (alphanumeric === true) { | |
| string = string.replace(/[\W_]+/g, ''); | |
| } else { | |
| string = string.replace(/\//g, '_').replace(/\+/g, '-'); | |
| } | |
| if (string.length < length) { | |
| throw new Error(`Generated string is too short. Please catch this Error and try again.`); | |
| } | |
| return string.substr(0, length); | |
| } | |
| }; | |
| module.exports = srs; | |