aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage-user/core/uuid.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage-user/core/uuid.js')
-rwxr-xr-xnode_modules/montage-user/core/uuid.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/node_modules/montage-user/core/uuid.js b/node_modules/montage-user/core/uuid.js
new file mode 100755
index 00000000..09d9acec
--- /dev/null
+++ b/node_modules/montage-user/core/uuid.js
@@ -0,0 +1,74 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6/* <notice>
7 Code from node-uuid: https://github.com/broofa/node-uuid/raw/master/uuid.js<br/>
8 MIT license https://github.com/broofa/node-uuid/blob/master/LICENSE.md<br/>
9 </notice> */
10
11/**
12 @module montage/core/uuid
13 @requires montage/core/core
14*/
15/**
16 @class module:montage/core/uuid.Uuid
17 @extends module:montage/core/core.Montage
18 */
19var CHARS = '0123456789ABCDEF'.split(''),
20 FORMAT = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.split(''),
21 Uuid = exports.Uuid = Object.create(Object.prototype, /** @lends module:montage/core/uuid.Uuid# */ {
22 /**
23 Returns a univerally unique ID (UUID).
24 @function
25 @param {Property} argument
26 @returns {String} The UUID.
27 */
28 generate: {
29 enumerable: false,
30 value: generate
31 }
32 });
33
34exports.generate = generate;
35function generate(argument) {
36 var c = CHARS, id = FORMAT, r;
37
38 id[0] = c[(r = Math.random() * 0x100000000) & 0xf];
39 id[1] = c[(r >>>= 4) & 0xf];
40 id[2] = c[(r >>>= 4) & 0xf];
41 id[3] = c[(r >>>= 4) & 0xf];
42 id[4] = c[(r >>>= 4) & 0xf];
43 id[5] = c[(r >>>= 4) & 0xf];
44 id[6] = c[(r >>>= 4) & 0xf];
45 id[7] = c[(r >>>= 4) & 0xf];
46
47 id[9] = c[(r = Math.random() * 0x100000000) & 0xf];
48 id[10] = c[(r >>>= 4) & 0xf];
49 id[11] = c[(r >>>= 4) & 0xf];
50 id[12] = c[(r >>>= 4) & 0xf];
51 id[15] = c[(r >>>= 4) & 0xf];
52 id[16] = c[(r >>>= 4) & 0xf];
53 id[17] = c[(r >>>= 4) & 0xf];
54
55 id[19] = c[(r = Math.random() * 0x100000000) & 0x3 | 0x8];
56 id[20] = c[(r >>>= 4) & 0xf];
57 id[21] = c[(r >>>= 4) & 0xf];
58 id[22] = c[(r >>>= 4) & 0xf];
59 id[24] = c[(r >>>= 4) & 0xf];
60 id[25] = c[(r >>>= 4) & 0xf];
61 id[26] = c[(r >>>= 4) & 0xf];
62 id[27] = c[(r >>>= 4) & 0xf];
63
64 id[28] = c[(r = Math.random() * 0x100000000) & 0xf];
65 id[29] = c[(r >>>= 4) & 0xf];
66 id[30] = c[(r >>>= 4) & 0xf];
67 id[31] = c[(r >>>= 4) & 0xf];
68 id[32] = c[(r >>>= 4) & 0xf];
69 id[33] = c[(r >>>= 4) & 0xf];
70 id[34] = c[(r >>>= 4) & 0xf];
71 id[35] = c[(r >>>= 4) & 0xf];
72
73 return id.join('');
74}