📜  import uuid javascript - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:36.804000             🧑  作者: Mango

代码示例4
function uuid() {
        const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
        const xAndYOnly = /[xy]/g;

        return template.replace(xAndYOnly, (character) => {
            const randomNo =  Math.floor(Math.random() * 16);
            const newValue = character === 'x' ? randomNo : (randomNo & 0x3) | 0x8;

            return newValue.toString(16);
        });
    }