nish 0.35.0 → 0.37.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.
Files changed (129) hide show
  1. package/docs/AI.md +50 -4
  2. package/docs/INSTALL.md +73 -59
  3. package/package.json +19 -5
  4. package/runtime/async.d.mts +2 -0
  5. package/runtime/async.mjs +7 -0
  6. package/runtime/nish.d.ts +4849 -430
  7. package/runtime/nish.h +25 -0
  8. package/runtime/page.d.ts +53 -0
  9. package/runtime/page.mjs +146 -0
  10. package/runtime/runtime-async.c +557 -0
  11. package/runtime/runtime-wasm.c +63 -7
  12. package/runtime/vite.d.ts +30 -0
  13. package/runtime/vite.mjs +150 -0
  14. package/scripts/build.sh +252 -15
  15. package/scripts/fuzz.sh +1 -0
  16. package/scripts/undocumented.txt +14 -0
  17. package/std/README.md +107 -82
  18. package/std/base64.ts +34 -5
  19. package/std/bytes.ts +279 -59
  20. package/std/cli-args.ts +296 -70
  21. package/std/cli-flags.ts +184 -19
  22. package/std/cli.ts +475 -54
  23. package/std/collections.ts +121 -23
  24. package/std/compress/checksum.ts +44 -14
  25. package/std/compress/deflate.ts +224 -111
  26. package/std/compress/gzip.ts +217 -53
  27. package/std/compress/zlib.ts +63 -7
  28. package/std/crypto/aes.ts +128 -52
  29. package/std/crypto/base64url.ts +29 -5
  30. package/std/crypto/bcrypt-batch.ts +101 -34
  31. package/std/crypto/bcrypt.ts +93 -27
  32. package/std/crypto/chacha20poly1305.ts +69 -14
  33. package/std/crypto/ct.ts +32 -13
  34. package/std/crypto/ed25519.ts +66 -16
  35. package/std/crypto/hkdf.ts +198 -13
  36. package/std/crypto/hmac.ts +242 -37
  37. package/std/crypto/jwt.ts +204 -72
  38. package/std/crypto/p256.ts +222 -72
  39. package/std/crypto/p384.ts +51 -23
  40. package/std/crypto/pki-roots.ts +32 -2
  41. package/std/crypto/pki.ts +99 -30
  42. package/std/crypto/rsa.ts +56 -22
  43. package/std/crypto/sha1.ts +3 -0
  44. package/std/crypto/sha256.ts +24 -1
  45. package/std/crypto/sha512.ts +99 -14
  46. package/std/crypto/x25519.ts +163 -24
  47. package/std/crypto/x509-random.ts +10 -0
  48. package/std/crypto/x509.ts +133 -66
  49. package/std/host/ring.ts +124 -0
  50. package/std/json-equal.ts +31 -11
  51. package/std/json-format.ts +112 -13
  52. package/std/json-number.ts +76 -26
  53. package/std/json-pointer.ts +23 -1
  54. package/std/json-tokenizer.ts +126 -51
  55. package/std/json-typed.ts +757 -96
  56. package/std/json-value.ts +438 -157
  57. package/std/json.ts +170 -38
  58. package/std/map.ts +25 -7
  59. package/std/math.ts +36 -4
  60. package/std/net/buffer-pool.ts +42 -11
  61. package/std/net/dns-config.ts +109 -23
  62. package/std/net/dns-message.ts +62 -7
  63. package/std/net/dns-resolver.ts +247 -53
  64. package/std/net/dns.ts +203 -35
  65. package/std/net/fetch.ts +1267 -290
  66. package/std/net/handler.ts +296 -80
  67. package/std/net/hpack.ts +290 -77
  68. package/std/net/http-compress.ts +152 -36
  69. package/std/net/http-fields.ts +85 -9
  70. package/std/net/http1-client-codec.ts +129 -44
  71. package/std/net/http1-codec.ts +279 -114
  72. package/std/net/http1-server.ts +409 -139
  73. package/std/net/http2-frame.ts +289 -51
  74. package/std/net/http2-tls.ts +152 -49
  75. package/std/net/http2.ts +314 -160
  76. package/std/net/http3-frame.ts +165 -27
  77. package/std/net/http3-server.ts +282 -131
  78. package/std/net/http3.ts +377 -173
  79. package/std/net/outbound.ts +37 -3
  80. package/std/net/postgres-carrier.ts +144 -8
  81. package/std/net/postgres.ts +898 -260
  82. package/std/net/prefork.ts +202 -65
  83. package/std/net/qpack.ts +120 -32
  84. package/std/net/quic-conn-ack.ts +60 -12
  85. package/std/net/quic-conn-cid.ts +135 -27
  86. package/std/net/quic-conn-params.ts +109 -22
  87. package/std/net/quic-datagram.ts +50 -3
  88. package/std/net/quic-frame.ts +333 -23
  89. package/std/net/quic-listener.ts +161 -75
  90. package/std/net/quic-packet.ts +373 -73
  91. package/std/net/quic-recovery.ts +287 -65
  92. package/std/net/quic-stream.ts +436 -146
  93. package/std/net/quic.ts +693 -323
  94. package/std/net/router.ts +87 -40
  95. package/std/net/tls/client.ts +167 -51
  96. package/std/net/tls/codec.ts +494 -68
  97. package/std/net/tls/record-client.ts +140 -73
  98. package/std/net/tls/record-server.ts +233 -105
  99. package/std/net/tls/record.ts +142 -36
  100. package/std/net/tls/schedule.ts +235 -26
  101. package/std/net/tls/ticket.ts +161 -40
  102. package/std/net/tls/verify.ts +57 -10
  103. package/std/net/tls-tcp.ts +308 -95
  104. package/std/net/tls.ts +276 -102
  105. package/std/net/upstream.ts +81 -45
  106. package/std/net/url.ts +109 -22
  107. package/std/net/websocket.ts +140 -26
  108. package/std/net/webtransport.ts +243 -106
  109. package/std/pair.ts +10 -2
  110. package/std/random.ts +42 -15
  111. package/std/regex.ts +422 -257
  112. package/std/region.ts +70 -15
  113. package/std/secret.ts +52 -11
  114. package/std/sort.ts +17 -2
  115. package/std/sqlite.ts +256 -35
  116. package/std/sync/ring.ts +229 -56
  117. package/std/sync/shm.ts +203 -23
  118. package/std/term-io.ts +154 -78
  119. package/std/term-pixels.ts +144 -19
  120. package/std/term-probe.ts +77 -35
  121. package/std/term-rate.ts +199 -118
  122. package/std/term.ts +400 -175
  123. package/std/testing.ts +130 -32
  124. package/std/text.ts +84 -17
  125. package/std/threads.ts +248 -56
  126. package/std/yaml-json.ts +111 -97
  127. package/std/yaml-lines.ts +47 -15
  128. package/std/yaml-write.ts +45 -30
  129. package/std/yaml.ts +764 -384
