@@ -10,13 +10,13 @@ const ENCODING_LEN = ENCODING.length;
1010const TIME_MAX = Math . pow ( 2 , 48 ) - 1 ;
1111const TIME_LEN = 10 ;
1212const RANDOM_LEN = 16 ;
13- function replaceCharAt ( str , index , char ) {
13+ export function replaceCharAt ( str , index , char ) {
1414 if ( index > str . length - 1 ) {
1515 return str ;
1616 }
1717 return str . substr ( 0 , index ) + char + str . substr ( index + 1 ) ;
1818}
19- function incrementBase32 ( str ) {
19+ export function incrementBase32 ( str ) {
2020 let done = undefined ;
2121 let index = str . length ;
2222 let char ;
@@ -39,14 +39,14 @@ function incrementBase32(str) {
3939 }
4040 throw createError ( "cannot increment this string" ) ;
4141}
42- function randomChar ( prng ) {
42+ export function randomChar ( prng ) {
4343 let rand = Math . floor ( prng ( ) * ENCODING_LEN ) ;
4444 if ( rand === ENCODING_LEN ) {
4545 rand = ENCODING_LEN - 1 ;
4646 }
4747 return ENCODING . charAt ( rand ) ;
4848}
49- function encodeTime ( now , len ) {
49+ export function encodeTime ( now , len ) {
5050 if ( isNaN ( now ) ) {
5151 throw new Error ( now + " must be a number" ) ;
5252 }
@@ -68,14 +68,14 @@ function encodeTime(now, len) {
6868 }
6969 return str ;
7070}
71- function encodeRandom ( len , prng ) {
71+ export function encodeRandom ( len , prng ) {
7272 let str = "" ;
7373 for ( ; len > 0 ; len -- ) {
7474 str = randomChar ( prng ) + str ;
7575 }
7676 return str ;
7777}
78- function decodeTime ( id ) {
78+ export function decodeTime ( id ) {
7979 if ( id . length !== TIME_LEN + RANDOM_LEN ) {
8080 throw createError ( "malformed ulid" ) ;
8181 }
@@ -95,7 +95,7 @@ function decodeTime(id) {
9595 }
9696 return time ;
9797}
98- function detectPrng ( allowInsecure = false , root ) {
98+ export function detectPrng ( allowInsecure = false , root ) {
9999 if ( ! root ) {
100100 root = typeof window !== "undefined" ? window : null ;
101101 }
@@ -122,7 +122,7 @@ function detectPrng(allowInsecure = false, root) {
122122 }
123123 throw createError ( "secure crypto unusable, insecure Math.random not allowedW" ) ;
124124}
125- function factory ( currPrng ) {
125+ export function factory ( currPrng ) {
126126 if ( ! currPrng ) {
127127 currPrng = detectPrng ( ) ;
128128 }
@@ -133,7 +133,7 @@ function factory(currPrng) {
133133 return encodeTime ( seedTime , TIME_LEN ) + encodeRandom ( RANDOM_LEN , currPrng ) ;
134134 } ;
135135}
136- function monotonicFactory ( currPrng ) {
136+ export function monotonicFactory ( currPrng ) {
137137 if ( ! currPrng ) {
138138 currPrng = detectPrng ( ) ;
139139 }
@@ -152,6 +152,4 @@ function monotonicFactory(currPrng) {
152152 return encodeTime ( seedTime , TIME_LEN ) + newRandom ;
153153 } ;
154154}
155- const ulid = factory ( ) ;
156-
157- export { replaceCharAt , incrementBase32 , randomChar , encodeTime , encodeRandom , decodeTime , detectPrng , factory , monotonicFactory , ulid } ;
155+ export const ulid = factory ( ) ;
0 commit comments