@amritk/nish-aarch64-linux 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.
- package/INSTALL.md +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- 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 +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- 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 +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- 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 +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- 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 +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
package/std/json-format.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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)
|
package/std/json-number.ts
CHANGED
|
@@ -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
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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)
|
package/std/json-pointer.ts
CHANGED
|
@@ -77,7 +77,13 @@ const jsonPointerWellFormed = (s: string, from: i32): boolean => {
|
|
|
77
77
|
return true
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
/**
|
|
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)) {
|