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
@@ -238,14 +238,32 @@ const jfFullTimeFrom = (s: string, at: i32): boolean => {
238
238
  return second !== 60 || (hour * 60 + minute - offset + 1440) % 1440 === 1439
239
239
  }
240
240
 
241
- /** Whether `s` is an RFC 3339 `date-time`, `1963-06-19T08:30:06.283185Z`. */
241
+ /**
242
+ * Whether `s` is an RFC 3339 `date-time`, `1963-06-19T08:30:06.283185Z`.
243
+ *
244
+ * @param s - the text to check, whole: nothing before or after the date-time is
245
+ * allowed.
246
+ * @returns true when `s` is a date-time, false otherwise.
247
+ */
242
248
  export const isDateTime = (s: string): boolean =>
243
249
  jfFullDateAt(s, 0) && jfLower(jfUnitAt(s, 10)) === 116 && jfFullTimeFrom(s, 11)
244
250
 
245
- /** Whether `s` is an RFC 3339 `full-date`, `1963-06-19`. */
251
+ /**
252
+ * Whether `s` is an RFC 3339 `full-date`, `1963-06-19`.
253
+ *
254
+ * @param s - the text to check, whole: nothing before or after the date is
255
+ * allowed.
256
+ * @returns true when `s` is a date, false otherwise.
257
+ */
246
258
  export const isDate = (s: string): boolean => toI32(s.length) === 10 && jfFullDateAt(s, 0)
247
259
 
248
- /** Whether `s` is an RFC 3339 `full-time`, `08:30:06Z` or `08:30:06+01:00`. */
260
+ /**
261
+ * Whether `s` is an RFC 3339 `full-time`, `08:30:06Z` or `08:30:06+01:00`.
262
+ *
263
+ * @param s - the text to check, whole: nothing before or after the time is
264
+ * allowed.
265
+ * @returns true when `s` is a time, false otherwise.
266
+ */
249
267
  export const isTime = (s: string): boolean => jfFullTimeFrom(s, 0)
250
268
 
251
269
  /** The place of unit `u` in `units`, or -1 if it is not one of them. */
