Files
Superalgos/Projects/Superalgos/TS/Utilities/MiscellaneousFunctions.js
T

26 lines
749 B
JavaScript

exports.newSuperalgosUtilitiesMiscellaneousFunctions = function () {
let thisObject = {
genereteUniqueId: genereteUniqueId,
truncateToThisPrecision: truncateToThisPrecision,
pad: pad
}
return thisObject
function genereteUniqueId () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8)
return v.toString(16)
})
}
function truncateToThisPrecision(floatNumber, precision) {
return parseFloat(floatNumber.toFixed(precision))
}
function pad(str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
}