2016-06-26 11:53:19 +00:00
|
|
|
define(function(require, exports, module) {
|
|
|
|
|
|
|
|
exports.inherits = function(Child, Parent) {
|
|
|
|
Child.prototype = Object.create(Parent.prototype, { constructor: { value: Child }});
|
2016-11-25 13:08:14 +00:00
|
|
|
};
|
2016-06-26 11:53:19 +00:00
|
|
|
|
2016-11-25 11:46:17 +00:00
|
|
|
var isNode = (typeof global !== "undefined" && ({}).toString.call(global) == '[object global]');
|
|
|
|
var isBrowser = (typeof window !== "undefined" && ({}).toString.call(window) == '[object window]');
|
|
|
|
|
|
|
|
if (isNode) {
|
|
|
|
exports.uid = function(length) {
|
2016-11-25 13:08:14 +00:00
|
|
|
// make sure packagers don't try to package "crypto"
|
|
|
|
return (require("cry" + "pto")
|
2016-11-25 11:46:17 +00:00
|
|
|
.randomBytes(length)
|
|
|
|
.toString("base64")
|
|
|
|
.slice(0, length)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
} else if (isBrowser && window.crypto && window.crypto.getRandomValues) {
|
|
|
|
exports.uid = function(length) {
|
|
|
|
var values = new Uint8Array(length);
|
|
|
|
window.crypto.getRandomValues(values);
|
|
|
|
return btoa(String.fromCharCode.apply(null, values)).slice(0, 10);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
exports.uid = function(length) {
|
|
|
|
var arr = [];
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
arr[i] = Math.floor(Math.random() * 255);
|
|
|
|
}
|
2016-11-25 13:08:14 +00:00
|
|
|
return btoa(String.fromCharCode.apply(null, arr)).slice(0, 10);
|
2016-11-25 11:46:17 +00:00
|
|
|
};
|
2016-06-26 11:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|