feat: uuid nativo node:crypto, remove dep uuid npm, bump v0.354.0
This commit is contained in:
parent
088de12237
commit
fdfe409088
6 changed files with 51 additions and 719 deletions
|
|
@ -25,21 +25,32 @@ __export(uuid_exports, {
|
|||
validarUuid: () => validarUuid
|
||||
});
|
||||
module.exports = __toCommonJS(uuid_exports);
|
||||
var import_uuid = require("uuid");
|
||||
var import_node_crypto = require("node:crypto");
|
||||
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 = (uuid2) => {
|
||||
const retorno = erUuid.test(String(uuid2 || ""));
|
||||
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 ? uuidV3(grupo) : import_uuid.NIL
|
||||
);
|
||||
const NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
||||
const formatarUuidV3 = (hash) => {
|
||||
const chars = hash.slice(0, 32);
|
||||
return [
|
||||
chars.slice(0, 8),
|
||||
chars.slice(8, 12),
|
||||
`3${chars.slice(13, 16)}`,
|
||||
// version 3
|
||||
`${(Number.parseInt(chars[16], 16) & 3 | 8).toString(16)}${chars.slice(17, 20)}`,
|
||||
// variant
|
||||
chars.slice(20, 32)
|
||||
].join("-");
|
||||
};
|
||||
const uuidV4 = import_uuid.v4;
|
||||
const uuidV3 = (chave, grupo) => {
|
||||
const namespace = grupo ? uuidV3(grupo) : NIL_UUID;
|
||||
const input = typeof chave === "string" ? chave : typeof chave === "number" ? String(chave) : JSON.stringify(chave);
|
||||
const hash = (0, import_node_crypto.createHash)("md5").update(namespace + input).digest("hex");
|
||||
return formatarUuidV3(hash);
|
||||
};
|
||||
const uuidV4 = () => (0, import_node_crypto.randomUUID)();
|
||||
const uuid = uuidV4;
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue