MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / nanoidToBytes

Function nanoidToBytes

packages/@stdlib/misc/src/nanoid.ts:12–35  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

10export const nanoidLength = 21;
11
12export function nanoidToBytes(input: string): Uint8Array {
13 const bytes = new Uint8Array(16);
14
15 let bitPos = 0;
16 let bytePos = 0;
17
18 let oldBitOffset = 0;
19
20 for (let i = 0; i < nanoidLength; i++) {
21 bytes[bytePos] |= charMap.get(input[i])! << oldBitOffset;
22
23 bitPos += 6;
24 bytePos = bitPos >>> 3;
25 const newBitOffset = bitPos % 8;
26
27 if (oldBitOffset > newBitOffset) {
28 bytes[bytePos] |= charMap.get(input[i])! >>> (8 - oldBitOffset);
29 }
30
31 oldBitOffset = newBitOffset;
32 }
33
34 return bytes;
35}
36
37const nanoidRegExp = /^[\w-]{21}$/;
38

Callers 3

data-publishing.tsFile · 0.90
getDeviceHashFunction · 0.90

Calls 1

getMethod · 0.65

Tested by

no test coverage detected