phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.
30 lines (26 loc) • 823 B
JavaScript
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2025 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Creates and returns an RFC4122 version 4 compliant UUID.
*
* The string is in the form: `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` where each `x` is replaced with a random
* hexadecimal digit from 0 to f, and `y` is replaced with a random hexadecimal digit from 8 to b.
*
* @function Phaser.Utils.String.UUID
* @since 3.12.0
*
* @return {string} The UUID string.
*/
var UUID = function ()
{
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c)
{
var r = Math.random() * 16 | 0;
var v = (c === 'x') ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
module.exports = UUID;