node-random-chars
Advanced tools
Comparing version 1.0.2 to 2.0.0
18
index.js
@@ -0,5 +1,15 @@ | ||
const crypto = require('crypto'); | ||
function generateHash(len) { | ||
var hash = ""; | ||
for(; hash.length < len; hash += Math.random().toString(36).substr(2)); | ||
return hash.substr(0, len); | ||
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | ||
const charSetLength = charSet.length; | ||
let hash = ''; | ||
for (let i = 0; i < len; i++) { | ||
const randomBuffer = crypto.randomBytes(1); | ||
const randomIndex = randomBuffer[0] % charSetLength; | ||
hash += charSet[randomIndex]; | ||
} | ||
return hash; | ||
} | ||
@@ -14,2 +24,2 @@ | ||
} | ||
}; | ||
}; |
{ | ||
"name": "node-random-chars", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Creates random alphanumeric hash strings with given length", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
32
4369