UNPKG

ember-source

Version:

A JavaScript framework for creating ambitious web applications

33 lines (28 loc) 1.38 kB
import { c as createConstRef } from './reference-BshxG6wn.js'; import { i as internalHelper } from './internal-helper-DIbr1RgC.js'; /** @module ember */ const uniqueId = internalHelper(() => { // SAFETY: glimmer-vm should change the signature of createUnboundRef to use a generic // so that the type param to `Reference<?>` can infer from the first argument. // // NOTE: constRef is an optimization so we don't let the VM create extra wrappers, // tracking frames, etc. return createConstRef(uniqueId$1()); }); // From https://gist.github.com/selfish/fef2c0ba6cdfe07af76e64cecd74888b // // This code should be reasonably fast, and provide a unique value every time // it's called, which is what we need here. It produces a string formatted as a // standard UUID, which avoids accidentally turning Ember-specific // implementation details into an intimate API. It also ensures that the UUID // always starts with a letter, to avoid creating invalid IDs with a numeric // digit at the start. function uniqueId$1() { // @ts-expect-error this one-liner abuses weird JavaScript semantics that // TypeScript (legitimately) doesn't like, but they're nonetheless valid and // specced. return ([3e7] + -1e3 + -4e3 + -2e3 + -1e11).replace(/[0-3]/g, a => (a * 4 ^ Math.random() * 16 >> (a & 2)).toString(16)); } export { uniqueId as a, uniqueId$1 as u };