adicionado uuid
This commit is contained in:
parent
e3c5642027
commit
c19d8bc40f
5 changed files with 81 additions and 23 deletions
|
|
@ -18,19 +18,31 @@ var __copyProps = (to, from, except, desc) => {
|
|||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var uuid_exports = {};
|
||||
__export(uuid_exports, {
|
||||
uuid: () => uuid
|
||||
erUuid: () => erUuid,
|
||||
uuidV3: () => uuidV3,
|
||||
uuidV4: () => uuidV4,
|
||||
validarUuid: () => validarUuid
|
||||
});
|
||||
module.exports = __toCommonJS(uuid_exports);
|
||||
const letras = "0123456789abcdef".split("");
|
||||
const uuid = () => {
|
||||
letras.sort(() => Math.random() - 0.5);
|
||||
const modelo = "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx".split("");
|
||||
const retorno = modelo.map(
|
||||
(letra) => letra === "x" ? letras[(1e3 * Math.random() | 0) % letras.length] : letra
|
||||
).join("");
|
||||
var import_uuid = require("uuid");
|
||||
const erUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
const validarUuid = (uuid) => {
|
||||
const retorno = erUuid.test(String(uuid || ""));
|
||||
return retorno;
|
||||
};
|
||||
const uuidV3 = (chave, grupo) => {
|
||||
return (0, import_uuid.v3)(
|
||||
// Converte a chave para string (de forma segura)
|
||||
typeof chave === "string" ? chave : typeof chave === "number" ? String(chave) : JSON.stringify(chave),
|
||||
// Se um grupo foi fornecido, gera um UUID v3 recursivamente com base nele, senão usa NIL
|
||||
grupo ? typeof grupo == "string" && validarUuid(grupo) ? grupo : uuidV3(grupo) : import_uuid.NIL
|
||||
);
|
||||
};
|
||||
const uuidV4 = import_uuid.v4;
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
uuid
|
||||
erUuid,
|
||||
uuidV3,
|
||||
uuidV4,
|
||||
validarUuid
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue