All files uniqueId.js

100% Statements 10/10
80% Branches 4/5
100% Functions 4/4
100% Lines 9/9

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 20 2119x 5262x 2631x 2631x 2631x 2631x                     2631x 2631x 2631x    
const LCG = (seed) => {
  const lcg = (a) => a * 48271 % 2147483647
  seed = seed ? lcg(seed) : lcg(Math.random())
  return () => {
    seed = lcg(seed)
    return seed / 2147483648
  }
}
 
/**
 * uniqueId
 *
 * @param {string} [prefix] - optional prefix
 * @return {string}
 */
export default (prefix, ex = 9e15) => {
  const random = LCG()
  const id = parseInt((random() * ex).toFixed(0), 10).toString(36)
  return (prefix) ? `${prefix}-${id}` : id
}