forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUUID.js
More file actions
29 lines (26 loc) · 824 Bytes
/
Copy pathUUID.js
File metadata and controls
29 lines (26 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @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;