Skip to content

Instantly share code, notes, and snippets.

View MattiasFestin's full-sized avatar

Mattias Festin MattiasFestin

View GitHub Profile
@MattiasFestin
MattiasFestin / uneval.es6
Last active January 7, 2020 13:55
uneval "polyfill"
let uneval = (o, noNativeFns = true) => {
var retVal = '';
if (typeof o === 'object') {
if (Array.isArray(o)) {
retVal = '[' + o.map((el) => uneval(el)).join(',') + ']';
} else if (o instanceof RegExp) {
retVal = o.toString();
} else if (o instanceof Date) {
retVal = `new Date(${o})`;
} else if (o === null) {
@MattiasFestin
MattiasFestin / hash.es6
Last active August 29, 2015 14:20
JavaScript ES6 non-secure hash function
let hash = (o) => {
return padLeft(uneval(o)
.split('')
.map((c) => c.charCodeAt(0))
.reduce((x,y) => {
let v = ((y<<5)-y)+x;
return modPow(0xBCD1B799D, v && v, 0x7FFFFFFF);
})
.toString(16)
.toUpperCase(),'0',9);