Files
Bubberstation/tgui/packages/common/uuid.ts
SkyratBot c98d76bca5 [MIRROR] Tgui: More common components in ts (#27674)
* Tgui: More common components in ts (#83098)

## About The Pull Request
Converts more of common into typescript, with some tests
## Why It's Good For The Game
Typescript,,,,

* Tgui: More common components in ts

---------

Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>
2024-05-15 00:57:58 +02:00

25 lines
487 B
TypeScript

/**
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
/**
* Creates a UUID v4 string
*
* @example
* ```tsx
* createUuid(); // 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
* ```
*/
export function createUuid(): string {
let d = new Date().getTime();
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
});
}