Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Is UUID/GUID ?

node v13.14.0
version: 1.0.0
endpointsharetweet
const isUUID = require("is-uuid") const isGuid = require("is-guid").isGuid let testPayload = null
function formatToUUID(str) { if (str.split('-').length === 5) { return str; } const r = new RegExp(/([A-Za-z0-9]{8})([A-Za-z0-9]{4})([A-Za-z0-9]{4})([A-Za-z0-9]{4})([A-Za-z0-9]{12})/gi); const matches = r.exec(str); if (matches.length !== 6) { throw new Error('Invalid UUID'); } const ret = matches.slice(1, matches.length).join('-').toLowerCase(); console.log(ret); return ret; }
// testPayload = formatToUUID('C4CEBFD8B6A782A5E0DC32AFE31D6D09') testPayload = formatToUUID("2de22ac1-963b-6fd3-a395-14cab158f85d")
isUUID.v1(testPayload); // true
isUUID.v2(testPayload); // true
isUUID.v3(testPayload); // true
isUUID.v4(testPayload); // true
isUUID.v5(testPayload);
isGuid(testPayload)
Loading…

no comments

    sign in to comment