diff options
| -rw-r--r-- | index.js | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -1,12 +1,22 @@ export default class RandomAvatars { - constructor(string, hashcount=11, ignoreext=true) { + constructor(string, hashcount = 11, ignoreext = true) { /** * This creates our avatar. * Takes in a string and makes an picture out of it. */ - if (ignoreext) removeExts(this, string); + let string = string; + if (ignoreext) string = removeExts(this, string); - this.format = 'png' + this.hexdigest = crypto.createHash('sha512').update(string).digest('hex'); + this.hasharray = []; + // Start this at 4, so earlier is reserved + // 0 = Color + // 1 = Set + // 2 = bgset + // 3 = BG + this.iter = 4; + createhashes(this, hashcount); + this.format = 'png'; } } @@ -28,3 +38,19 @@ function removeExts(currentClass, string) { } return input; } + +function createhashes(currentClass, count) { + /** + * Breaks up our hash into slots, so we can pull them out later. + * Essentially, it splits our SHA/MD5/etc into X parts. + */ + + for (const i of Array(count).keys()) { + // Get 1/numblocks of the hash + const blocksize = parseInt(currentClass.hexdigest.length/count); + const currentStart = ((i + 1) * blocksize) - blocksize; + const currentEnd = (1 +i) * blocksize; + currentClass.hasharray.push(parseInt(currentClass.hexdigest.substr(currentStart, currentEnd), 16)); + } + currentClass.hasharray = currentClass.hasharray + currentClass.hasharray +} |
