make uid function reusable
This commit is contained in:
@@ -7,6 +7,11 @@ define([], function () {
|
|||||||
}, map));
|
}, map));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Util.uid = function () {
|
||||||
|
return Number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER))
|
||||||
|
.toString(32).replace(/\./g, '');
|
||||||
|
};
|
||||||
|
|
||||||
Util.fixHTML = function (str) {
|
Util.fixHTML = function (str) {
|
||||||
if (!str) { return ''; }
|
if (!str) { return ''; }
|
||||||
return str.replace(/[<>&"']/g, function (x) {
|
return str.replace(/[<>&"']/g, function (x) {
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ define([
|
|||||||
common.createRandomInteger = Util.createRandomInteger;
|
common.createRandomInteger = Util.createRandomInteger;
|
||||||
common.getAppType = Util.getAppType;
|
common.getAppType = Util.getAppType;
|
||||||
common.notAgainForAnother = Util.notAgainForAnother;
|
common.notAgainForAnother = Util.notAgainForAnother;
|
||||||
|
common.uid = Util.uid;
|
||||||
|
|
||||||
// import hash utilities for export
|
// import hash utilities for export
|
||||||
var createRandomHash = common.createRandomHash = Hash.createRandomHash;
|
var createRandomHash = common.createRandomHash = Hash.createRandomHash;
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
define([
|
define([
|
||||||
|
'/common/common-util.js',
|
||||||
'/bower_components/tweetnacl/nacl-fast.min.js',
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
||||||
], function () {
|
], function (Util) {
|
||||||
var Nacl = window.nacl;
|
var Nacl = window.nacl;
|
||||||
|
|
||||||
var uid = function () {
|
var uid = Util.uid;
|
||||||
return Number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER))
|
|
||||||
.toString(32).replace(/\./g, '');
|
|
||||||
};
|
|
||||||
|
|
||||||
var signMsg = function (data, signKey) {
|
var signMsg = function (data, signKey) {
|
||||||
var buffer = Nacl.util.decodeUTF8(JSON.stringify(data));
|
var buffer = Nacl.util.decodeUTF8(JSON.stringify(data));
|
||||||
return Nacl.util.encodeBase64(Nacl.sign.detached(buffer, signKey));
|
return Nacl.util.encodeBase64(Nacl.sign.detached(buffer, signKey));
|
||||||
|
|||||||
Reference in New Issue
Block a user