@fedify/vocab-runtime 2.1.0-dev.565 → 2.1.0-dev.599
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/deno.json +4 -3
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/jsonld.cjs +8 -0
- package/dist/jsonld.d.cts +6 -0
- package/dist/jsonld.d.ts +6 -0
- package/dist/jsonld.js +7 -0
- package/dist/mod.cjs +4485 -4329
- package/dist/mod.d.cts +95 -4
- package/dist/mod.d.ts +95 -4
- package/dist/mod.js +4474 -4299
- package/dist/tests/decimal.test.cjs +154 -0
- package/dist/tests/decimal.test.d.cts +1 -0
- package/dist/tests/decimal.test.d.ts +1 -0
- package/dist/tests/decimal.test.js +153 -0
- package/dist/tests/docloader-B7jXFZpf.cjs +4562 -0
- package/dist/tests/docloader-DMCOWvVB.js +4550 -0
- package/dist/tests/docloader.test.cjs +7 -4491
- package/dist/tests/docloader.test.js +4 -4488
- package/dist/tests/internal/multicodec.test.cjs +77 -0
- package/dist/tests/internal/multicodec.test.d.cts +1 -0
- package/dist/tests/internal/multicodec.test.d.ts +1 -0
- package/dist/tests/internal/multicodec.test.js +76 -0
- package/dist/tests/key-ByCmSI2y.js +183 -0
- package/dist/tests/key-CCPn6TEY.cjs +231 -0
- package/dist/tests/key.test.cjs +36 -212
- package/dist/tests/key.test.js +9 -185
- package/dist/tests/langstr-BsVE3s9u.js +30 -0
- package/dist/tests/langstr-EPh86hXK.cjs +36 -0
- package/dist/tests/langstr.test.cjs +5 -33
- package/dist/tests/langstr.test.js +1 -29
- package/dist/tests/link.test.cjs +1 -1
- package/dist/tests/link.test.js +1 -1
- package/dist/tests/multibase/multibase.test.cjs +1 -1
- package/dist/tests/multibase/multibase.test.js +1 -1
- package/dist/tests/multicodec--6hQ74zI.cjs +59 -0
- package/dist/tests/multicodec-Dq3IiOV4.js +41 -0
- package/dist/tests/{request-3ywvRFy1.js → request-BQtyeAfw.js} +6 -3
- package/dist/tests/{request-Dhnqve0g.cjs → request-CW9KOmQu.cjs} +6 -3
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.js +1 -1
- package/dist/tests/url.test.cjs +1 -1
- package/dist/tests/url.test.js +1 -1
- package/package.json +12 -2
- package/src/contexts/activitystreams.json +379 -0
- package/src/contexts/did-v1.json +57 -0
- package/src/contexts/fep-5711.json +36 -0
- package/src/contexts/gotosocial.json +86 -0
- package/src/contexts/identity-v1.json +152 -0
- package/src/contexts/joinmastodon.json +28 -0
- package/src/contexts/schemaorg.json +8845 -0
- package/src/contexts/security-data-integrity-v1.json +78 -0
- package/src/contexts/security-data-integrity-v2.json +81 -0
- package/src/contexts/security-multikey-v1.json +35 -0
- package/src/contexts/security-v1.json +74 -0
- package/src/contexts/webfinger.json +10 -0
- package/src/contexts.ts +33 -4392
- package/src/decimal.test.ts +90 -0
- package/src/decimal.ts +112 -0
- package/src/internal/multicodec.test.ts +68 -0
- package/src/internal/multicodec.ts +53 -0
- package/src/jsonld.ts +4 -0
- package/src/key.test.ts +22 -1
- package/src/key.ts +9 -8
- package/src/mod.ts +6 -0
- package/tsdown.config.ts +1 -1
- /package/dist/tests/{link-Ck2yj4dH.js → link-C3q2TC2G.js} +0 -0
- /package/dist/tests/{link-CdFPEo9O.cjs → link-DYNFAdNu.cjs} +0 -0
- /package/dist/tests/{multibase-DStmqni9.js → multibase-B4g8pz6F.js} +0 -0
- /package/dist/tests/{multibase-BFbBiaPE.cjs → multibase-o_ovPHYJ.cjs} +0 -0
- /package/dist/tests/{url-fW_DHbih.js → url-CWEP9Zs9.js} +0 -0
- /package/dist/tests/{url-C5Vs9nYh.cjs → url-DIjOdK8Q.cjs} +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
|
+
require('./docloader-B7jXFZpf.cjs');
|
|
3
|
+
require('./request-CW9KOmQu.cjs');
|
|
4
|
+
require('./link-DYNFAdNu.cjs');
|
|
5
|
+
require('./url-DIjOdK8Q.cjs');
|
|
6
|
+
require('./multicodec--6hQ74zI.cjs');
|
|
7
|
+
require('./key-CCPn6TEY.cjs');
|
|
8
|
+
require('./multibase-o_ovPHYJ.cjs');
|
|
9
|
+
require('./langstr-EPh86hXK.cjs');
|
|
10
|
+
const node_assert = require_chunk.__toESM(require("node:assert"));
|
|
11
|
+
const node_test = require_chunk.__toESM(require("node:test"));
|
|
12
|
+
|
|
13
|
+
//#region src/decimal.ts
|
|
14
|
+
const DECIMAL_PATTERN = /^(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)$/;
|
|
15
|
+
const XML_SCHEMA_WHITESPACE_PATTERN = /[\t\n\r ]+/g;
|
|
16
|
+
function collapseXmlSchemaWhitespace(value) {
|
|
17
|
+
return value.replace(XML_SCHEMA_WHITESPACE_PATTERN, " ").trim();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether a string is a valid `xsd:decimal` lexical form.
|
|
21
|
+
*
|
|
22
|
+
* This predicate checks the lexical form strictly, without applying XML Schema
|
|
23
|
+
* whitespace normalization first. It is useful as a type guard for values
|
|
24
|
+
* that are already expected to be normalized decimal strings.
|
|
25
|
+
*
|
|
26
|
+
* @param value A candidate `xsd:decimal` lexical form.
|
|
27
|
+
* @returns `true` if the string matches the XML Schema `xsd:decimal` lexical
|
|
28
|
+
* form, or `false` otherwise.
|
|
29
|
+
* @since 2.1.0
|
|
30
|
+
*/
|
|
31
|
+
function isDecimal(value) {
|
|
32
|
+
return DECIMAL_PATTERN.test(value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks whether a string can be parsed as an `xsd:decimal` lexical form.
|
|
36
|
+
*
|
|
37
|
+
* Unlike {@link isDecimal}, this predicate first applies the XML Schema
|
|
38
|
+
* `whiteSpace="collapse"` normalization step and then validates the
|
|
39
|
+
* normalized string. This means values like `" 12.50 "` are parseable even
|
|
40
|
+
* though they are not already normalized decimal literals.
|
|
41
|
+
*
|
|
42
|
+
* @param value A candidate `xsd:decimal` lexical form.
|
|
43
|
+
* @returns `true` if the normalized string matches the XML Schema
|
|
44
|
+
* `xsd:decimal` lexical form, or `false` otherwise.
|
|
45
|
+
* @since 2.1.0
|
|
46
|
+
*/
|
|
47
|
+
function canParseDecimal(value) {
|
|
48
|
+
return isDecimal(collapseXmlSchemaWhitespace(value));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parses a string as an `xsd:decimal` lexical form and returns it as a
|
|
52
|
+
* branded {@link Decimal}.
|
|
53
|
+
*
|
|
54
|
+
* This function validates the input against the XML Schema `xsd:decimal`
|
|
55
|
+
* lexical space after applying the XML Schema `whiteSpace="collapse"`
|
|
56
|
+
* normalization step. It returns the normalized string without any further
|
|
57
|
+
* canonicalization.
|
|
58
|
+
*
|
|
59
|
+
* @param value A candidate `xsd:decimal` lexical form.
|
|
60
|
+
* @returns The normalized string branded as {@link Decimal}.
|
|
61
|
+
* @throws {TypeError} Thrown when the value is not a valid `xsd:decimal`
|
|
62
|
+
* lexical form.
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const price = parseDecimal("12.50");
|
|
66
|
+
* ```
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const price = parseDecimal(" 12.50 ");
|
|
70
|
+
* console.assert(price === "12.50");
|
|
71
|
+
* ```
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* try {
|
|
75
|
+
* parseDecimal("1e3");
|
|
76
|
+
* } catch (error) {
|
|
77
|
+
* console.assert(error instanceof TypeError);
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
* @since 2.1.0
|
|
81
|
+
*/
|
|
82
|
+
function parseDecimal(value) {
|
|
83
|
+
const normalized = collapseXmlSchemaWhitespace(value);
|
|
84
|
+
if (!isDecimal(normalized)) throw new TypeError(`${JSON.stringify(value)} is not a valid xsd:decimal lexical form.`);
|
|
85
|
+
return normalized;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/decimal.test.ts
|
|
90
|
+
(0, node_test.test)("parseDecimal() accepts valid xsd:decimal lexical forms", () => {
|
|
91
|
+
const values = [
|
|
92
|
+
"-1.23",
|
|
93
|
+
"12678967.543233",
|
|
94
|
+
"+100000.00",
|
|
95
|
+
"210",
|
|
96
|
+
".5",
|
|
97
|
+
"5.",
|
|
98
|
+
"0",
|
|
99
|
+
"-0.0"
|
|
100
|
+
];
|
|
101
|
+
for (const value of values) (0, node_assert.deepStrictEqual)(parseDecimal(value), value);
|
|
102
|
+
});
|
|
103
|
+
(0, node_test.test)("isDecimal() reports valid xsd:decimal lexical forms", () => {
|
|
104
|
+
(0, node_assert.deepStrictEqual)(isDecimal("12.50"), true);
|
|
105
|
+
(0, node_assert.deepStrictEqual)(isDecimal(".5"), true);
|
|
106
|
+
(0, node_assert.deepStrictEqual)(isDecimal("1e3"), false);
|
|
107
|
+
(0, node_assert.deepStrictEqual)(isDecimal(" 12.50 "), false);
|
|
108
|
+
(0, node_assert.deepStrictEqual)(isDecimal(" 12.50\n"), false);
|
|
109
|
+
});
|
|
110
|
+
(0, node_test.test)("canParseDecimal() accepts whitespace-normalized xsd:decimal strings", () => {
|
|
111
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal("12.50"), true);
|
|
112
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal(" 12.50 "), true);
|
|
113
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal(" +100000.00\r\n"), true);
|
|
114
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal(" .5 "), true);
|
|
115
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal("1e3"), false);
|
|
116
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal("1 2.50"), false);
|
|
117
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal("1 2.50"), false);
|
|
118
|
+
});
|
|
119
|
+
(0, node_test.test)("parseDecimal() normalizes XML Schema whitespace", () => {
|
|
120
|
+
(0, node_assert.deepStrictEqual)(parseDecimal("12.50"), "12.50");
|
|
121
|
+
(0, node_assert.deepStrictEqual)(parseDecimal(" 12.50 "), "12.50");
|
|
122
|
+
(0, node_assert.deepStrictEqual)(parseDecimal(" +100000.00\r\n"), "+100000.00");
|
|
123
|
+
(0, node_assert.deepStrictEqual)(parseDecimal(" .5 "), ".5");
|
|
124
|
+
});
|
|
125
|
+
(0, node_test.test)("parseDecimal() rejects invalid xsd:decimal lexical forms", () => {
|
|
126
|
+
const values = [
|
|
127
|
+
"",
|
|
128
|
+
".",
|
|
129
|
+
"+",
|
|
130
|
+
"-",
|
|
131
|
+
"1e3",
|
|
132
|
+
"NaN",
|
|
133
|
+
"INF",
|
|
134
|
+
"1,2",
|
|
135
|
+
"1..2",
|
|
136
|
+
"1 2.3",
|
|
137
|
+
"1 2.3"
|
|
138
|
+
];
|
|
139
|
+
for (const value of values) (0, node_assert.throws)(() => parseDecimal(value), {
|
|
140
|
+
name: "TypeError",
|
|
141
|
+
message: `${JSON.stringify(value)} is not a valid xsd:decimal lexical form.`
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
(0, node_test.test)("parseDecimal() is exported from the package root", () => {
|
|
145
|
+
(0, node_assert.deepStrictEqual)(parseDecimal("12.50"), "12.50");
|
|
146
|
+
});
|
|
147
|
+
(0, node_test.test)("canParseDecimal() is exported from the package root", () => {
|
|
148
|
+
(0, node_assert.deepStrictEqual)(canParseDecimal(" 12.50 "), true);
|
|
149
|
+
});
|
|
150
|
+
(0, node_test.test)("isDecimal() is exported from the package root", () => {
|
|
151
|
+
(0, node_assert.deepStrictEqual)(isDecimal("12.50"), true);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import "./docloader-DMCOWvVB.js";
|
|
2
|
+
import "./request-BQtyeAfw.js";
|
|
3
|
+
import "./link-C3q2TC2G.js";
|
|
4
|
+
import "./url-CWEP9Zs9.js";
|
|
5
|
+
import "./multicodec-Dq3IiOV4.js";
|
|
6
|
+
import "./key-ByCmSI2y.js";
|
|
7
|
+
import "./multibase-B4g8pz6F.js";
|
|
8
|
+
import "./langstr-BsVE3s9u.js";
|
|
9
|
+
import { deepStrictEqual, throws } from "node:assert";
|
|
10
|
+
import { test } from "node:test";
|
|
11
|
+
|
|
12
|
+
//#region src/decimal.ts
|
|
13
|
+
const DECIMAL_PATTERN = /^(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)$/;
|
|
14
|
+
const XML_SCHEMA_WHITESPACE_PATTERN = /[\t\n\r ]+/g;
|
|
15
|
+
function collapseXmlSchemaWhitespace(value) {
|
|
16
|
+
return value.replace(XML_SCHEMA_WHITESPACE_PATTERN, " ").trim();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether a string is a valid `xsd:decimal` lexical form.
|
|
20
|
+
*
|
|
21
|
+
* This predicate checks the lexical form strictly, without applying XML Schema
|
|
22
|
+
* whitespace normalization first. It is useful as a type guard for values
|
|
23
|
+
* that are already expected to be normalized decimal strings.
|
|
24
|
+
*
|
|
25
|
+
* @param value A candidate `xsd:decimal` lexical form.
|
|
26
|
+
* @returns `true` if the string matches the XML Schema `xsd:decimal` lexical
|
|
27
|
+
* form, or `false` otherwise.
|
|
28
|
+
* @since 2.1.0
|
|
29
|
+
*/
|
|
30
|
+
function isDecimal(value) {
|
|
31
|
+
return DECIMAL_PATTERN.test(value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether a string can be parsed as an `xsd:decimal` lexical form.
|
|
35
|
+
*
|
|
36
|
+
* Unlike {@link isDecimal}, this predicate first applies the XML Schema
|
|
37
|
+
* `whiteSpace="collapse"` normalization step and then validates the
|
|
38
|
+
* normalized string. This means values like `" 12.50 "` are parseable even
|
|
39
|
+
* though they are not already normalized decimal literals.
|
|
40
|
+
*
|
|
41
|
+
* @param value A candidate `xsd:decimal` lexical form.
|
|
42
|
+
* @returns `true` if the normalized string matches the XML Schema
|
|
43
|
+
* `xsd:decimal` lexical form, or `false` otherwise.
|
|
44
|
+
* @since 2.1.0
|
|
45
|
+
*/
|
|
46
|
+
function canParseDecimal(value) {
|
|
47
|
+
return isDecimal(collapseXmlSchemaWhitespace(value));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parses a string as an `xsd:decimal` lexical form and returns it as a
|
|
51
|
+
* branded {@link Decimal}.
|
|
52
|
+
*
|
|
53
|
+
* This function validates the input against the XML Schema `xsd:decimal`
|
|
54
|
+
* lexical space after applying the XML Schema `whiteSpace="collapse"`
|
|
55
|
+
* normalization step. It returns the normalized string without any further
|
|
56
|
+
* canonicalization.
|
|
57
|
+
*
|
|
58
|
+
* @param value A candidate `xsd:decimal` lexical form.
|
|
59
|
+
* @returns The normalized string branded as {@link Decimal}.
|
|
60
|
+
* @throws {TypeError} Thrown when the value is not a valid `xsd:decimal`
|
|
61
|
+
* lexical form.
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const price = parseDecimal("12.50");
|
|
65
|
+
* ```
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const price = parseDecimal(" 12.50 ");
|
|
69
|
+
* console.assert(price === "12.50");
|
|
70
|
+
* ```
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* try {
|
|
74
|
+
* parseDecimal("1e3");
|
|
75
|
+
* } catch (error) {
|
|
76
|
+
* console.assert(error instanceof TypeError);
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
* @since 2.1.0
|
|
80
|
+
*/
|
|
81
|
+
function parseDecimal(value) {
|
|
82
|
+
const normalized = collapseXmlSchemaWhitespace(value);
|
|
83
|
+
if (!isDecimal(normalized)) throw new TypeError(`${JSON.stringify(value)} is not a valid xsd:decimal lexical form.`);
|
|
84
|
+
return normalized;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/decimal.test.ts
|
|
89
|
+
test("parseDecimal() accepts valid xsd:decimal lexical forms", () => {
|
|
90
|
+
const values = [
|
|
91
|
+
"-1.23",
|
|
92
|
+
"12678967.543233",
|
|
93
|
+
"+100000.00",
|
|
94
|
+
"210",
|
|
95
|
+
".5",
|
|
96
|
+
"5.",
|
|
97
|
+
"0",
|
|
98
|
+
"-0.0"
|
|
99
|
+
];
|
|
100
|
+
for (const value of values) deepStrictEqual(parseDecimal(value), value);
|
|
101
|
+
});
|
|
102
|
+
test("isDecimal() reports valid xsd:decimal lexical forms", () => {
|
|
103
|
+
deepStrictEqual(isDecimal("12.50"), true);
|
|
104
|
+
deepStrictEqual(isDecimal(".5"), true);
|
|
105
|
+
deepStrictEqual(isDecimal("1e3"), false);
|
|
106
|
+
deepStrictEqual(isDecimal(" 12.50 "), false);
|
|
107
|
+
deepStrictEqual(isDecimal(" 12.50\n"), false);
|
|
108
|
+
});
|
|
109
|
+
test("canParseDecimal() accepts whitespace-normalized xsd:decimal strings", () => {
|
|
110
|
+
deepStrictEqual(canParseDecimal("12.50"), true);
|
|
111
|
+
deepStrictEqual(canParseDecimal(" 12.50 "), true);
|
|
112
|
+
deepStrictEqual(canParseDecimal(" +100000.00\r\n"), true);
|
|
113
|
+
deepStrictEqual(canParseDecimal(" .5 "), true);
|
|
114
|
+
deepStrictEqual(canParseDecimal("1e3"), false);
|
|
115
|
+
deepStrictEqual(canParseDecimal("1 2.50"), false);
|
|
116
|
+
deepStrictEqual(canParseDecimal("1 2.50"), false);
|
|
117
|
+
});
|
|
118
|
+
test("parseDecimal() normalizes XML Schema whitespace", () => {
|
|
119
|
+
deepStrictEqual(parseDecimal("12.50"), "12.50");
|
|
120
|
+
deepStrictEqual(parseDecimal(" 12.50 "), "12.50");
|
|
121
|
+
deepStrictEqual(parseDecimal(" +100000.00\r\n"), "+100000.00");
|
|
122
|
+
deepStrictEqual(parseDecimal(" .5 "), ".5");
|
|
123
|
+
});
|
|
124
|
+
test("parseDecimal() rejects invalid xsd:decimal lexical forms", () => {
|
|
125
|
+
const values = [
|
|
126
|
+
"",
|
|
127
|
+
".",
|
|
128
|
+
"+",
|
|
129
|
+
"-",
|
|
130
|
+
"1e3",
|
|
131
|
+
"NaN",
|
|
132
|
+
"INF",
|
|
133
|
+
"1,2",
|
|
134
|
+
"1..2",
|
|
135
|
+
"1 2.3",
|
|
136
|
+
"1 2.3"
|
|
137
|
+
];
|
|
138
|
+
for (const value of values) throws(() => parseDecimal(value), {
|
|
139
|
+
name: "TypeError",
|
|
140
|
+
message: `${JSON.stringify(value)} is not a valid xsd:decimal lexical form.`
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
test("parseDecimal() is exported from the package root", () => {
|
|
144
|
+
deepStrictEqual(parseDecimal("12.50"), "12.50");
|
|
145
|
+
});
|
|
146
|
+
test("canParseDecimal() is exported from the package root", () => {
|
|
147
|
+
deepStrictEqual(canParseDecimal(" 12.50 "), true);
|
|
148
|
+
});
|
|
149
|
+
test("isDecimal() is exported from the package root", () => {
|
|
150
|
+
deepStrictEqual(isDecimal("12.50"), true);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
//#endregion
|