All files / node-user-accounts-boilerplate-nahid/helper generateId.js

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19    9x                   9x   106x        
"use strict";
 
const crypto = require('crypto');
 
/**
 * Helper method that generates a new user id.
 * 
 * This method uses current timestamp and random number generator to come up
 * with unique ids.
 * 
 * @return {string}
 */
module.exports = function ()
{
  return `${crypto.randomBytes(4)
    .toString('hex')}.${(Date.now() + Math.random())
    .toString(26)}`;
}