source:
frontend/node_modules/crypto-random-string/index.js
| Last change on this file was 9af201e, checked in by , 11 days ago | |
|---|---|
|
|
| File size: 253 bytes | |
| Line | |
|---|---|
| 1 | 'use strict'; |
| 2 | const crypto = require('crypto'); |
| 3 | |
| 4 | module.exports = length => { |
| 5 | if (!Number.isFinite(length)) { |
| 6 | throw new TypeError('Expected a finite number'); |
| 7 | } |
| 8 | |
| 9 | return crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length); |
| 10 | }; |
Note:
See TracBrowser
for help on using the repository browser.