@@ -267,6 +285,10 @@ const jfUnitIndex = (u: i32, units: string): i32 => {
267
285
  * 1*DIGIT "Y" [dur-month]`), so the units of each half must be consecutive
268
286
  * in `YMD` and `HMS` order: `P1Y1D` and `PT1H1S` are invalid as written,
269
287
  * though ISO 8601 allows them.
288
+ *
289
+ * @param s - the text to check, whole: nothing before or after the duration is
290
+ * allowed.
291
+ * @returns true when `s` is a duration, false otherwise.
270
292
  */
271
293
  export const isDuration = (s: string): boolean => {
272
294
  const length: i32 = toI32(s.length)
@@ -386,10 +408,22 @@ const jfIpv6Range = (s: string, from: i32, to: i32): boolean => {
386
408
  return elided ? groups <= 7 : groups === 8
387
409
  }
388
410
 
389
- /** Whether `s` is a dotted-quad IPv4 address, `192.168.0.1`. */
411
+ /**
412
+ * Whether `s` is a dotted-quad IPv4 address, `192.168.0.1`.
413
+ *
414
+ * @param s - the text to check, whole: nothing before or after the IPv4 address
415
+ * is allowed.
416
+ * @returns true when `s` is an IPv4 address, false otherwise.
417
+ */
390
418
  export const isIpv4 = (s: string): boolean => jfIpv4Range(s, 0, toI32(s.length))
391
419
 
392
- /** Whether `s` is an IPv6 address, `::ffff:192.168.0.1`. */
420
+ /**
421
+ * Whether `s` is an IPv6 address, `::ffff:192.168.0.1`.
422
+ *
423
+ * @param s - the text to check, whole: nothing before or after the IPv6 address
424
+ * is allowed.
425
+ * @returns true when `s` is an IPv6 address, false otherwise.
426
+ */
393
427
  export const isIpv6 = (s: string): boolean => jfIpv6Range(s, 0, toI32(s.length))
394
428
 
395
429
  const jfIsLdh = (c: i32): boolean => jfIsAlpha(c) || jfIsDigit(c) || c === 45
@@ -416,7 +450,13 @@ const jfHostnameRange = (s: string, from: i32, to: i32): boolean => {
416
450
  return true
417
451
  }
418
452
 
419
- /** Whether `s` is a host name, `www.example.com`. */
453
+ /**
454
+ * Whether `s` is a host name, `www.example.com`.
455
+ *
456
+ * @param s - the text to check, whole: nothing before or after the host name is
457
+ * allowed.
458
+ * @returns true when `s` is a host name, false otherwise.
459
+ */
420
460
  export const isHostname = (s: string): boolean => jfHostnameRange(s, 0, toI32(s.length))
421
461
 
422
462
  /** Whether `c` is RFC 5322's `atext`: a letter, a digit or one of ``!#$%&'*+-/=?^_`{|}~``. */
@@ -501,7 +541,13 @@ const jfGeneralLiteral = (s: string, from: i32, to: i32): boolean => {
501
541
  return true
502
542
  }
503
543
 
504
- /** Whether `s` is an RFC 5321 mailbox, `joe.bloggs@example.com`. */
544
+ /**
545
+ * Whether `s` is an RFC 5321 mailbox, `joe.bloggs@example.com`.
546
+ *
547
+ * @param s - the text to check, whole: nothing before or after the mailbox is
548
+ * allowed.
549
+ * @returns true when `s` is a mailbox, false otherwise.
550
+ */
505
551
  export const isEmail = (s: string): boolean => {
506
552
  const length: i32 = toI32(s.length)
507
553
  const at = jfLocalPartEnd(s)
@@ -533,7 +579,13 @@ export const isEmail = (s: string): boolean => {
533
579
  return jfIpv4Range(s, inner, end) || jfGeneralLiteral(s, inner, end)
534
580
  }
535
581
 
536
- /** Whether `s` is a UUID, `2eb8aa08-aa98-11ea-b4aa-73b441d16380`. */
582
+ /**
583
+ * Whether `s` is a UUID, `2eb8aa08-aa98-11ea-b4aa-73b441d16380`.
584
+ *
585
+ * @param s - the text to check, whole: nothing before or after the UUID is
586
+ * allowed.
587
+ * @returns true when `s` is a UUID, false otherwise.
588
+ */
537
589
  export const isUuid = (s: string): boolean => {
538
590
  if (toI32(s.length) !== 36) {
539
591
  return false
@@ -813,16 +865,40 @@ const jfUriCheck = (s: string, iri: boolean, reference: boolean): boolean => {
813
865
  return true
814
866
  }
815
867
 
816
- /** Whether `s` is an absolute URI, `http://example.com/a?b#c`. */
868
+ /**
869
+ * Whether `s` is an absolute URI, `http://example.com/a?b#c`.
870
+ *
871
+ * @param s - the text to check, whole: nothing before or after the URI is
872
+ * allowed.
873
+ * @returns true when `s` is a URI, false otherwise.
874
+ */
817
875
  export const isUri = (s: string): boolean => jfUriCheck(s, false, false)
818
876
 
819
- /** Whether `s` is a URI or a relative reference, `../a?b#c`. */
877
+ /**
878
+ * Whether `s` is a URI or a relative reference, `../a?b#c`.
879
+ *
880
+ * @param s - the text to check, whole: nothing before or after the URI
881
+ * reference is allowed.
882
+ * @returns true when `s` is a URI reference, false otherwise.
883
+ */
820
884
  export const isUriReference = (s: string): boolean => jfUriCheck(s, false, true)
821
885
 
822
- /** Whether `s` is an absolute IRI, `http://ƒøø.ßår/?∂éœ=πîx`. */
886
+ /**
887
+ * Whether `s` is an absolute IRI, `http://ƒøø.ßår/?∂éœ=πîx`.
888
+ *
889
+ * @param s - the text to check, whole: nothing before or after the IRI is
890
+ * allowed.
891
+ * @returns true when `s` is an IRI, false otherwise.
892
+ */
823
893
  export const isIri = (s: string): boolean => jfUriCheck(s, true, false)
824
894
 
825
- /** Whether `s` is an IRI or a relative IRI reference. */
895
+ /**
896
+ * Whether `s` is an IRI or a relative IRI reference.
897
+ *
898
+ * @param s - the text to check, whole: nothing before or after the IRI
899
+ * reference is allowed.
900
+ * @returns true when `s` is an IRI reference, false otherwise.
901
+ */
826
902
  export const isIriReference = (s: string): boolean => jfUriCheck(s, true, true)
827
903
 
828
904
  /** The code units of RFC 6570's `varchar` at `i` of `s`, `ALPHA / DIGIT / "_" / pct-encoded`, or 0. */
@@ -909,7 +985,14 @@ const jfIsTemplateLiteral = (c: i32): boolean =>
909
985
  (c >= 97 && c <= 122) ||
910
986
  c === 126
911
987
 
912
- /** Whether `s` is an RFC 6570 URI template, `http://example.com/{term:1}/{term}`. */
988
+ /**
989
+ * Whether `s` is an RFC 6570 URI template,
990
+ * `http://example.com/{term:1}/{term}`.
991
+ *
992
+ * @param s - the text to check, whole: nothing before or after the URI template
993
+ * is allowed.
994
+ * @returns true when `s` is a URI template, false otherwise.
995
+ */
913
996
  export const isUriTemplate = (s: string): boolean => {
914
997
  const length: i32 = toI32(s.length)
915
998
  let i: i32 = 0
@@ -945,12 +1028,20 @@ export const isUriTemplate = (s: string): boolean => {
945
1028
  * Whether `s` is a regular expression `nish/regex` compiles with no flags.
946
1029
  * Lookaround, backreferences and what the `u` flag refuses are answered
947
1030
  * false, though ECMA-262 accepts them (see the module header).
1031
+ *
1032
+ * @param s - the pattern source, without slashes or flags.
1033
+ * @returns true when `nish/regex` compiles `s`, false otherwise.
948
1034
  */
949
1035
  export const isRegex = (s: string): boolean => regexCompile(s, "").isOk()
950
1036
 
951
1037
  /**
952
1038
  * The id of the format `name` for `jsonFormatCheck`, one of the
953
1039
  * `JSON_FORMAT_*` ids, or -1 for a format this module does not check.
1040
+ *
1041
+ * @param name - the name a schema's `format` keyword gives, such as
1042
+ * `"date-time"`.
1043
+ * @returns the format's `JSON_FORMAT_*` id, or -1 when this module does not
1044
+ * check that format.
954
1045
  */
955
1046
  export const jsonFormatId = (name: string): i32 => {
956
1047
  if (name === "date-time") {
@@ -1052,6 +1143,10 @@ const jfPasses = (id: i32, value: string): boolean => {
1052
1143
  * `value` checked against the format `id` from `jsonFormatId`:
1053
1144
  * `JSON_FORMAT_VALID` or `JSON_FORMAT_INVALID`, or `JSON_FORMAT_UNKNOWN`
1054
1145
  * for an id that names no format, -1 included.
1146
+ *
1147
+ * @param id - a format id from `jsonFormatId`.
1148
+ * @param value - the string instance to check.
1149
+ * @returns `JSON_FORMAT_VALID`, `JSON_FORMAT_INVALID` or `JSON_FORMAT_UNKNOWN`.
1055
1150
  */
1056
1151
  export const jsonFormatCheck = (id: i32, value: string): i32 => {
1057
1152
  if (id < JSON_FORMAT_DATE_TIME || id > JSON_FORMAT_REGEX) {
@@ -1065,6 +1160,10 @@ export const jsonFormatCheck = (id: i32, value: string): i32 => {
1065
1160
  * `JSON_FORMAT_INVALID`, or `JSON_FORMAT_UNKNOWN` for a format this module
1066
1161
  * does not check. A validator that checks many instances against one schema
1067
1162
  * resolves the name once with `jsonFormatId` and calls `jsonFormatCheck`.
1163
+ *
1164
+ * @param name - the name a schema's `format` keyword gives.
1165
+ * @param value - the string instance to check.
1166
+ * @returns `JSON_FORMAT_VALID`, `JSON_FORMAT_INVALID` or `JSON_FORMAT_UNKNOWN`.
1068
1167
  */
1069
1168
  export const jsonFormatValidate = (name: string, value: string): i32 =>
1070
1169
  jsonFormatCheck(jsonFormatId(name), value)
@@ -19,18 +19,18 @@
19
19
  * grammar exactly (what `JsonDocument.numberText` answers); anything else is
20
20
  * `JSON_NUMBER_ERR_SYNTAX`.
21
21
  *
22
- * **What a call costs.** `jsonNumberCompare` reads each text once and
23
- * allocates two records of a few fields, nothing in proportion to the text:
24
- * time is linear in the texts' lengths. `jsonNumberCanonical` allocates the
25
- * string it answers, at most the text's length plus an exponent.
26
- * `jsonNumberMultipleOf` divides the value's digits, followed by as many
27
- * zeros as its exponent is above the divisor's (the gap), by the divisor's
28
- * digits: one step per digit of that dividend when the divisor has at most 18
29
- * significant digits, and one per digit of the dividend per digit of the
30
- * divisor otherwise, which then also allocates the remainder, one byte per
31
- * divisor digit. A step of that long division is a shift, up to ten
32
- * comparisons and up to nine subtractions of a byte each, so about twenty
33
- * byte operations.
22
+ * **What a call costs.** `jsonNumberCompare` reads each text once and allocates
23
+ * two records of a few fields, nothing in proportion to the text: time is
24
+ * linear in the texts' lengths. `jsonNumberCanonical` allocates the string it
25
+ * answers, at most the text's length plus an exponent.
26
+ *
27
+ * `jsonNumberMultipleOf` divides the value's digits, followed by as many zeros
28
+ * as its exponent is above the divisor's (the gap), by the divisor's digits:
29
+ * one step per digit of that dividend when the divisor has at most 18
30
+ * significant digits, and one per digit of the dividend per digit of the
31
+ * divisor otherwise, which then also allocates the remainder, one byte per
32
+ * divisor digit. A step of that long division is a shift, up to ten comparisons
33
+ * and up to nine subtractions of a byte each, so about twenty byte operations.
34
34
  *
35
35
  * **The bounds are stated.** An exponent is at most `JSON_NUMBER_MAX_EXPONENT`
36
36
  * in size, which keeps every exponent sum far inside `i64`, and past
@@ -83,25 +83,57 @@ const jsonNumberIsDigit = (c: i32): boolean => c >= JSON_NUMBER_DIGIT_0 && c <=
83
83
  * stepping over the point.
84
84
  */
85
85
  class JsonNumberParts {
86
- text: string
87
- /** `0` when the text is a number, else a `JSON_NUMBER_ERR_*` code. */
86
+ private text: string
87
+ /**
88
+ * `0` when the text is a number, else a `JSON_NUMBER_ERR_*` code.
89
+ *
90
+ * @internal Read by the `jsonNumber*` free functions of this module; the
91
+ * class is not exported.
92
+ */
88
93
  code: i32
94
+ /**
95
+ * @internal Read by the `jsonNumber*` free functions of this module; the
96
+ * class is not exported.
97
+ */
89
98
  negative: boolean
90
- /** Whether every digit is zero, `-0` and `0.0e5` included. */
99
+ /**
100
+ * Whether every digit is zero, `-0` and `0.0e5` included.
101
+ *
102
+ * @internal Read by the `jsonNumber*` free functions of this module; the
103
+ * class is not exported.
104
+ */
91
105
  zero: boolean
92
106
  /** Where the integer part's digits start, and how many there are. */
93
- intStart: i32
94
- intLen: i32
107
+ private intStart: i32
108
+ private intLen: i32
95
109
  /** Where the fraction's digits start, after the point, and how many there are. */
96
- fracStart: i32
97
- fracLen: i32
110
+ private fracStart: i32
111
+ private fracLen: i32
98
112
  /** The first significant digit's place among the integer and fraction digits run together. */
99
- first: i32
100
- /** How many significant digits there are, from the first non-zero one to the last. */
113
+ private first: i32
114
+ /**
115
+ * How many significant digits there are, from the first non-zero one to the
116
+ * last.
117
+ *
118
+ * @internal Read by the `jsonNumber*` free functions of this module; the
119
+ * class is not exported.
120
+ */
101
121
  count: i32
102
- /** The decimal exponent of the first significant digit: `3` for `1234`, `-2` for `0.05`. */
122
+ /**
123
+ * The decimal exponent of the first significant digit: `3` for `1234`, `-2`
124
+ * for `0.05`.
125
+ *
126
+ * @internal Read by the `jsonNumber*` free functions of this module; the
127
+ * class is not exported.
128
+ */
103
129
  lead: i64
104
- /** The decimal exponent of the last significant digit: `0` for `1234`, `2` for `1200`, `-2` for `0.05`. */
130
+ /**
131
+ * The decimal exponent of the last significant digit: `0` for `1234`, `2` for
132
+ * `1200`, `-2` for `0.05`.
133
+ *
134
+ * @internal Read by the `jsonNumber*` free functions of this module; the
135
+ * class is not exported.
136
+ */
105
137
  last: i64
106
138
 
107
139
  constructor(text: string) {
@@ -120,19 +152,24 @@ class JsonNumberParts {
120
152
  this.code = this.read()
121
153
  }
122
154
 
123
- /** The k-th significant digit, `0 <= k < count`, as `0` to `9`. */
155
+ /**
156
+ * The k-th significant digit, `0 <= k < count`, as `0` to `9`.
157
+ *
158
+ * @internal Read by the `jsonNumber*` free functions of this module; the
159
+ * class is not exported.
160
+ */
124
161
  digit(k: i32): i32 {
125
162
  return this.placeDigit(this.first + k)
126
163
  }
127
164
 
128
165
  /** The digit at place `p` of the integer and fraction digits run together. */
129
- placeDigit(p: i32): i32 {
166
+ private placeDigit(p: i32): i32 {
130
167
  const at: i32 = p < this.intLen ? this.intStart + p : this.fracStart + (p - this.intLen)
131
168
  return toI32(this.text.charCodeAt(at)) - JSON_NUMBER_DIGIT_0
132
169
  }
133
170
 
134
171
  /** Reads the text against RFC 8259's number grammar; answers `0` or a code. */
135
- read(): i32 {
172
+ private read(): i32 {
136
173
  const s: string = this.text
137
174
  const n: i32 = toI32(s.length)
138
175
  let i: i32 = 0
@@ -249,6 +286,11 @@ const jsonNumberSign = (p: JsonNumberParts): i32 => {
249
286
  * and `-0` equals `0`. A text that is not a number, or whose exponent is past
250
287
  * `JSON_NUMBER_MAX_EXPONENT`, is that `JSON_NUMBER_ERR_*` code, `a`'s first.
251
288
  * Linear in the two lengths; allocates two small records.
289
+ *
290
+ * @param a - the first JSON number text.
291
+ * @param b - the second JSON number text.
292
+ * @returns `-1`, `0` or `1` as `a` is below, equal to or above `b`, or a
293
+ * negative `JSON_NUMBER_ERR_*` code.
252
294
  */
253
295
  export const jsonNumberCompare = (a: string, b: string): i32 => {
254
296
  const x = new JsonNumberParts(a)
@@ -279,6 +321,9 @@ export const jsonNumberCompare = (a: string, b: string): i32 => {
279
321
  * `jsonNumberCompare` calls them equal, which makes it a key for a set or a
280
322
  * hash. `""` for a text that is not a number or whose exponent is past
281
323
  * `JSON_NUMBER_MAX_EXPONENT`. Allocates the answer.
324
+ *
325
+ * @param text - a JSON number text.
326
+ * @returns the canonical text of its value, or `""` when `text` is refused.
282
327
  */
283
328
  export const jsonNumberCanonical = (text: string): string => {
284
329
  const p = new JsonNumberParts(text)
@@ -391,6 +436,11 @@ const jsonNumberDividesShort = (v: JsonNumberParts, d: JsonNumberParts, total: i
391
436
  * `JSON_NUMBER_MAX_STEPS` steps, which is `JSON_NUMBER_ERR_GAP`: the value's
392
437
  * digits plus the gap between the two last digits' exponents, times the
393
438
  * divisor's digits when it has more than 18.
439
+ *
440
+ * @param value - the JSON number text to test.
441
+ * @param divisor - the JSON number text it should be a multiple of.
442
+ * @returns `1` for a multiple, `0` for not one, or a negative
443
+ * `JSON_NUMBER_ERR_*` code when the question is refused.
394
444
  */
395
445
  export const jsonNumberMultipleOf = (value: string, divisor: string): i32 => {
396
446
  const v = new JsonNumberParts(value)
@@ -77,7 +77,13 @@ const jsonPointerWellFormed = (s: string, from: i32): boolean => {
77
77
  return true
78
78
  }
79
79
 
80
- /** Whether `s` is an RFC 6901 JSON Pointer (the module header's grammar). Allocates nothing. */
80
+ /**
81
+ * Whether `s` is an RFC 6901 JSON Pointer (the module header's grammar).
82
+ * Allocates nothing.
83
+ *
84
+ * @param s - the text to check.
85
+ * @returns true when `s` is a JSON Pointer, the empty one included.
86
+ */
81
87
  export const isJsonPointer = (s: string): boolean => jsonPointerWellFormed(s, 0)
82
88
 
83
89
  /**
@@ -103,6 +109,9 @@ const jsonPointerIntegerEnd = (s: string, from: i32): i32 => {
103
109
  * leading zero (`0`, `12`, not `01`, `+1` or `-1`), then `#`, or an optional
104
110
  * `+` or `-` and another such integer and then a JSON Pointer, which may be
105
111
  * empty. Allocates nothing.
112
+ *
113
+ * @param s - the text to check.
114
+ * @returns true when `s` is a relative JSON Pointer.
106
115
  */
107
116
  export const isRelativeJsonPointer = (s: string): boolean => {
108
117
  let i: i32 = jsonPointerIntegerEnd(s, 0)
@@ -157,6 +166,10 @@ const jsonPointerTokenEnd = (p: string, from: i32): i32 => {
157
166
  /**
158
167
  * The reference tokens of JSON Pointer `p`, decoded: `[]` for `""`,
159
168
  * `["a/b", "", "~"]` for `/a~1b//~0`. `null` when `p` is not a JSON Pointer.
169
+ *
170
+ * @param p - the pointer text.
171
+ * @returns the decoded reference tokens, in order, or `null` when `p` is not a
172
+ * JSON Pointer.
160
173
  */
161
174
  export const jsonPointerParse = (p: string): string[] | null => {
162
175
  if (!isJsonPointer(p)) {
@@ -175,6 +188,9 @@ export const jsonPointerParse = (p: string): string[] | null => {
175
188
  /**
176
189
  * `token` written as one token of a JSON Pointer: `~` as `~0` and `/` as
177
190
  * `~1`, so `"a/b"` is `a~1b`. Everything else is copied whole.
191
+ *
192
+ * @param token - one reference token, as it reads in an object key.
193
+ * @returns the token as it is written inside a pointer.
178
194
  */
179
195
  export const jsonPointerEscape = (token: string): string => {
180
196
  const parts: string[] = []
@@ -220,6 +236,12 @@ const jsonPointerIndex = (p: string, from: i32, end: i32, length: i32): i32 => {
220
236
  * `""`, else each token taken in turn, as the module header says.
221
237
  * `JSON_POINTER_NONE` when the pointer names nothing there (or `root` names
222
238
  * no value), and `JSON_POINTER_ERR_SYNTAX` when `p` is not a JSON Pointer.
239
+ *
240
+ * @param doc - the document to look in.
241
+ * @param root - the value the pointer starts from.
242
+ * @param p - the pointer text.
243
+ * @returns the handle of the value named, `JSON_POINTER_NONE`, or
244
+ * `JSON_POINTER_ERR_SYNTAX`.
223
245
  */
224
246
  export const jsonPointerResolve = (doc: JsonDocument, root: i32, p: string): i32 => {
225
247
  if (!isJsonPointer(p)) {