@@ -42,31 +42,35 @@
42
42
  * any well-formed UTF-8 (RFC 3629: no overlong form, no surrogate code point,
43
43
  * nothing past U+10FFFF, no sequence cut short), no raw byte below 0x20, and
44
44
  * the escapes of RFC 8259 §7. A `\u` escape of a high surrogate must be
45
- * followed at once by one of a low surrogate, and a low surrogate must follow
46
- * a high one: a lone surrogate escape is an error. RFC 8259 allows one, but it
47
- * names no Unicode character, decodes to no valid UTF-8, and is what a peer
48
- * smuggles past a check done on the decoded bytes, so this module takes the
49
- * stricter reading (`docs/security/json.md`, "Lone surrogates"). Nothing is decoded until
50
- * the caller asks: `stringInto` writes the decoded bytes of the current key
51
- * or string into the caller's array, and `keyEquals` compares them with a
52
- * string without writing them anywhere.
45
+ * followed at once by one of a low surrogate, and a low surrogate must follow a
46
+ * high one: a lone surrogate escape is an error.
47
+ *
48
+ * RFC 8259 allows one, but it names no Unicode character, decodes to no valid
49
+ * UTF-8, and is what a peer smuggles past a check done on the decoded bytes, so
50
+ * this module takes the stricter reading (`docs/security/json.md`, "Lone
51
+ * surrogates"). Nothing is decoded until the caller asks: `stringInto` writes
52
+ * the decoded bytes of the current key or string into the caller's array, and
53
+ * `keyEquals` compares them with a string without writing them anywhere.
53
54
  *
54
55
  * **Numbers are checked against the grammar and parsed on request.**
55
56
  * `numberF64` is correctly rounded, ties to even, in one of three ways. A
56
- * number of at most 19 significant digits is read into a `u64`. When that is
57
- * at most 2^53 and the decimal exponent is within ±22, the answer is one exact
58
- * multiply or divide of two exact doubles (Clinger's fast path). Any other
59
- * number of at most 19 digits is the Eisel–Lemire algorithm as fast_float
60
- * computes it: one or two 64×64-bit products with a truncated power of five,
61
- * which Mushtak and Lemire prove always decide the rounding for so few digits,
62
- * so it never needs a fallback. A number of more digits, or with an exponent
63
- * past `JSON_TOK_EXPONENT_CAP`, goes to the runtime's `parseFloat`, which is
64
- * `strtod`, from a function whose own arena scope releases the copy it reads,
65
- * so it leaves the arena where it was. `isInteger` and `numberI64` read a number
66
- * written without a fraction or an exponent that fits in an `i64`, and
67
- * `isU64` and `numberU64` one written without a sign either that fits in a
68
- * `u64`. Those go by spelling; `isIntegral` asks whether the value is whole,
69
- * however it is written (`1.0`, `1e2`), from the text and at any size.
57
+ * number of at most 19 significant digits is read into a `u64`. When that is at
58
+ * most 2^53 and the decimal exponent is within ±22, the answer is one exact
59
+ * multiply or divide of two exact doubles (Clinger's fast path).
60
+ *
61
+ * Any other number of at most 19 digits is the Eisel–Lemire algorithm as
62
+ * fast_float computes it: one or two 64×64-bit products with a truncated power
63
+ * of five, which Mushtak and Lemire prove always decide the rounding for so few
64
+ * digits, so it never needs a fallback. A number of more digits, or with an
65
+ * exponent past `JSON_TOK_EXPONENT_CAP`, goes to the runtime's `parseFloat`,
66
+ * which is `strtod`, from a function whose own arena scope releases the copy it
67
+ * reads, so it leaves the arena where it was.
68
+ *
69
+ * `isInteger` and `numberI64` read a number written without a fraction or an
70
+ * exponent that fits in an `i64`, and `isU64` and `numberU64` one written
71
+ * without a sign either that fits in a `u64`. Those go by spelling;
72
+ * `isIntegral` asks whether the value is whole, however it is written (`1.0`,
73
+ * `1e2`), from the text and at any size.
70
74
  *
71
75
  * **Runs are read in bulk.** A string's plain bytes, the blanks between
72
76
  * tokens and a number's digits are each stepped over by a loop that reads
@@ -155,8 +159,14 @@ export const JSON_TOK_ERR_WINDOW: i32 = -13
155
159
  * over; and a body of 16 MiB is past what an HTTP server should buffer anyway.
156
160
  */
157
161
  export const JSON_DEFAULT_MAX_DEPTH: i32 = 128
162
+ /**
163
+ * The default longest string or key: a mebibyte of raw bytes between its
164
+ * quotes, escapes counted as written.
165
+ */
158
166
  export const JSON_DEFAULT_MAX_STRING_BYTES: i32 = 1048576
167
+ /** The default longest number text, in bytes: room for any double in its shortest form. */
159
168
  export const JSON_DEFAULT_MAX_NUMBER_BYTES: i32 = 256
169
+ /** The default largest window, in bytes: a 16 MiB body. */
160
170
  export const JSON_DEFAULT_MAX_TOTAL_BYTES: i32 = 16777216
161
171
 
162
172
  /**
@@ -543,30 +553,40 @@ const jsonTokEscapeLength = (src: u8[], at: i32, end: i32, cp: i32): i32 => {
543
553
  * current token found, and are read through the methods.
544
554
  */
545
555
  export class JsonTokenizer {
556
+ /** The bytes being read. The tokenizer never writes them. */
546
557
  src: u8[]
547
558
  /** The integral number `integerScan` read last, negated. */
548
- integerValue: i64
559
+ private integerValue: i64
549
560
  /** The integral number `unsignedScan` read last. */
550
- unsignedValue: u64
561
+ private unsignedValue: u64
551
562
  /** One byte per open container, `JSON_TOK_IN_OBJECT` or `JSON_TOK_IN_ARRAY`, `maxDepth` long. */
552
- stack: u8[]
553
- /** The window: bytes `[off, end)` of `src`. */
563
+ private stack: u8[]
564
+ /**
565
+ * The window: bytes `[off, end)` of `src`.
566
+ *
567
+ * @internal Dead: written by the constructor and `reset`, never read.
568
+ */
554
569
  off: i32
555
- end: i32
570
+ private end: i32
556
571
  /** The next byte `next()` reads. */
557
- pos: i32
558
- maxDepth: i32
559
- maxStringBytes: i32
560
- maxNumberBytes: i32
572
+ private pos: i32
573
+ private maxDepth: i32
574
+ private maxStringBytes: i32
575
+ private maxNumberBytes: i32
576
+ /**
577
+ * @internal Read by std/yaml-json.ts, which caps the text a YAML load stores
578
+ * at the same limit.
579
+ */
561
580
  maxTotalBytes: i32
562
581
  /** Containers open after the current token. */
563
582
  depth: i32
564
583
  /** What `next()` expects at `pos`. */
565
- want: i32
584
+ private want: i32
566
585
  /** The current token's kind, the last `next()` answered; `JSON_TOK_END` before the first. */
567
586
  kind: i32
568
587
  /** The current token's bytes, `src[tokStart, tokEnd)`; a string's and a key's include their quotes. */
569
588
  tokStart: i32
589
+ /** One past the current token's last byte; see `tokStart`. */
570
590
  tokEnd: i32
571
591
  /** The sticky error, a negative `JSON_TOK_ERR_*` code; `0` until one. */
572
592
  failed: i32
@@ -577,13 +597,24 @@ export class JsonTokenizer {
577
597
  */
578
598
  errorAt: i32
579
599
  /** The current string's or key's length once decoded; shorter than its raw length exactly when it holds an escape. */
580
- stringBytes: i32
600
+ private stringBytes: i32
581
601
  /**
582
602
  * Whether the current number is written with neither a fraction nor an
583
603
  * exponent: the spelling, so `1.0` is not. `isIntegral()` reads the value.
584
604
  */
585
605
  integral: boolean
586
606
 
607
+ /**
608
+ * A tokenizer over `src[off, off + len)` held to `limits`. A negative limit
609
+ * counts as 0, and the depth stack is allocated here, once, `maxDepth` bytes
610
+ * long, and `reset` reuses it.
611
+ *
612
+ * @param src - the bytes to read, which the tokenizer only reads.
613
+ * @param off - the offset in `src` of the first byte of the text.
614
+ * @param len - how many bytes the text is.
615
+ * @param limits - the depth and size limits, copied, so later changes to it
616
+ * do not reach this tokenizer.
617
+ */
587
618
  constructor(src: u8[], off: i32, len: i32, limits: JsonLimits) {
588
619
  this.maxDepth = limits.maxDepth < 0 ? 0 : limits.maxDepth
589
620
  this.maxStringBytes = limits.maxStringBytes < 0 ? 0 : limits.maxStringBytes
@@ -612,6 +643,10 @@ export class JsonTokenizer {
612
643
  * Starts over on `src[off, off + len)`, keeping the limits and the depth
613
644
  * stack, and clearing any error. A window outside `src` or longer than the
614
645
  * total limit is refused here, and the first `next()` answers it.
646
+ *
647
+ * @param src - the bytes to read next.
648
+ * @param off - the offset in `src` of the first byte of the text.
649
+ * @param len - how many bytes the text is.
615
650
  */
616
651
  reset(src: u8[], off: i32, len: i32): void {
617
652
  this.src = src
@@ -641,7 +676,7 @@ export class JsonTokenizer {
641
676
  }
642
677
 
643
678
  /** Records the first error and answers it. */
644
- fail(code: i32, at: i32): i32 {
679
+ private fail(code: i32, at: i32): i32 {
645
680
  if (this.failed === 0) {
646
681
  this.failed = code
647
682
  this.errorAt = at
@@ -649,7 +684,14 @@ export class JsonTokenizer {
649
684
  return this.failed
650
685
  }
651
686
 
652
- /** The next token's kind, `JSON_TOK_END`, or a negative error, which is sticky. */
687
+ /**
688
+ * The next token's kind, `JSON_TOK_END`, or a negative error, which is
689
+ * sticky.
690
+ *
691
+ * @returns a `JSON_TOK_*` kind, `JSON_TOK_END` once the top-level value is
692
+ * complete, or a negative `JSON_TOK_ERR_*` code that every later call
693
+ * repeats.
694
+ */
653
695
  next(): i32 {
654
696
  if (this.failed !== 0) {
655
697
  return this.failed
@@ -702,7 +744,7 @@ export class JsonTokenizer {
702
744
  }
703
745
 
704
746
  /** The kind of the innermost open container, or `0` at the top level. */
705
- top(): i32 {
747
+ private top(): i32 {
706
748
  const d: i32 = this.depth
707
749
  if (d <= 0 || d > toI32(this.stack.length)) {
708
750
  return 0
@@ -711,7 +753,7 @@ export class JsonTokenizer {
711
753
  }
712
754
 
713
755
  /** Records the token `src[start, stop)` of kind `k` and what may follow it. */
714
- emit(k: i32, start: i32, stop: i32): i32 {
756
+ private emit(k: i32, start: i32, stop: i32): i32 {
715
757
  this.kind = k
716
758
  this.tokStart = start
717
759
  this.tokEnd = stop
@@ -729,7 +771,7 @@ export class JsonTokenizer {
729
771
  }
730
772
 
731
773
  /** A closer at `at`, which must match the innermost container, `inside`. */
732
- close(at: i32, inside: i32): i32 {
774
+ private close(at: i32, inside: i32): i32 {
733
775
  if (this.top() !== inside) {
734
776
  return this.fail(JSON_TOK_ERR_SYNTAX, at)
735
777
  }
@@ -738,7 +780,7 @@ export class JsonTokenizer {
738
780
  }
739
781
 
740
782
  /** An opener at `at`, refused past the depth limit. */
741
- open(at: i32, inside: i32): i32 {
783
+ private open(at: i32, inside: i32): i32 {
742
784
  const d: i32 = this.depth
743
785
  if (d >= this.maxDepth || d < 0 || d >= toI32(this.stack.length)) {
744
786
  return this.fail(JSON_TOK_ERR_DEPTH, at)
@@ -749,7 +791,7 @@ export class JsonTokenizer {
749
791
  }
750
792
 
751
793
  /** A key at `at`: a string, whose colon the next call reads. */
752
- key(at: i32): i32 {
794
+ private key(at: i32): i32 {
753
795
  const b: i32 = jsonTokByteAt(this.src, at, this.end)
754
796
  if (b === JSON_TOK_QUOTE) {
755
797
  return this.string(at, JSON_TOK_KEY)
@@ -758,7 +800,7 @@ export class JsonTokenizer {
758
800
  }
759
801
 
760
802
  /** A value at `at`. */
761
- value(at: i32): i32 {
803
+ private value(at: i32): i32 {
762
804
  const src: u8[] = this.src
763
805
  const end: i32 = this.end
764
806
  const b: i32 = jsonTokByteAt(src, at, end)
@@ -785,7 +827,7 @@ export class JsonTokenizer {
785
827
  }
786
828
 
787
829
  /** `true`, `false` or `null` at `at`; a window that ends inside the word is truncated. */
788
- literal(at: i32, word: string, k: i32): i32 {
830
+ private literal(at: i32, word: string, k: i32): i32 {
789
831
  const n: i32 = toI32(word.length)
790
832
  let matched: i32 = 0
791
833
  while (
@@ -811,7 +853,7 @@ export class JsonTokenizer {
811
853
  * number that reaches that byte is refused for its length, whatever the
812
854
  * grammar would have said of the rest.
813
855
  */
814
- number(at: i32): i32 {
856
+ private number(at: i32): i32 {
815
857
  const src: u8[] = this.src
816
858
  const end: i32 = this.maxNumberBytes >= this.end - at ? this.end : at + this.maxNumberBytes + 1
817
859
  let i: i32 = at
@@ -858,7 +900,7 @@ export class JsonTokenizer {
858
900
  }
859
901
 
860
902
  /** `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 {
903
+ private numberRefused(code: i32, at: i32, i: i32): i32 {
862
904
  if (i - at > this.maxNumberBytes) {
863
905
  return this.fail(JSON_TOK_ERR_NUMBER_LIMIT, at + this.maxNumberBytes)
864
906
  }
@@ -871,7 +913,7 @@ export class JsonTokenizer {
871
913
  * limit counts raw bytes and is checked at every byte, so a string past it
872
914
  * is refused where it crosses the limit, not where it ends.
873
915
  */
874
- string(at: i32, k: i32): i32 {
916
+ private string(at: i32, k: i32): i32 {
875
917
  const src: u8[] = this.src
876
918
  const end: i32 = this.end
877
919
  // Where the string would pass its limit, or `end` when it cannot pass it
@@ -933,7 +975,7 @@ export class JsonTokenizer {
933
975
  * joined into one, or a negative error, recorded. Used both to check a
934
976
  * string and, on one already checked, to decode it.
935
977
  */
936
- escapeCodePoint(at: i32): i32 {
978
+ private escapeCodePoint(at: i32): i32 {
937
979
  const src: u8[] = this.src
938
980
  const end: i32 = this.end
939
981
  const letter: i32 = jsonTokByteAt(src, at + 1, end)
@@ -975,7 +1017,11 @@ export class JsonTokenizer {
975
1017
  )
976
1018
  }
977
1019
 
978
- /** Whether the current token is a key or a string. */
1020
+ /**
1021
+ * Whether the current token is a key or a string.
1022
+ *
1023
+ * @returns true when the current token is a key or a string.
1024
+ */
979
1025
  isText(): boolean {
980
1026
  return this.kind === JSON_TOK_KEY || this.kind === JSON_TOK_STRING
981
1027
  }
@@ -984,6 +1030,10 @@ export class JsonTokenizer {
984
1030
  * Writes the current key's or string's decoded bytes to `out` from `at`,
985
1031
  * and answers how many; `-1`, writing nothing, when the current token is
986
1032
  * neither or `out` has fewer than `stringLength()` bytes from `at`.
1033
+ *
1034
+ * @param out - the buffer the decoded bytes are written into.
1035
+ * @param at - the offset in `out` of the first byte written.
1036
+ * @returns how many bytes were written, or `-1` when nothing was.
987
1037
  */
988
1038
  stringInto(out: u8[], at: i32): i32 {
989
1039
  const n: i32 = this.stringBytes
@@ -1040,7 +1090,12 @@ export class JsonTokenizer {
1040
1090
  return o - at
1041
1091
  }
1042
1092
 
1043
- /** The current key's or string's length once decoded, or `-1` when the token is neither. */
1093
+ /**
1094
+ * The current key's or string's length once decoded, or `-1` when the token
1095
+ * is neither.
1096
+ *
1097
+ * @returns the decoded length in bytes, or `-1`.
1098
+ */
1044
1099
  stringLength(): i32 {
1045
1100
  return this.isText() ? this.stringBytes : -1
1046
1101
  }
@@ -1054,6 +1109,9 @@ export class JsonTokenizer {
1054
1109
  * not match there, and a name whose code units 0x80 to 0xFF spell those
1055
1110
  * bytes does (`"é"` matches a key `"é"`). That is the bytes against code
1056
1111
  * units divergence `docs/wp33-round-trip.md` §3.2 records.
1112
+ *
1113
+ * @param name - the key to compare against.
1114
+ * @returns true when the decoded text is `name`.
1057
1115
  */
1058
1116
  keyEquals(name: string): boolean {
1059
1117
  const n: i32 = toI32(name.length)
@@ -1105,6 +1163,9 @@ export class JsonTokenizer {
1105
1163
  * exponent whose value fits in an `i64`: `-0` and `9223372036854775807`
1106
1164
  * are, `1.0`, `1e2` and `9223372036854775808` are not. That is the
1107
1165
  * spelling rule; `isIntegral()` asks whether the value is whole.
1166
+ *
1167
+ * @returns true when the current number is spelt as an integer that fits an
1168
+ * `i64`.
1108
1169
  */
1109
1170
  isInteger(): boolean {
1110
1171
  return this.kind === JSON_TOK_NUMBER && this.integral && this.integerScan()
@@ -1114,6 +1175,8 @@ export class JsonTokenizer {
1114
1175
  * The current number as an `i64` when `isInteger()` holds, and `0`
1115
1176
  * otherwise. Read it after checking `isInteger()`: a `0` alone does not say
1116
1177
  * which.
1178
+ *
1179
+ * @returns the integer, or `0` when `isInteger()` does not hold.
1117
1180
  */
1118
1181
  numberI64(): i64 {
1119
1182
  if (!this.isInteger()) {
@@ -1130,7 +1193,7 @@ export class JsonTokenizer {
1130
1193
  * negative number reaches -2^63, where a positive one stops at 2^63 - 1, so
1131
1194
  * the bound for a positive number is one less.
1132
1195
  */
1133
- integerScan(): boolean {
1196
+ private integerScan(): boolean {
1134
1197
  const src: u8[] = this.src
1135
1198
  const end: i32 = this.tokEnd
1136
1199
  const negative: boolean = jsonTokByteAt(src, this.tokStart, end) === JSON_TOK_MINUS
@@ -1163,6 +1226,9 @@ export class JsonTokenizer {
1163
1226
  * sign, fraction or exponent, whose value fits in a `u64`: `0` and
1164
1227
  * `18446744073709551615` are; `-0`, `-1`, `1.0`, `1e2` and
1165
1228
  * `18446744073709551616` are not.
1229
+ *
1230
+ * @returns true when the current number is spelt as an unsigned integer that
1231
+ * fits a `u64`.
1166
1232
  */
1167
1233
  isU64(): boolean {
1168
1234
  return this.kind === JSON_TOK_NUMBER && this.integral && this.unsignedScan()
@@ -1171,6 +1237,8 @@ export class JsonTokenizer {
1171
1237
  /**
1172
1238
  * The current number as a `u64` when `isU64()` holds, and `0` otherwise.
1173
1239
  * Read it after checking `isU64()`: a `0` alone does not say which.
1240
+ *
1241
+ * @returns the integer, or `0` when `isU64()` does not hold.
1174
1242
  */
1175
1243
  numberU64(): u64 {
1176
1244
  return this.isU64() ? this.unsignedValue : toU64(0)
@@ -1184,7 +1252,7 @@ export class JsonTokenizer {
1184
1252
  * 19 digits no greater than 2^64 - 1's last 19, 8446744073709551615, so the
1185
1253
  * sum never wraps and needs no divide.
1186
1254
  */
1187
- unsignedScan(): boolean {
1255
+ private unsignedScan(): boolean {
1188
1256
  const src: u8[] = this.src
1189
1257
  const end: i32 = this.tokEnd
1190
1258
  const n: i32 = toI32(src.length)
@@ -1237,6 +1305,8 @@ export class JsonTokenizer {
1237
1305
  * zero or E - F + z >= 0. F and z count bytes of the token, so F - z fits an
1238
1306
  * `i32` whatever the limits, and `jsonTokDigitsExceed` compares E with it
1239
1307
  * without adding up more of E than it needs, so `1e99999999999` answers too.
1308
+ *
1309
+ * @returns true when the current number's value is a whole number.
1240
1310
  */
1241
1311
  isIntegral(): boolean {
1242
1312
  if (this.kind !== JSON_TOK_NUMBER) {
@@ -1301,6 +1371,8 @@ export class JsonTokenizer {
1301
1371
  * reads it: `-0` is negative zero, a magnitude past the largest double is
1302
1372
  * an infinity and one below the smallest is zero. `0` when the current
1303
1373
  * token is not a number.
1374
+ *
1375
+ * @returns the nearest double, or `0` when the current token is not a number.
1304
1376
  */
1305
1377
  numberF64(): f64 {
1306
1378
  if (this.kind !== JSON_TOK_NUMBER) {
@@ -1390,7 +1462,7 @@ export class JsonTokenizer {
1390
1462
  * runs under Node. A token outside `src` can only mean the caller shortened
1391
1463
  * the array after `next()` read it, and answers `0` rather than panic.
1392
1464
  */
1393
- numberSlow(): f64 {
1465
+ private numberSlow(): f64 {
1394
1466
  const src: u8[] = this.src
1395
1467
  const start: i32 = this.tokStart
1396
1468
  const end: i32 = this.tokEnd
@@ -1406,6 +1478,9 @@ export class JsonTokenizer {
1406
1478
  * opener, everything up to and including its closer; after a scalar or a
1407
1479
  * closer, nothing. Answers the kind of the last token it read (the closer,
1408
1480
  * or the scalar), or a negative error.
1481
+ *
1482
+ * @returns the kind of the last token read, or a negative `JSON_TOK_ERR_*`
1483
+ * code.
1409
1484
  */
1410
1485
  skipValue(): i32 {
1411
1486
  if (this.failed !== 0) {