UNPKG

devfty

Version:

Devfty is a library for developer building low code factory

27 lines (25 loc) 709 B
/** * 依据编码和名称生成uid * @param {*} code * @param {*} name * @returns */ export async function generateUID(code, name) { const data = { code, name } const stringData = JSON.stringify(data) const uint8 = new TextEncoder().encode(stringData) const hashBuffer = await crypto.subtle.digest('SHA-256', uint8) const hashArray = Array.from(new Uint8Array(hashBuffer)) const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('') return hashHex } export const base64 = { // 加密 encode: (str) => { return window.btoa(str) }, // 解密 decode: (str) => { return window.atob(str) }, }