source: imaps-frontend/node_modules/uuid/dist/esm-browser/v35.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[79a0317]1import parse from './parse.js';
2import { unsafeStringify } from './stringify.js';
3export function stringToBytes(str) {
4 str = unescape(encodeURIComponent(str));
5 const bytes = new Uint8Array(str.length);
6 for (let i = 0; i < str.length; ++i) {
7 bytes[i] = str.charCodeAt(i);
8 }
9 return bytes;
10}
11export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
12export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
13export default function v35(version, hash, value, namespace, buf, offset) {
14 const valueBytes = typeof value === 'string' ? stringToBytes(value) : value;
15 const namespaceBytes = typeof namespace === 'string' ? parse(namespace) : namespace;
16 if (typeof namespace === 'string') {
17 namespace = parse(namespace);
18 }
19 if (namespace?.length !== 16) {
20 throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
21 }
22 let bytes = new Uint8Array(16 + valueBytes.length);
23 bytes.set(namespaceBytes);
24 bytes.set(valueBytes, namespaceBytes.length);
25 bytes = hash(bytes);
26 bytes[6] = (bytes[6] & 0x0f) | version;
27 bytes[8] = (bytes[8] & 0x3f) | 0x80;
28 if (buf) {
29 offset = offset || 0;
30 for (let i = 0; i < 16; ++i) {
31 buf[offset + i] = bytes[i];
32 }
33 return buf;
34 }
35 return unsafeStringify(bytes);
36}
Note: See TracBrowser for help on using the repository browser.