-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathconstants.ts
More file actions
20 lines (19 loc) · 983 Bytes
/
constants.ts
File metadata and controls
20 lines (19 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// These values should NEVER change. The values are precisely for
// generating ULIDs.
export const B32_CHARACTERS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
export const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; // Crockford's Base32
export const ENCODING_LEN = 32; // from ENCODING.length;
export const MAX_ULID = "7ZZZZZZZZZZZZZZZZZZZZZZZZZ";
export const MIN_ULID = "00000000000000000000000000";
export const RANDOM_LEN = 16;
export const TIME_LEN = 10;
export const TIME_MAX = 281474976710655; // from Math.pow(2, 48) - 1;
export const ULID_REGEX = /^[0-7][0-9a-hjkmnp-tv-zA-HJKMNP-TV-Z]{25}$/;
export const UUID_REGEX = /^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$/;
// fast lookup of index, avoid O(n) indexOf calls
export const ENCODING_LOOKUP = new Map<string, number>(
ENCODING.split("").map((char, index) => [char, index])
);
export const B32_CHARACTERS_LOOKUP = new Map<string, number>(
B32_CHARACTERS.split("").map((char, index) => [char, index])
);