Skip to content

Instantly share code, notes, and snippets.

@ilsubyeega
Created April 30, 2025 05:23
Show Gist options
  • Save ilsubyeega/c47e8048964334d1a1a112ef460db712 to your computer and use it in GitHub Desktop.
Save ilsubyeega/c47e8048964334d1a1a112ef460db712 to your computer and use it in GitHub Desktop.
// from https://github.com/firebase/firebase-js-sdk/blob/ea1f9139e6baec0269fbb91233fd3f7f4b0d5875/packages/installations/src/helpers/generate-fid.ts#L20
const fidByteArray = new Uint8Array(17);
self.crypto.getRandomValues(fidByteArray);
fidByteArray[0] = 0b01110000 + (fidByteArray[0] % 0b00010000)
const fid = btoa(String.fromCharCode(...fidByteArray)).replace(/\+/g, '-').replace(/\//g, '_').substr(0,22);
/^[cdef][\w-]{21}$/.test(fid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment