src/vs/base/common/uuid.ts

70 LOC · 29 covered · 41 uncovered · 5 ranges · 9304 concepts · 3 introducers · 4835 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- uuid.ts ×3
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 >
7 > const _UUIDPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8 >
9 > export function isUUID(value: string): boolean {
10 > return _UUIDPattern.test(value); uuid.ts ×1
11 > }
13 > export const generateUuid = (function (): () => string {
14 >
15 > // use `randomUUID` if possible
16 > if (typeof crypto.randomUUID === 'function') {
17 > // see https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto
18 > // > Although crypto is available on all windows, the returned Crypto object only has one
19 > // > usable feature in insecure contexts: the getRandomValues() method.
20 > // > In general, you should use this API only in secure contexts.
21 >
22 > return crypto.randomUUID.bind(crypto);
23 > }
24
25 // prep-work
26 const _data = new Uint8Array(16);
27 const _hex: string[] = [];
28 for (let i = 0; i < 256; i++) {
29 _hex.push(i.toString(16).padStart(2, '0'));
30 }
31
32 return function generateUuid(): string {
33 // get data
34 crypto.getRandomValues(_data);
35
36 // set version bits
37 _data[6] = (_data[6] & 0x0f) | 0x40;
38 _data[8] = (_data[8] & 0x3f) | 0x80;
39
40 // print as string
41 let i = 0;
42 let result = '';
43 result += _hex[_data[i++]];
44 result += _hex[_data[i++]];
45 result += _hex[_data[i++]];
46 result += _hex[_data[i++]];
47 result += '-';
48 result += _hex[_data[i++]];
49 result += _hex[_data[i++]];
50 result += '-';
51 result += _hex[_data[i++]];
52 result += _hex[_data[i++]];
53 result += '-';
54 result += _hex[_data[i++]];
55 result += _hex[_data[i++]];
56 result += '-';
57 result += _hex[_data[i++]];
58 result += _hex[_data[i++]];
59 result += _hex[_data[i++]];
60 result += _hex[_data[i++]];
61 result += _hex[_data[i++]];
62 result += _hex[_data[i++]];
63 return result;
64 };
65 > })(); uuid.ts ×3
66 >
67 > /** Namespace should be 3 letters, e.g. `abc-<uuid>`. */
68 > export function prefixedUuid(namespace: string): string {
69 > return `${namespace}-${generateUuid()}`; uuid.ts ×1
70 > }