@@ -45,7 +45,7 @@ export function to_string(term) {
45
45
}
46
46
47
47
export function float_to_string ( float ) {
48
- let string = float . toString ( ) ;
48
+ const string = float . toString ( ) ;
49
49
if ( string . indexOf ( "." ) >= 0 ) {
50
50
return string ;
51
51
} else {
@@ -133,10 +133,10 @@ export function string_length(string) {
133
133
if ( string === "" ) {
134
134
return 0 ;
135
135
}
136
- let iterator = graphemes_iterator ( string ) ;
136
+ const iterator = graphemes_iterator ( string ) ;
137
137
if ( iterator ) {
138
138
let i = 0 ;
139
- for ( let _ of iterator ) {
139
+ for ( const _ of iterator ) {
140
140
i ++ ;
141
141
}
142
142
return i ;
@@ -159,7 +159,7 @@ function graphemes_iterator(string) {
159
159
160
160
export function pop_grapheme ( string ) {
161
161
let first ;
162
- let iterator = graphemes_iterator ( string ) ;
162
+ const iterator = graphemes_iterator ( string ) ;
163
163
if ( iterator ) {
164
164
first = iterator . next ( ) . value ?. segment ;
165
165
} else {
@@ -221,10 +221,10 @@ export function ends_with(haystack, needle) {
221
221
}
222
222
223
223
export function split_once ( haystack , needle ) {
224
- let index = haystack . indexOf ( needle ) ;
224
+ const index = haystack . indexOf ( needle ) ;
225
225
if ( index >= 0 ) {
226
- let before = haystack . slice ( 0 , index ) ;
227
- let after = haystack . slice ( index + needle . length ) ;
226
+ const before = haystack . slice ( 0 , index ) ;
227
+ const after = haystack . slice ( index + needle . length ) ;
228
228
return new Ok ( [ before , after ] ) ;
229
229
} else {
230
230
return new Error ( Nil ) ;
@@ -265,7 +265,7 @@ export function crash(message) {
265
265
266
266
export function bit_string_to_string ( bit_string ) {
267
267
try {
268
- let decoder = new TextDecoder ( "utf-8" , { fatal : true } ) ;
268
+ const decoder = new TextDecoder ( "utf-8" , { fatal : true } ) ;
269
269
return new Ok ( decoder . decode ( bit_string . buffer ) ) ;
270
270
} catch ( _error ) {
271
271
return new Error ( Nil ) ;
@@ -283,7 +283,7 @@ export function print(string) {
283
283
}
284
284
285
285
export function print_error ( string ) {
286
- if ( typeof process === "object" ) {
286
+ if ( typeof process === "object" && process . stderr ?. write ) {
287
287
process . stderr . write ( string ) ; // We can write without a trailing newline
288
288
} else if ( typeof Deno === "object" ) {
289
289
Deno . stderr . writeSync ( new TextEncoder ( ) . encode ( string ) ) ; // We can write without a trailing newline
@@ -293,7 +293,7 @@ export function print_error(string) {
293
293
}
294
294
295
295
export function print_debug ( string ) {
296
- if ( typeof process === "object" ) {
296
+ if ( typeof process === "object" && process . stderr ?. write ) {
297
297
process . stderr . write ( string + "\n" ) ; // If we're in Node.js, use `stderr`
298
298
} else if ( typeof Deno === "object" ) {
299
299
Deno . stderr . writeSync ( new TextEncoder ( ) . encode ( string + "\n" ) ) ; // If we're in Deno, use `stderr`
@@ -329,7 +329,7 @@ export function power(base, exponent) {
329
329
}
330
330
331
331
export function random_uniform ( ) {
332
- let random_uniform_result = Math . random ( ) ;
332
+ const random_uniform_result = Math . random ( ) ;
333
333
// With round-to-nearest-even behavior, the ranges claimed for the functions below
334
334
// (excluding the one for Math.random() itself) aren't exact.
335
335
// If extremely large bounds are chosen (2^53 or higher),
@@ -344,10 +344,10 @@ export function random_uniform() {
344
344
}
345
345
346
346
export function bit_string_slice ( bits , position , length ) {
347
- let start = Math . min ( position , position + length ) ;
348
- let end = Math . max ( position , position + length ) ;
347
+ const start = Math . min ( position , position + length ) ;
348
+ const end = Math . max ( position , position + length ) ;
349
349
if ( start < 0 || end > bits . length ) return new Error ( Nil ) ;
350
- let buffer = new Uint8Array ( bits . buffer . buffer , start , Math . abs ( length ) ) ;
350
+ const buffer = new Uint8Array ( bits . buffer . buffer , start , Math . abs ( length ) ) ;
351
351
return new Ok ( new BitString ( buffer ) ) ;
352
352
}
353
353
@@ -381,13 +381,13 @@ export function compile_regex(pattern, options) {
381
381
if ( options . multi_line ) flags += "m" ;
382
382
return new Ok ( new RegExp ( pattern , flags ) ) ;
383
383
} catch ( error ) {
384
- let number = ( error . columnNumber || 0 ) | 0 ;
384
+ const number = ( error . columnNumber || 0 ) | 0 ;
385
385
return new Error ( new RegexCompileError ( error . message , number ) ) ;
386
386
}
387
387
}
388
388
389
389
export function regex_scan ( regex , string ) {
390
- let matches = Array . from ( string . matchAll ( regex ) ) . map ( ( match ) => {
390
+ const matches = Array . from ( string . matchAll ( regex ) ) . map ( ( match ) => {
391
391
const content = match [ 0 ] ;
392
392
const submatches = [ ] ;
393
393
for ( let n = match . length - 1 ; n > 0 ; n -- ) {
@@ -439,7 +439,7 @@ function unsafe_percent_decode(string) {
439
439
export function percent_decode ( string ) {
440
440
try {
441
441
return new Ok ( unsafe_percent_decode ( string ) ) ;
442
- } catch ( error ) {
442
+ } catch ( _error ) {
443
443
return new Error ( Nil ) ;
444
444
}
445
445
}
@@ -450,23 +450,23 @@ export function percent_encode(string) {
450
450
451
451
export function parse_query ( query ) {
452
452
try {
453
- let pairs = [ ] ;
454
- for ( let section of query . split ( "&" ) ) {
455
- let [ key , value ] = section . split ( "=" ) ;
453
+ const pairs = [ ] ;
454
+ for ( const section of query . split ( "&" ) ) {
455
+ const [ key , value ] = section . split ( "=" ) ;
456
456
if ( ! key ) continue ;
457
457
pairs . push ( [ unsafe_percent_decode ( key ) , unsafe_percent_decode ( value ) ] ) ;
458
458
}
459
459
return new Ok ( List . fromArray ( pairs ) ) ;
460
- } catch ( error ) {
460
+ } catch ( _error ) {
461
461
return new Error ( Nil ) ;
462
462
}
463
463
}
464
464
465
465
// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8
466
466
export function encode64 ( bit_string ) {
467
- let aBytes = bit_string . buffer ;
468
- let nMod3 = 2 ,
469
- sB64Enc = "" ;
467
+ const aBytes = bit_string . buffer ;
468
+ let nMod3 = 2 ;
469
+ let sB64Enc = "" ;
470
470
471
471
for ( let nLen = aBytes . length , nUint24 = 0 , nIdx = 0 ; nIdx < nLen ; nIdx ++ ) {
472
472
nMod3 = nIdx % 3 ;
@@ -524,10 +524,10 @@ function b64ToUint6(nChr) {
524
524
// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8
525
525
export function decode64 ( sBase64 ) {
526
526
if ( sBase64 . match ( / [ ^ A - Z a - z 0 - 9 \+ \/ = ] / g) ) return new Error ( Nil ) ;
527
- let sB64Enc = sBase64 . replace ( / = / g, "" ) ;
528
- let nInLen = sB64Enc . length ;
529
- let nOutLen = ( nInLen * 3 + 1 ) >> 2 ;
530
- let taBytes = new Uint8Array ( nOutLen ) ;
527
+ const sB64Enc = sBase64 . replace ( / = / g, "" ) ;
528
+ const nInLen = sB64Enc . length ;
529
+ const nOutLen = ( nInLen * 3 + 1 ) >> 2 ;
530
+ const taBytes = new Uint8Array ( nOutLen ) ;
531
531
532
532
for (
533
533
let nMod3 , nMod4 , nUint24 = 0 , nOutIdx = 0 , nInIdx = 0 ;
@@ -569,7 +569,7 @@ export function classify_dynamic(data) {
569
569
} else if ( data === undefined ) {
570
570
return "Nil" ;
571
571
} else {
572
- let type = typeof data ;
572
+ const type = typeof data ;
573
573
return type . charAt ( 0 ) . toUpperCase ( ) + type . slice ( 1 ) ;
574
574
}
575
575
}
@@ -654,7 +654,7 @@ export function decode_option(data, decoder) {
654
654
if ( data === null || data === undefined || data instanceof None )
655
655
return new Ok ( new None ( ) ) ;
656
656
if ( data instanceof Some ) data = data [ 0 ] ;
657
- let result = decoder ( data ) ;
657
+ const result = decoder ( data ) ;
658
658
if ( result . isOk ( ) ) {
659
659
return new Ok ( new Some ( result [ 0 ] ) ) ;
660
660
} else {
@@ -663,10 +663,14 @@ export function decode_option(data, decoder) {
663
663
}
664
664
665
665
export function decode_field ( value , name ) {
666
- let not_a_map_error = ( ) => decoder_error ( "Map" , value ) ;
666
+ const not_a_map_error = ( ) => decoder_error ( "Map" , value ) ;
667
667
668
- if ( value instanceof PMap || value instanceof WeakMap || value instanceof Map ) {
669
- let entry = map_get ( value , name ) ;
668
+ if (
669
+ value instanceof PMap ||
670
+ value instanceof WeakMap ||
671
+ value instanceof Map
672
+ ) {
673
+ const entry = map_get ( value , name ) ;
670
674
return new Ok ( entry . isOk ( ) ? new Some ( entry [ 0 ] ) : new None ( ) ) ;
671
675
} else if ( Object . getPrototypeOf ( value ) == Object . prototype ) {
672
676
return try_get_field ( value , name , ( ) => new Ok ( new None ( ) ) ) ;
0 commit comments