I'm using the following typescript method to generate UUID
s. The code itself is basically the typescript version of this stackoverflow answer.
generateUUID(): string {
let date = new Date().getTime();
if (window.performance && typeof window.performance.now === 'function') {
date += performance.now();
}
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
let r = (date + Math.random() * 16) % 16 | 0;
date = Math.floor(date / 16);
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
};
Our development team uses TSLint
to keep the code clean and we have a rule that forbids to use bitwise operators
. I have no idea how to rewrite this code without harming the cryptographic aspect of the UUID generator. How can this piece of code be rewritten or doesn't this make sense at all?
/* tslint:disable */
and/* tslint:enable */
(Or be more specific about the rule we are "accepting", see palantir.github.io/tslint/usage/rule-flags ) – Coalfield1 && 1 === 1
and1 & 1 === 0
. – Profluent