1- "use strict" ;
2- Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
3- exports . ulid = void 0 ;
4- exports . replaceCharAt = replaceCharAt ;
5- exports . incrementBase32 = incrementBase32 ;
6- exports . randomChar = randomChar ;
7- exports . encodeTime = encodeTime ;
8- exports . encodeRandom = encodeRandom ;
9- exports . decodeTime = decodeTime ;
10- exports . detectPrng = detectPrng ;
11- exports . factory = factory ;
12- exports . monotonicFactory = monotonicFactory ;
131function createError ( message ) {
142 const err = new Error ( message ) ;
153 err . source = "ulid" ;
@@ -22,13 +10,13 @@ const ENCODING_LEN = ENCODING.length;
2210const TIME_MAX = Math . pow ( 2 , 48 ) - 1 ;
2311const TIME_LEN = 10 ;
2412const RANDOM_LEN = 16 ;
25- function replaceCharAt ( str , index , char ) {
13+ export function replaceCharAt ( str , index , char ) {
2614 if ( index > str . length - 1 ) {
2715 return str ;
2816 }
2917 return str . substr ( 0 , index ) + char + str . substr ( index + 1 ) ;
3018}
31- function incrementBase32 ( str ) {
19+ export function incrementBase32 ( str ) {
3220 let done = undefined ;
3321 let index = str . length ;
3422 let char ;
@@ -51,14 +39,14 @@ function incrementBase32(str) {
5139 }
5240 throw createError ( "cannot increment this string" ) ;
5341}
54- function randomChar ( prng ) {
42+ export function randomChar ( prng ) {
5543 let rand = Math . floor ( prng ( ) * ENCODING_LEN ) ;
5644 if ( rand === ENCODING_LEN ) {
5745 rand = ENCODING_LEN - 1 ;
5846 }
5947 return ENCODING . charAt ( rand ) ;
6048}
61- function encodeTime ( now , len ) {
49+ export function encodeTime ( now , len ) {
6250 if ( isNaN ( now ) ) {
6351 throw new Error ( now + " must be a number" ) ;
6452 }
@@ -80,14 +68,14 @@ function encodeTime(now, len) {
8068 }
8169 return str ;
8270}
83- function encodeRandom ( len , prng ) {
71+ export function encodeRandom ( len , prng ) {
8472 let str = "" ;
8573 for ( ; len > 0 ; len -- ) {
8674 str = randomChar ( prng ) + str ;
8775 }
8876 return str ;
8977}
90- function decodeTime ( id ) {
78+ export function decodeTime ( id ) {
9179 if ( id . length !== TIME_LEN + RANDOM_LEN ) {
9280 throw createError ( "malformed ulid" ) ;
9381 }
@@ -107,7 +95,7 @@ function decodeTime(id) {
10795 }
10896 return time ;
10997}
110- function detectPrng ( allowInsecure = false , root ) {
98+ export function detectPrng ( allowInsecure = false , root ) {
11199 if ( ! root ) {
112100 root = typeof window !== "undefined" ? window : null ;
113101 }
@@ -135,7 +123,7 @@ function detectPrng(allowInsecure = false, root) {
135123 }
136124 throw createError ( "secure crypto unusable, insecure Math.random not allowed" ) ;
137125}
138- function factory ( currPrng ) {
126+ export function factory ( currPrng ) {
139127 if ( ! currPrng ) {
140128 currPrng = detectPrng ( ) ;
141129 }
@@ -146,7 +134,7 @@ function factory(currPrng) {
146134 return encodeTime ( seedTime , TIME_LEN ) + encodeRandom ( RANDOM_LEN , currPrng ) ;
147135 } ;
148136}
149- function monotonicFactory ( currPrng ) {
137+ export function monotonicFactory ( currPrng ) {
150138 if ( ! currPrng ) {
151139 currPrng = detectPrng ( ) ;
152140 }
@@ -165,4 +153,4 @@ function monotonicFactory(currPrng) {
165153 return encodeTime ( seedTime , TIME_LEN ) + newRandom ;
166154 } ;
167155}
168- exports . ulid = factory ( ) ;
156+ export const ulid = factory ( ) ;
0 commit comments