UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

35 lines (34 loc) • 1.15 kB
/** * DevExtreme (esm/__internal/core/guid.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ export class Guid { constructor(value) { const initialValue = value ? String(value) : ""; this._value = this._normalize(initialValue || this._generate()) } _normalize(value) { let normalizedValue = value.replace(/[^a-f0-9]/gi, "").toLowerCase(); while (normalizedValue.length < 32) { normalizedValue += "0" } return [normalizedValue.slice(0, 8), normalizedValue.slice(8, 12), normalizedValue.slice(12, 16), normalizedValue.slice(16, 20), normalizedValue.slice(20, 32)].join("-") } _generate() { const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16)); return Array.from(bytes, byte => byte.toString(16).padStart(2, "0")).join("") } toString() { return this._value } valueOf() { return this._value } toJSON() { return this._value } }