File size: 371 Bytes
4e23b01
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { isValid, ulid } from 'ulid';

export const ulidRegex = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;

export function parseOrGenerateRequestId(headerValue: string | undefined): string {
  if (typeof headerValue === 'string' && isValid(headerValue)) {
    return headerValue;
  }
  return ulid();
}

export function isUlid(value: string): boolean {
  return isValid(value);
}