diff options
Diffstat (limited to 'js/components/core')
-rw-r--r-- | js/components/core/class-uuid.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/js/components/core/class-uuid.js b/js/components/core/class-uuid.js new file mode 100644 index 00000000..31175a4a --- /dev/null +++ b/js/components/core/class-uuid.js | |||
@@ -0,0 +1,45 @@ | |||
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 components/core/class-uuid | ||
13 | @requires montage/core/core | ||
14 | */ | ||
15 | /** | ||
16 | @class components/core/class-uuid.ClassUuid | ||
17 | @extends module:montage/core/core.Montage | ||
18 | */ | ||
19 | var Montage = require("montage/core/core").Montage, | ||
20 | CHARS = '0123456789ABCDEF'.split(''), | ||
21 | FORMAT = 'xxxxx'.split(''), | ||
22 | |||
23 | ClassUuid = exports.ClassUuid = Montage.create(Montage,/** @lends module:montage/core/class-uuid.ClassUuid# */ { | ||
24 | |||
25 | /** | ||
26 | Returns a univerally unique ID (UUID). | ||
27 | @function | ||
28 | @param {Property} argument TODO | ||
29 | @returns {String} The UUID. | ||
30 | */ | ||
31 | generate: { | ||
32 | enumerable: false, | ||
33 | value: function generate(argument) { | ||
34 | var c = CHARS, id = FORMAT, r; | ||
35 | |||
36 | id[0] = c[(r = Math.random() * 0x100000000) & 0xf]; | ||
37 | id[1] = c[(r >>>= 4) & 0xf]; | ||
38 | id[2] = c[(r >>>= 4) & 0xf]; | ||
39 | id[3] = c[(r >>>= 4) & 0xf]; | ||
40 | id[4] = c[(r >>>= 4) & 0xf]; | ||
41 | |||
42 | return id.join(''); | ||
43 | } | ||
44 | } | ||
45 | }); | ||