“UUID JavaScript” Respostas de código

UUID JavaScript

function uuid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}

var userID=uuid();//something like: "ec0c22fa-f909-48da-92cb-db17ecdb91c5" 
Grepper

Importar JavaScript Uuid

import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
Uptight Unicorn

Gerador UUID JS

function uuidv4() {
  return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  );
}

console.log(uuidv4());
Bare Faced Go Away Bird

UUID JavaScript

    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);
        });
    }
Nervous Narwhal

UUID JavaScript

function uuid() {
  try {
  	return crypto.randomUUID();
  } catch (e) {
  	return String(new Date().getTime());
  }
}
It's Not Easy Being Green

UUID JavaScript

1
2
3
4
5


Faris Hazazi

Respostas semelhantes a “UUID JavaScript”

Perguntas semelhantes a “UUID JavaScript”

Mais respostas relacionadas para “UUID JavaScript” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código