/**
 * Genrates a hash for the given string
 * @param string String to generate hash for
 * @returns string generated hash string
 */
export const Hasher = function(string) {
  var hash = 0
  var chr = 0

  if (string.length === 0) return hash
  for (var i = 0; i < string.length; i++) {
    chr = string.charCodeAt(i)
    hash = (hash << 5) - hash + chr
    hash |= 0 // Convert to 32bit integer
  }
  return hash
}

/**
 * Generate uuidv4
 * @returns {string}
 */
export const uuidv4 = function uuidv4() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = (Math.random() * 16) | 0,
      v = c == 'x' ? r : (r & 0x3) | 0x8
    return v.toString(16)
  })
}
