Numeric ids for generateGuid: timestamp + random

This commit is contained in:
James Barnsley
2018-03-21 09:04:08 +13:00
parent 1761456e76
commit 03f93900ce
3 changed files with 26 additions and 21 deletions

View File

@ -471,18 +471,21 @@ var digestMopidyImages = exports.digestMopidyImages = function digestMopidyImage
}; };
var generateGuid = exports.generateGuid = function generateGuid() { var generateGuid = exports.generateGuid = function generateGuid() {
var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'xxxxxxxxxxxx'; var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'numeric';
// numeric // numeric
return new Date().valueOf() + Math.random(); if (type == 'numeric') {
var date = new Date().valueOf().toString();
// alpha-numeric var random_number = Math.floor(Math.random() * 100).toString();
/* return parseInt(date + random_number);
return format.replace(/[xy]/g, function(c){ } else {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); var format = 'xxxxxxxxxx';
return v.toString(16); return format.replace(/[xy]/g, function (c) {
}); var r = Math.random() * 16 | 0,
*/ v = c == 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
}
}; };
var getCurrentPusherConnection = exports.getCurrentPusherConnection = function getCurrentPusherConnection(connections, connectionid) { var getCurrentPusherConnection = exports.getCurrentPusherConnection = function getCurrentPusherConnection(connections, connectionid) {

File diff suppressed because one or more lines are too long

View File

@ -204,17 +204,19 @@ export let digestMopidyImages = function(mopidy, images){
} }
export let generateGuid = function(format = 'xxxxxxxxxxxx'){ export let generateGuid = function(type = 'numeric'){
// numeric // numeric
return new Date().valueOf() + Math.random(); if (type == 'numeric'){
var date = new Date().valueOf().toString();
// alpha-numeric var random_number = Math.floor((Math.random() * 100)).toString();
/* return parseInt(date+random_number);
return format.replace(/[xy]/g, function(c){ } else {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); var format = 'xxxxxxxxxx';
return v.toString(16); return format.replace(/[xy]/g, function(c){
}); var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
*/ return v.toString(16);
});
}
} }
export let getCurrentPusherConnection = function(connections, connectionid){ export let getCurrentPusherConnection = function(connections, connectionid){