nish 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/AI.md +9 -2
- package/docs/INSTALL.md +6 -1
- package/package.json +15 -5
- package/runtime/nish.d.ts +4612 -430
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/base64.ts +34 -5
- package/std/bytes.ts +256 -40
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +235 -27
- package/std/net/http1-server.ts +343 -85
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +246 -96
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +723 -103
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +228 -44
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +489 -171
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +205 -35
- package/std/sync/shm.ts +194 -16
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/json-tokenizer.ts
CHANGED
|
@@ -155,8 +155,14 @@ export const JSON_TOK_ERR_WINDOW: i32 = -13
|
|
|
155
155
|
* over; and a body of 16 MiB is past what an HTTP server should buffer anyway.
|
|
156
156
|
*/
|
|
157
157
|
export const JSON_DEFAULT_MAX_DEPTH: i32 = 128
|
|
158
|
+
/**
|
|
159
|
+
* The default longest string or key: a mebibyte of raw bytes between its
|
|
160
|
+
* quotes, escapes counted as written.
|
|
161
|
+
*/
|
|
158
162
|
export const JSON_DEFAULT_MAX_STRING_BYTES: i32 = 1048576
|
|
163
|
+
/** The default longest number text, in bytes: room for any double in its shortest form. */
|
|
159
164
|
export const JSON_DEFAULT_MAX_NUMBER_BYTES: i32 = 256
|
|
165
|
+
/** The default largest window, in bytes: a 16 MiB body. */
|
|
160
166
|
export const JSON_DEFAULT_MAX_TOTAL_BYTES: i32 = 16777216
|
|
161
167
|
|
|
162
168
|
/**
|
|
@@ -543,30 +549,40 @@ const jsonTokEscapeLength = (src: u8[], at: i32, end: i32, cp: i32): i32 => {
|
|
|
543
549
|
* current token found, and are read through the methods.
|
|
544
550
|
*/
|
|
545
551
|
export class JsonTokenizer {
|
|
552
|
+
/** The bytes being read. The tokenizer never writes them. */
|
|
546
553
|
src: u8[]
|
|
547
554
|
/** The integral number `integerScan` read last, negated. */
|
|
548
|
-
integerValue: i64
|
|
555
|
+
private integerValue: i64
|
|
549
556
|
/** The integral number `unsignedScan` read last. */
|
|
550
|
-
unsignedValue: u64
|
|
557
|
+
private unsignedValue: u64
|
|
551
558
|
/** One byte per open container, `JSON_TOK_IN_OBJECT` or `JSON_TOK_IN_ARRAY`, `maxDepth` long. */
|
|
552
|
-
stack: u8[]
|
|
553
|
-
/**
|
|
559
|
+
private stack: u8[]
|
|
560
|
+
/**
|
|
561
|
+
* The window: bytes `[off, end)` of `src`.
|
|
562
|
+
*
|
|
563
|
+
* @internal Dead: written by the constructor and `reset`, never read.
|
|
564
|
+
*/
|
|
554
565
|
off: i32
|
|
555
|
-
end: i32
|
|
566
|
+
private end: i32
|
|
556
567
|
/** The next byte `next()` reads. */
|
|
557
|
-
pos: i32
|
|
558
|
-
maxDepth: i32
|
|
559
|
-
maxStringBytes: i32
|
|
560
|
-
maxNumberBytes: i32
|
|
568
|
+
private pos: i32
|
|
569
|
+
private maxDepth: i32
|
|
570
|
+
private maxStringBytes: i32
|
|
571
|
+
private maxNumberBytes: i32
|
|
572
|
+
/**
|
|
573
|
+
* @internal Read by std/yaml-json.ts, which caps the text a YAML load stores
|
|
574
|
+
* at the same limit.
|
|
575
|
+
*/
|
|
561
576
|
maxTotalBytes: i32
|
|
562
577
|
/** Containers open after the current token. */
|
|
563
578
|
depth: i32
|
|
564
579
|
/** What `next()` expects at `pos`. */
|
|
565
|
-
want: i32
|
|
580
|
+
private want: i32
|
|
566
581
|
/** The current token's kind, the last `next()` answered; `JSON_TOK_END` before the first. */
|
|
567
582
|
kind: i32
|
|
568
583
|
/** The current token's bytes, `src[tokStart, tokEnd)`; a string's and a key's include their quotes. */
|
|
569
584
|
tokStart: i32
|
|
585
|
+
/** One past the current token's last byte; see `tokStart`. */
|
|
570
586
|
tokEnd: i32
|
|
571
587
|
/** The sticky error, a negative `JSON_TOK_ERR_*` code; `0` until one. */
|
|
572
588
|
failed: i32
|
|
@@ -577,13 +593,24 @@ export class JsonTokenizer {
|
|
|
577
593
|
*/
|
|
578
594
|
errorAt: i32
|
|
579
595
|
/** The current string's or key's length once decoded; shorter than its raw length exactly when it holds an escape. */
|
|
580
|
-
stringBytes: i32
|
|
596
|
+
private stringBytes: i32
|
|
581
597
|
/**
|
|
582
598
|
* Whether the current number is written with neither a fraction nor an
|
|
583
599
|
* exponent: the spelling, so `1.0` is not. `isIntegral()` reads the value.
|
|
584
600
|
*/
|
|
585
601
|
integral: boolean
|
|
586
602
|
|
|
603
|
+
/**
|
|
604
|
+
* A tokenizer over `src[off, off + len)` held to `limits`. A negative limit
|
|
605
|
+
* counts as 0, and the depth stack is allocated here, once, `maxDepth` bytes
|
|
606
|
+
* long, and `reset` reuses it.
|
|
607
|
+
*
|
|
608
|
+
* @param src - the bytes to read, which the tokenizer only reads.
|
|
609
|
+
* @param off - the offset in `src` of the first byte of the text.
|
|
610
|
+
* @param len - how many bytes the text is.
|
|
611
|
+
* @param limits - the depth and size limits, copied, so later changes to it
|
|
612
|
+
* do not reach this tokenizer.
|
|
613
|
+
*/
|
|
587
614
|
constructor(src: u8[], off: i32, len: i32, limits: JsonLimits) {
|
|
588
615
|
this.maxDepth = limits.maxDepth < 0 ? 0 : limits.maxDepth
|
|
589
616
|
this.maxStringBytes = limits.maxStringBytes < 0 ? 0 : limits.maxStringBytes
|
|
@@ -612,6 +639,10 @@ export class JsonTokenizer {
|
|
|
612
639
|
* Starts over on `src[off, off + len)`, keeping the limits and the depth
|
|
613
640
|
* stack, and clearing any error. A window outside `src` or longer than the
|
|
614
641
|
* total limit is refused here, and the first `next()` answers it.
|
|
642
|
+
*
|
|
643
|
+
* @param src - the bytes to read next.
|
|
644
|
+
* @param off - the offset in `src` of the first byte of the text.
|
|
645
|
+
* @param len - how many bytes the text is.
|
|
615
646
|
*/
|
|
616
647
|
reset(src: u8[], off: i32, len: i32): void {
|
|
617
648
|
this.src = src
|
|
@@ -641,7 +672,7 @@ export class JsonTokenizer {
|
|
|
641
672
|
}
|
|
642
673
|
|
|
643
674
|
/** Records the first error and answers it. */
|
|
644
|
-
fail(code: i32, at: i32): i32 {
|
|
675
|
+
private fail(code: i32, at: i32): i32 {
|
|
645
676
|
if (this.failed === 0) {
|
|
646
677
|
this.failed = code
|
|
647
678
|
this.errorAt = at
|
|
@@ -649,7 +680,14 @@ export class JsonTokenizer {
|
|
|
649
680
|
return this.failed
|
|
650
681
|
}
|
|
651
682
|
|
|
652
|
-
/**
|
|
683
|
+
/**
|
|
684
|
+
* The next token's kind, `JSON_TOK_END`, or a negative error, which is
|
|
685
|
+
* sticky.
|
|
686
|
+
*
|
|
687
|
+
* @returns a `JSON_TOK_*` kind, `JSON_TOK_END` once the top-level value is
|
|
688
|
+
* complete, or a negative `JSON_TOK_ERR_*` code that every later call
|
|
689
|
+
* repeats.
|
|
690
|
+
*/
|
|
653
691
|
next(): i32 {
|
|
654
692
|
if (this.failed !== 0) {
|
|
655
693
|
return this.failed
|
|
@@ -702,7 +740,7 @@ export class JsonTokenizer {
|
|
|
702
740
|
}
|
|
703
741
|
|
|
704
742
|
/** The kind of the innermost open container, or `0` at the top level. */
|
|
705
|
-
top(): i32 {
|
|
743
|
+
private top(): i32 {
|
|
706
744
|
const d: i32 = this.depth
|
|
707
745
|
if (d <= 0 || d > toI32(this.stack.length)) {
|
|
708
746
|
return 0
|
|
@@ -711,7 +749,7 @@ export class JsonTokenizer {
|
|
|
711
749
|
}
|
|
712
750
|
|
|
713
751
|
/** Records the token `src[start, stop)` of kind `k` and what may follow it. */
|
|
714
|
-
emit(k: i32, start: i32, stop: i32): i32 {
|
|
752
|
+
private emit(k: i32, start: i32, stop: i32): i32 {
|
|
715
753
|
this.kind = k
|
|
716
754
|
this.tokStart = start
|
|
717
755
|
this.tokEnd = stop
|
|
@@ -729,7 +767,7 @@ export class JsonTokenizer {
|
|
|
729
767
|
}
|
|
730
768
|
|
|
731
769
|
/** A closer at `at`, which must match the innermost container, `inside`. */
|
|
732
|
-
close(at: i32, inside: i32): i32 {
|
|
770
|
+
private close(at: i32, inside: i32): i32 {
|
|
733
771
|
if (this.top() !== inside) {
|
|
734
772
|
return this.fail(JSON_TOK_ERR_SYNTAX, at)
|
|
735
773
|
}
|
|
@@ -738,7 +776,7 @@ export class JsonTokenizer {
|
|
|
738
776
|
}
|
|
739
777
|
|
|
740
778
|
/** An opener at `at`, refused past the depth limit. */
|
|
741
|
-
open(at: i32, inside: i32): i32 {
|
|
779
|
+
private open(at: i32, inside: i32): i32 {
|
|
742
780
|
const d: i32 = this.depth
|
|
743
781
|
if (d >= this.maxDepth || d < 0 || d >= toI32(this.stack.length)) {
|
|
744
782
|
return this.fail(JSON_TOK_ERR_DEPTH, at)
|
|
@@ -749,7 +787,7 @@ export class JsonTokenizer {
|
|
|
749
787
|
}
|
|
750
788
|
|
|
751
789
|
/** A key at `at`: a string, whose colon the next call reads. */
|
|
752
|
-
key(at: i32): i32 {
|
|
790
|
+
private key(at: i32): i32 {
|
|
753
791
|
const b: i32 = jsonTokByteAt(this.src, at, this.end)
|
|
754
792
|
if (b === JSON_TOK_QUOTE) {
|
|
755
793
|
return this.string(at, JSON_TOK_KEY)
|
|
@@ -758,7 +796,7 @@ export class JsonTokenizer {
|
|
|
758
796
|
}
|
|
759
797
|
|
|
760
798
|
/** A value at `at`. */
|
|
761
|
-
value(at: i32): i32 {
|
|
799
|
+
private value(at: i32): i32 {
|
|
762
800
|
const src: u8[] = this.src
|
|
763
801
|
const end: i32 = this.end
|
|
764
802
|
const b: i32 = jsonTokByteAt(src, at, end)
|
|
@@ -785,7 +823,7 @@ export class JsonTokenizer {
|
|
|
785
823
|
}
|
|
786
824
|
|
|
787
825
|
/** `true`, `false` or `null` at `at`; a window that ends inside the word is truncated. */
|
|
788
|
-
literal(at: i32, word: string, k: i32): i32 {
|
|
826
|
+
private literal(at: i32, word: string, k: i32): i32 {
|
|
789
827
|
const n: i32 = toI32(word.length)
|
|
790
828
|
let matched: i32 = 0
|
|
791
829
|
while (
|
|
@@ -811,7 +849,7 @@ export class JsonTokenizer {
|
|
|
811
849
|
* number that reaches that byte is refused for its length, whatever the
|
|
812
850
|
* grammar would have said of the rest.
|
|
813
851
|
*/
|
|
814
|
-
number(at: i32): i32 {
|
|
852
|
+
private number(at: i32): i32 {
|
|
815
853
|
const src: u8[] = this.src
|
|
816
854
|
const end: i32 = this.maxNumberBytes >= this.end - at ? this.end : at + this.maxNumberBytes + 1
|
|
817
855
|
let i: i32 = at
|
|
@@ -858,7 +896,7 @@ export class JsonTokenizer {
|
|
|
858
896
|
}
|
|
859
897
|
|
|
860
898
|
/** `code` at `i`, unless the number starting at `at` has run past its limit, which is the error then. */
|
|
861
|
-
numberRefused(code: i32, at: i32, i: i32): i32 {
|
|
899
|
+
private numberRefused(code: i32, at: i32, i: i32): i32 {
|
|
862
900
|
if (i - at > this.maxNumberBytes) {
|
|
863
901
|
return this.fail(JSON_TOK_ERR_NUMBER_LIMIT, at + this.maxNumberBytes)
|
|
864
902
|
}
|
|
@@ -871,7 +909,7 @@ export class JsonTokenizer {
|
|
|
871
909
|
* limit counts raw bytes and is checked at every byte, so a string past it
|
|
872
910
|
* is refused where it crosses the limit, not where it ends.
|
|
873
911
|
*/
|
|
874
|
-
string(at: i32, k: i32): i32 {
|
|
912
|
+
private string(at: i32, k: i32): i32 {
|
|
875
913
|
const src: u8[] = this.src
|
|
876
914
|
const end: i32 = this.end
|
|
877
915
|
// Where the string would pass its limit, or `end` when it cannot pass it
|
|
@@ -933,7 +971,7 @@ export class JsonTokenizer {
|
|
|
933
971
|
* joined into one, or a negative error, recorded. Used both to check a
|
|
934
972
|
* string and, on one already checked, to decode it.
|
|
935
973
|
*/
|
|
936
|
-
escapeCodePoint(at: i32): i32 {
|
|
974
|
+
private escapeCodePoint(at: i32): i32 {
|
|
937
975
|
const src: u8[] = this.src
|
|
938
976
|
const end: i32 = this.end
|
|
939
977
|
const letter: i32 = jsonTokByteAt(src, at + 1, end)
|
|
@@ -975,7 +1013,11 @@ export class JsonTokenizer {
|
|
|
975
1013
|
)
|
|
976
1014
|
}
|
|
977
1015
|
|
|
978
|
-
/**
|
|
1016
|
+
/**
|
|
1017
|
+
* Whether the current token is a key or a string.
|
|
1018
|
+
*
|
|
1019
|
+
* @returns true when the current token is a key or a string.
|
|
1020
|
+
*/
|
|
979
1021
|
isText(): boolean {
|
|
980
1022
|
return this.kind === JSON_TOK_KEY || this.kind === JSON_TOK_STRING
|
|
981
1023
|
}
|
|
@@ -984,6 +1026,10 @@ export class JsonTokenizer {
|
|
|
984
1026
|
* Writes the current key's or string's decoded bytes to `out` from `at`,
|
|
985
1027
|
* and answers how many; `-1`, writing nothing, when the current token is
|
|
986
1028
|
* neither or `out` has fewer than `stringLength()` bytes from `at`.
|
|
1029
|
+
*
|
|
1030
|
+
* @param out - the buffer the decoded bytes are written into.
|
|
1031
|
+
* @param at - the offset in `out` of the first byte written.
|
|
1032
|
+
* @returns how many bytes were written, or `-1` when nothing was.
|
|
987
1033
|
*/
|
|
988
1034
|
stringInto(out: u8[], at: i32): i32 {
|
|
989
1035
|
const n: i32 = this.stringBytes
|
|
@@ -1040,7 +1086,12 @@ export class JsonTokenizer {
|
|
|
1040
1086
|
return o - at
|
|
1041
1087
|
}
|
|
1042
1088
|
|
|
1043
|
-
/**
|
|
1089
|
+
/**
|
|
1090
|
+
* The current key's or string's length once decoded, or `-1` when the token
|
|
1091
|
+
* is neither.
|
|
1092
|
+
*
|
|
1093
|
+
* @returns the decoded length in bytes, or `-1`.
|
|
1094
|
+
*/
|
|
1044
1095
|
stringLength(): i32 {
|
|
1045
1096
|
return this.isText() ? this.stringBytes : -1
|
|
1046
1097
|
}
|
|
@@ -1054,6 +1105,9 @@ export class JsonTokenizer {
|
|
|
1054
1105
|
* not match there, and a name whose code units 0x80 to 0xFF spell those
|
|
1055
1106
|
* bytes does (`"é"` matches a key `"é"`). That is the bytes against code
|
|
1056
1107
|
* units divergence `docs/wp33-round-trip.md` §3.2 records.
|
|
1108
|
+
*
|
|
1109
|
+
* @param name - the key to compare against.
|
|
1110
|
+
* @returns true when the decoded text is `name`.
|
|
1057
1111
|
*/
|
|
1058
1112
|
keyEquals(name: string): boolean {
|
|
1059
1113
|
const n: i32 = toI32(name.length)
|
|
@@ -1105,6 +1159,9 @@ export class JsonTokenizer {
|
|
|
1105
1159
|
* exponent whose value fits in an `i64`: `-0` and `9223372036854775807`
|
|
1106
1160
|
* are, `1.0`, `1e2` and `9223372036854775808` are not. That is the
|
|
1107
1161
|
* spelling rule; `isIntegral()` asks whether the value is whole.
|
|
1162
|
+
*
|
|
1163
|
+
* @returns true when the current number is spelt as an integer that fits an
|
|
1164
|
+
* `i64`.
|
|
1108
1165
|
*/
|
|
1109
1166
|
isInteger(): boolean {
|
|
1110
1167
|
return this.kind === JSON_TOK_NUMBER && this.integral && this.integerScan()
|
|
@@ -1114,6 +1171,8 @@ export class JsonTokenizer {
|
|
|
1114
1171
|
* The current number as an `i64` when `isInteger()` holds, and `0`
|
|
1115
1172
|
* otherwise. Read it after checking `isInteger()`: a `0` alone does not say
|
|
1116
1173
|
* which.
|
|
1174
|
+
*
|
|
1175
|
+
* @returns the integer, or `0` when `isInteger()` does not hold.
|
|
1117
1176
|
*/
|
|
1118
1177
|
numberI64(): i64 {
|
|
1119
1178
|
if (!this.isInteger()) {
|
|
@@ -1130,7 +1189,7 @@ export class JsonTokenizer {
|
|
|
1130
1189
|
* negative number reaches -2^63, where a positive one stops at 2^63 - 1, so
|
|
1131
1190
|
* the bound for a positive number is one less.
|
|
1132
1191
|
*/
|
|
1133
|
-
integerScan(): boolean {
|
|
1192
|
+
private integerScan(): boolean {
|
|
1134
1193
|
const src: u8[] = this.src
|
|
1135
1194
|
const end: i32 = this.tokEnd
|
|
1136
1195
|
const negative: boolean = jsonTokByteAt(src, this.tokStart, end) === JSON_TOK_MINUS
|
|
@@ -1163,6 +1222,9 @@ export class JsonTokenizer {
|
|
|
1163
1222
|
* sign, fraction or exponent, whose value fits in a `u64`: `0` and
|
|
1164
1223
|
* `18446744073709551615` are; `-0`, `-1`, `1.0`, `1e2` and
|
|
1165
1224
|
* `18446744073709551616` are not.
|
|
1225
|
+
*
|
|
1226
|
+
* @returns true when the current number is spelt as an unsigned integer that
|
|
1227
|
+
* fits a `u64`.
|
|
1166
1228
|
*/
|
|
1167
1229
|
isU64(): boolean {
|
|
1168
1230
|
return this.kind === JSON_TOK_NUMBER && this.integral && this.unsignedScan()
|
|
@@ -1171,6 +1233,8 @@ export class JsonTokenizer {
|
|
|
1171
1233
|
/**
|
|
1172
1234
|
* The current number as a `u64` when `isU64()` holds, and `0` otherwise.
|
|
1173
1235
|
* Read it after checking `isU64()`: a `0` alone does not say which.
|
|
1236
|
+
*
|
|
1237
|
+
* @returns the integer, or `0` when `isU64()` does not hold.
|
|
1174
1238
|
*/
|
|
1175
1239
|
numberU64(): u64 {
|
|
1176
1240
|
return this.isU64() ? this.unsignedValue : toU64(0)
|
|
@@ -1184,7 +1248,7 @@ export class JsonTokenizer {
|
|
|
1184
1248
|
* 19 digits no greater than 2^64 - 1's last 19, 8446744073709551615, so the
|
|
1185
1249
|
* sum never wraps and needs no divide.
|
|
1186
1250
|
*/
|
|
1187
|
-
unsignedScan(): boolean {
|
|
1251
|
+
private unsignedScan(): boolean {
|
|
1188
1252
|
const src: u8[] = this.src
|
|
1189
1253
|
const end: i32 = this.tokEnd
|
|
1190
1254
|
const n: i32 = toI32(src.length)
|
|
@@ -1237,6 +1301,8 @@ export class JsonTokenizer {
|
|
|
1237
1301
|
* zero or E - F + z >= 0. F and z count bytes of the token, so F - z fits an
|
|
1238
1302
|
* `i32` whatever the limits, and `jsonTokDigitsExceed` compares E with it
|
|
1239
1303
|
* without adding up more of E than it needs, so `1e99999999999` answers too.
|
|
1304
|
+
*
|
|
1305
|
+
* @returns true when the current number's value is a whole number.
|
|
1240
1306
|
*/
|
|
1241
1307
|
isIntegral(): boolean {
|
|
1242
1308
|
if (this.kind !== JSON_TOK_NUMBER) {
|
|
@@ -1301,6 +1367,8 @@ export class JsonTokenizer {
|
|
|
1301
1367
|
* reads it: `-0` is negative zero, a magnitude past the largest double is
|
|
1302
1368
|
* an infinity and one below the smallest is zero. `0` when the current
|
|
1303
1369
|
* token is not a number.
|
|
1370
|
+
*
|
|
1371
|
+
* @returns the nearest double, or `0` when the current token is not a number.
|
|
1304
1372
|
*/
|
|
1305
1373
|
numberF64(): f64 {
|
|
1306
1374
|
if (this.kind !== JSON_TOK_NUMBER) {
|
|
@@ -1390,7 +1458,7 @@ export class JsonTokenizer {
|
|
|
1390
1458
|
* runs under Node. A token outside `src` can only mean the caller shortened
|
|
1391
1459
|
* the array after `next()` read it, and answers `0` rather than panic.
|
|
1392
1460
|
*/
|
|
1393
|
-
numberSlow(): f64 {
|
|
1461
|
+
private numberSlow(): f64 {
|
|
1394
1462
|
const src: u8[] = this.src
|
|
1395
1463
|
const start: i32 = this.tokStart
|
|
1396
1464
|
const end: i32 = this.tokEnd
|
|
@@ -1406,6 +1474,9 @@ export class JsonTokenizer {
|
|
|
1406
1474
|
* opener, everything up to and including its closer; after a scalar or a
|
|
1407
1475
|
* closer, nothing. Answers the kind of the last token it read (the closer,
|
|
1408
1476
|
* or the scalar), or a negative error.
|
|
1477
|
+
*
|
|
1478
|
+
* @returns the kind of the last token read, or a negative `JSON_TOK_ERR_*`
|
|
1479
|
+
* code.
|
|
1409
1480
|
*/
|
|
1410
1481
|
skipValue(): i32 {
|
|
1411
1482
|
if (this.failed !== 0) {
|