Last active
September 20, 2024 23:15
-
-
Save johnelliott/cf77003f72f889abbc3f32785fa3df8d to your computer and use it in GitHub Desktop.
uuid v4 regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { v4 as uuid } from 'uuid'; | |
export function generateId() { | |
return uuid(); | |
} | |
const v4 = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i); | |
console.log(generateId().match(v4)); | |
//console.log(generateId().length) | |
//console.log('new way') | |
//console.log(generateId().length) | |
//console.log('new way, chopped') | |
//console.log(generateId().split('-')[0]) | |
//console.log('old way') | |
//const generateNumber = () => Math.ceil(Math.random() * 100) | |
//console.log(`${generateNumber()}${generateNumber()}${generateNumber()}${generateNumber()}`) | |
// run with $ node_modules/.bin/babel-node testuuid.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the alias here is just to make it concrete to the user that the
uuid
API returns a version 4 UUID.