const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; function valid(uuid) { return uuidPattern.test(uuid); } // Based on https://abhishekdutta.org/blog/standalone_uuid_generator_in_javascript.html // IE11 and Modern Browsers Only function uuid4() { var temp_url = URL.createObjectURL(new Blob()); var uuid = temp_url.toString(); URL.revokeObjectURL(temp_url); return uuid.split(/[:\/]/g).pop().toLowerCase(); // remove prefixes } uuid4.valid = valid; module.exports = uuid4;