@rdfx/literal 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ import type { Literal } from "@rdfjs/types";
2
+ import { Either } from "purify-ts";
3
+ import type { Primitive } from "./Primitive.js";
4
+ /**
5
+ * Decode other types from RDF/JS Literals.
6
+ *
7
+ * Partially adapted from rdf-literal.js (https://github.com/rubensworks/rdf-literal.js), MIT license.
8
+ */
9
+ export declare namespace LiteralDecoder {
10
+ function decodeBigIntLiteral(literal: Literal): Either<Error, bigint>;
11
+ function decodeBooleanLiteral(literal: Literal): Either<Error, boolean>;
12
+ function decodeDateLiteral(literal: Literal): Either<Error, Date>;
13
+ function decodeDateTimeLiteral(literal: Literal): Either<Error, Date>;
14
+ function decodeFloatLiteral(literal: Literal): Either<Error, number>;
15
+ function decodeIntLiteral(literal: Literal): Either<Error, number>;
16
+ function decodeNumberLiteral(literal: Literal): Either<Error, number>;
17
+ function decodePrimitiveLiteral(literal: Literal): Either<Error, Primitive>;
18
+ function decodeStringLiteral(literal: Literal): Either<Error, string>;
19
+ }
20
+ //# sourceMappingURL=LiteralDecoder.d.ts.map
@@ -0,0 +1,213 @@
1
+ import { Either, Left } from "purify-ts";
2
+ import { literalDatatypeDefinitions } from "./literalDatatypeDefinitions.js";
3
+ /**
4
+ * Decode other types from RDF/JS Literals.
5
+ *
6
+ * Partially adapted from rdf-literal.js (https://github.com/rubensworks/rdf-literal.js), MIT license.
7
+ */
8
+ export var LiteralDecoder;
9
+ (function (LiteralDecoder) {
10
+ const BIGINT_NUMBER_MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
11
+ const BIGINT_NUMBER_MIN_SAFE_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
12
+ function convertBigIntToNumber(literal, value) {
13
+ if (value >= BIGINT_NUMBER_MIN_SAFE_INTEGER &&
14
+ value <= BIGINT_NUMBER_MAX_SAFE_INTEGER) {
15
+ return Either.of(Number(value));
16
+ }
17
+ return Left(new LiteralValueError(literal, `bigint ${value} is outside number's safe integer range [${Number.MIN_SAFE_INTEGER}, ${Number.MAX_SAFE_INTEGER}]`));
18
+ }
19
+ function convertNumberToBigInt(literal, value) {
20
+ if (Number.isInteger(value)) {
21
+ return Either.of(BigInt(value));
22
+ }
23
+ return Left(new LiteralValueError(literal, `number ${value} is not an integer`));
24
+ }
25
+ function decodeBigIntLiteral(literal) {
26
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
27
+ if (!literalDatatypeDefinition) {
28
+ return Left(new LiteralDatatypeError(literal));
29
+ }
30
+ switch (literalDatatypeDefinition.kind) {
31
+ case "bigint":
32
+ return decodeBigIntLiteralValue(literal);
33
+ case "float":
34
+ return decodeFloatLiteralValue(literal).chain((value) => convertNumberToBigInt(literal, value));
35
+ case "int":
36
+ return decodeIntLiteralValue(literal).chain((value) => convertNumberToBigInt(literal, value));
37
+ default:
38
+ return Left(new LiteralDatatypeError(literal));
39
+ }
40
+ }
41
+ LiteralDecoder.decodeBigIntLiteral = decodeBigIntLiteral;
42
+ function decodeBigIntLiteralValue(literal) {
43
+ return Either.encase(() => BigInt(literal.value));
44
+ }
45
+ function decodeBooleanLiteral(literal) {
46
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "boolean") {
47
+ return decodeBooleanLiteralValue(literal);
48
+ }
49
+ return Left(new LiteralDatatypeError(literal));
50
+ }
51
+ LiteralDecoder.decodeBooleanLiteral = decodeBooleanLiteral;
52
+ function decodeBooleanLiteralValue(literal) {
53
+ switch (literal.value) {
54
+ case "false":
55
+ case "0":
56
+ return Either.of(false);
57
+ case "true":
58
+ case "1":
59
+ return Either.of(true);
60
+ default:
61
+ return Left(new LiteralValueError(literal));
62
+ }
63
+ }
64
+ function decodeDateLiteral(literal) {
65
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "date") {
66
+ return decodeDateLiteralValue(literal);
67
+ }
68
+ return Left(new LiteralDatatypeError(literal));
69
+ }
70
+ LiteralDecoder.decodeDateLiteral = decodeDateLiteral;
71
+ function decodeDateLiteralValue(literal) {
72
+ if (!literal.value.match(/^[0-9]+-[0-9][0-9]-[0-9][0-9]Z?$/)) {
73
+ return Left(new LiteralValueError(literal));
74
+ }
75
+ return Either.of(new Date(literal.value));
76
+ }
77
+ function decodeDateTimeLiteral(literal) {
78
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "datetime") {
79
+ return decodeDateTimeLiteralValue(literal);
80
+ }
81
+ return Left(new LiteralDatatypeError(literal));
82
+ }
83
+ LiteralDecoder.decodeDateTimeLiteral = decodeDateTimeLiteral;
84
+ function decodeDateTimeLiteralValue(literal) {
85
+ if (!literal.value.match(/^[0-9]+-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9](\.[0-9][0-9][0-9])?((Z?)|([+-][0-9][0-9]:[0-9][0-9]))$/)) {
86
+ return Left(new LiteralValueError(literal));
87
+ }
88
+ return Either.of(new Date(literal.value));
89
+ }
90
+ function decodeFloatLiteral(literal) {
91
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
92
+ if (!literalDatatypeDefinition) {
93
+ return Left(new LiteralDatatypeError(literal));
94
+ }
95
+ switch (literalDatatypeDefinition.kind) {
96
+ case "bigint":
97
+ return decodeBigIntLiteral(literal).chain((value) => convertBigIntToNumber(literal, value));
98
+ case "float":
99
+ case "int":
100
+ return decodeFloatLiteralValue(literal);
101
+ default:
102
+ return Left(new LiteralDatatypeError(literal));
103
+ }
104
+ }
105
+ LiteralDecoder.decodeFloatLiteral = decodeFloatLiteral;
106
+ function decodeFloatLiteralValue(literal) {
107
+ return Either.encase(() => {
108
+ switch (literal.value.toUpperCase()) {
109
+ case "NAN":
110
+ return NaN;
111
+ case "INF":
112
+ case "+INF":
113
+ return Infinity;
114
+ case "-INF":
115
+ return -Infinity;
116
+ }
117
+ const value = Number.parseFloat(literal.value);
118
+ if (Number.isNaN(value)) {
119
+ throw new LiteralValueError(literal, "not a number");
120
+ }
121
+ return value;
122
+ });
123
+ }
124
+ function decodeIntLiteral(literal) {
125
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
126
+ if (!literalDatatypeDefinition) {
127
+ return Left(new LiteralDatatypeError(literal));
128
+ }
129
+ switch (literalDatatypeDefinition.kind) {
130
+ case "bigint":
131
+ return decodeBigIntLiteral(literal).chain((value) => convertBigIntToNumber(literal, value));
132
+ case "float":
133
+ case "int":
134
+ return decodeIntLiteralValue(literal);
135
+ default:
136
+ return Left(new LiteralDatatypeError(literal));
137
+ }
138
+ }
139
+ LiteralDecoder.decodeIntLiteral = decodeIntLiteral;
140
+ function decodeIntLiteralValue(literal) {
141
+ return decodeFloatLiteralValue(literal).chain((value) => {
142
+ if (Number.isInteger(value)) {
143
+ return Either.of(value);
144
+ }
145
+ return Left(new LiteralValueError(literal, `${value} is not an integer`));
146
+ });
147
+ }
148
+ function decodeNumberLiteral(literal) {
149
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
150
+ if (!literalDatatypeDefinition) {
151
+ return Left(new LiteralDatatypeError(literal));
152
+ }
153
+ switch (literalDatatypeDefinition.kind) {
154
+ case "bigint":
155
+ return decodeBigIntLiteralValue(literal).chain((value) => convertBigIntToNumber(literal, value));
156
+ case "float":
157
+ return decodeFloatLiteralValue(literal);
158
+ case "int":
159
+ return decodeIntLiteralValue(literal);
160
+ default:
161
+ return Left(new LiteralDatatypeError(literal));
162
+ }
163
+ }
164
+ LiteralDecoder.decodeNumberLiteral = decodeNumberLiteral;
165
+ function decodePrimitiveLiteral(literal) {
166
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
167
+ if (!literalDatatypeDefinition) {
168
+ return Left(new LiteralDatatypeError(literal));
169
+ }
170
+ switch (literalDatatypeDefinition.kind) {
171
+ case "bigdecimal":
172
+ return Left(new LiteralDatatypeError(literal, "unable to decode bigdecimal Literal"));
173
+ case "bigint":
174
+ return decodeBigIntLiteralValue(literal);
175
+ case "boolean":
176
+ return decodeBooleanLiteralValue(literal);
177
+ case "date":
178
+ return decodeDateLiteralValue(literal);
179
+ case "datetime":
180
+ return decodeDateTimeLiteralValue(literal);
181
+ case "float":
182
+ return decodeFloatLiteralValue(literal);
183
+ case "int":
184
+ return decodeIntLiteralValue(literal);
185
+ case "string":
186
+ return decodeStringLiteralValue(literal);
187
+ }
188
+ }
189
+ LiteralDecoder.decodePrimitiveLiteral = decodePrimitiveLiteral;
190
+ function decodeStringLiteral(literal) {
191
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "string") {
192
+ return decodeStringLiteralValue(literal);
193
+ }
194
+ return Left(new LiteralDatatypeError(literal));
195
+ }
196
+ LiteralDecoder.decodeStringLiteral = decodeStringLiteral;
197
+ function decodeStringLiteralValue(literal) {
198
+ return Either.of(literal.value);
199
+ }
200
+ class LiteralDatatypeError extends Error {
201
+ constructor(literal, message) {
202
+ super(message ?? `unrecognized Literal datatype: ${literal.datatype.value}`);
203
+ this.literal = literal;
204
+ }
205
+ }
206
+ class LiteralValueError extends Error {
207
+ constructor(literal, message) {
208
+ super(message);
209
+ this.literal = literal;
210
+ }
211
+ }
212
+ })(LiteralDecoder || (LiteralDecoder = {}));
213
+ //# sourceMappingURL=LiteralDecoder.js.map
@@ -0,0 +1,20 @@
1
+ import type { DataFactory, Literal, NamedNode } from "@rdfjs/types";
2
+ import type { Primitive } from "./Primitive.js";
3
+ /**
4
+ * Factory with methods for creating RDF/JS Literals from other types.
5
+ */
6
+ export declare class LiteralFactory {
7
+ private readonly dataFactory;
8
+ private readonly xsd;
9
+ constructor({ dataFactory }: {
10
+ dataFactory: DataFactory;
11
+ });
12
+ bigint(value: bigint, datatype?: NamedNode): Literal;
13
+ boolean(value: boolean, datatype?: NamedNode): Literal;
14
+ date(value: Date, datatype?: NamedNode): Literal;
15
+ number(value: number, datatype?: NamedNode): Literal;
16
+ private numeric;
17
+ primitive(value: Primitive, datatype?: NamedNode): Literal;
18
+ string(value: string, datatype?: NamedNode): Literal;
19
+ }
20
+ //# sourceMappingURL=LiteralFactory.d.ts.map
@@ -0,0 +1,200 @@
1
+ import { literalDatatypeDefinitions } from "./literalDatatypeDefinitions.js";
2
+ class DatatypeRangeError extends RangeError {
3
+ constructor(datatype) {
4
+ super(`datatype out of range: ${datatype.value}`);
5
+ this.datatype = datatype;
6
+ }
7
+ }
8
+ /**
9
+ * Factory with methods for creating RDF/JS Literals from other types.
10
+ */
11
+ export class LiteralFactory {
12
+ constructor({ dataFactory }) {
13
+ this.dataFactory = dataFactory;
14
+ this.xsd = {
15
+ boolean: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean"),
16
+ byte: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#byte"),
17
+ date: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#date"),
18
+ dateTime: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#dateTime"),
19
+ dateTimeStamp: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#dateTimeStamp"),
20
+ decimal: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#decimal"),
21
+ double: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#double"),
22
+ float: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#float"),
23
+ int: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#int"),
24
+ integer: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#integer"),
25
+ long: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#long"),
26
+ short: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#short"),
27
+ string: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#string"),
28
+ unsignedByte: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedByte"),
29
+ unsignedInt: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedInt"),
30
+ unsignedLong: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedLong"),
31
+ unsignedShort: this.dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedShort"),
32
+ };
33
+ }
34
+ bigint(value, datatype) {
35
+ return this.numeric(value, datatype ?? this.xsd.integer);
36
+ }
37
+ boolean(value, datatype) {
38
+ if (!datatype) {
39
+ datatype = this.xsd.boolean;
40
+ }
41
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
42
+ if (datatypeDefinition && datatypeDefinition.kind !== "boolean") {
43
+ throw new DatatypeRangeError(datatype);
44
+ }
45
+ return this.dataFactory.literal(value.toString(), datatype);
46
+ }
47
+ date(value, datatype) {
48
+ if (!datatype) {
49
+ datatype = this.xsd.dateTime;
50
+ }
51
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
52
+ if (datatypeDefinition) {
53
+ switch (datatypeDefinition.kind) {
54
+ case "date":
55
+ return this.dataFactory.literal(value.toISOString().replace(/T.*$/, ""), datatype);
56
+ case "datetime":
57
+ return this.dataFactory.literal(value.toISOString(), datatype);
58
+ default:
59
+ throw new DatatypeRangeError(datatype);
60
+ }
61
+ }
62
+ // case "http://www.w3.org/2001/XMLSchema#gDay":
63
+ // return this.dataFactory.literal(
64
+ // value.getUTCDate().toString(),
65
+ // datatype,
66
+ // );
67
+ // case "http://www.w3.org/2001/XMLSchema#gMonthDay":
68
+ // return this.dataFactory.literal(
69
+ // `${value.getUTCMonth() + 1}-${value.getUTCDate()}`,
70
+ // datatype,
71
+ // );
72
+ // case "http://www.w3.org/2001/XMLSchema#gYear":
73
+ // return this.dataFactory.literal(
74
+ // value.getUTCFullYear().toString(),
75
+ // datatype,
76
+ // );
77
+ // case "http://www.w3.org/2001/XMLSchema#gYearMonth":
78
+ // return this.dataFactory.literal(
79
+ // `${value.getUTCFullYear()}-${value.getUTCMonth() + 1}`,
80
+ // datatype,
81
+ // );
82
+ return this.dataFactory.literal(value.toISOString(), datatype);
83
+ }
84
+ number(value, datatype) {
85
+ if (!datatype) {
86
+ if (Number.isInteger(value)) {
87
+ if (value < 0) {
88
+ datatype = [this.xsd.byte, this.xsd.short, this.xsd.int].find((checkDatatype) => {
89
+ const checkDatatypeDefinition = literalDatatypeDefinitions[checkDatatype.value];
90
+ if (checkDatatypeDefinition?.kind !== "int") {
91
+ throw new Error("should never happen");
92
+ }
93
+ return value >= checkDatatypeDefinition.range[0];
94
+ });
95
+ }
96
+ else {
97
+ datatype = [
98
+ this.xsd.unsignedByte,
99
+ this.xsd.unsignedShort,
100
+ this.xsd.unsignedInt,
101
+ ].find((checkDatatype) => {
102
+ const checkDatatypeDefinition = literalDatatypeDefinitions[checkDatatype.value];
103
+ if (checkDatatypeDefinition?.kind !== "int") {
104
+ throw new Error("should never happen");
105
+ }
106
+ return value <= checkDatatypeDefinition.range[1];
107
+ });
108
+ }
109
+ if (!datatype) {
110
+ datatype = this.xsd.integer;
111
+ }
112
+ }
113
+ else {
114
+ datatype = this.xsd.double;
115
+ }
116
+ }
117
+ return this.numeric(value, datatype);
118
+ }
119
+ numeric(value, datatype) {
120
+ let valueString;
121
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
122
+ if (datatypeDefinition) {
123
+ if (Number.isNaN(value) || value === Infinity || value === -Infinity) {
124
+ if (datatypeDefinition.kind !== "float") {
125
+ throw new RangeError(`NaN/INF/-INF values only supported by xsd:double and xsd:float`);
126
+ }
127
+ }
128
+ else {
129
+ switch (datatypeDefinition.kind) {
130
+ case "bigdecimal":
131
+ case "bigint":
132
+ case "float":
133
+ case "int": {
134
+ const [min, max] = datatypeDefinition.range;
135
+ if ((min !== undefined && value < min) ||
136
+ (max !== undefined && value > max)) {
137
+ throw new RangeError(`value (${value}) outside range [${min}, ${max}] of ${datatype.value}`);
138
+ }
139
+ break;
140
+ }
141
+ default:
142
+ throw new DatatypeRangeError(datatype);
143
+ }
144
+ if (datatypeDefinition.kind === "float") {
145
+ // Convert the number to scientific notation so Turtle will recognize it as an double without ^^
146
+ // Example: 1 -> 1e0
147
+ // Assume this coercion to number won't lose anything since we checked the range above.
148
+ let [mantissa, exponent] = Number(value).toExponential().split("e");
149
+ exponent = exponent.replace(/^\+/, "").replace(/^(-?)0+(\d)/, "$1$2");
150
+ valueString = `${mantissa}e${exponent}`;
151
+ }
152
+ }
153
+ }
154
+ if (!valueString) {
155
+ if (typeof value === "number") {
156
+ if (Number.isNaN(value)) {
157
+ valueString = "NaN";
158
+ }
159
+ else if (value === Infinity) {
160
+ valueString = "INF";
161
+ }
162
+ else if (value === -Infinity) {
163
+ valueString = "-INF";
164
+ }
165
+ }
166
+ if (!valueString) {
167
+ valueString = value.toString(10);
168
+ }
169
+ }
170
+ return this.dataFactory.literal(valueString, datatype);
171
+ }
172
+ primitive(value, datatype) {
173
+ switch (typeof value) {
174
+ case "bigint":
175
+ return this.bigint(value, datatype);
176
+ case "boolean":
177
+ return this.boolean(value, datatype);
178
+ case "object": {
179
+ if (value instanceof Date) {
180
+ return this.date(value, datatype);
181
+ }
182
+ throw new Error("not implemented");
183
+ }
184
+ case "number":
185
+ return this.number(value, datatype);
186
+ case "string":
187
+ return this.string(value, datatype);
188
+ }
189
+ }
190
+ string(value, datatype) {
191
+ if (datatype) {
192
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
193
+ if (datatypeDefinition && datatypeDefinition.kind !== "string") {
194
+ throw new DatatypeRangeError(datatype);
195
+ }
196
+ }
197
+ return this.dataFactory.literal(value, datatype);
198
+ }
199
+ }
200
+ //# sourceMappingURL=LiteralFactory.js.map
@@ -0,0 +1,2 @@
1
+ export type Primitive = bigint | boolean | Date | number | string;
2
+ //# sourceMappingURL=Primitive.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Primitive.js.map
@@ -0,0 +1,4 @@
1
+ export * from "./LiteralDecoder.js";
2
+ export * from "./LiteralFactory.js";
3
+ export * from "./literalDatatypeDefinitions.js";
4
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./LiteralDecoder.js";
2
+ export * from "./LiteralFactory.js";
3
+ export * from "./literalDatatypeDefinitions.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,24 @@
1
+ type LiteralDatatypeDefinition = {
2
+ kind: "bigdecimal";
3
+ readonly range: [undefined, undefined];
4
+ } | {
5
+ kind: "bigint";
6
+ range: readonly [bigint | undefined, bigint | undefined];
7
+ } | {
8
+ kind: "boolean";
9
+ } | {
10
+ kind: "date";
11
+ } | {
12
+ kind: "datetime";
13
+ } | {
14
+ kind: "float";
15
+ readonly range: readonly [number, number];
16
+ } | {
17
+ kind: "int";
18
+ readonly range: readonly [number, number];
19
+ } | {
20
+ kind: "string";
21
+ };
22
+ export declare const literalDatatypeDefinitions: Record<string, LiteralDatatypeDefinition>;
23
+ export {};
24
+ //# sourceMappingURL=literalDatatypeDefinitions.d.ts.map
@@ -0,0 +1,116 @@
1
+ export const literalDatatypeDefinitions = {
2
+ // Boolean
3
+ "http://www.w3.org/2001/XMLSchema#boolean": {
4
+ kind: "boolean",
5
+ },
6
+ // Date
7
+ "http://www.w3.org/2001/XMLSchema#date": {
8
+ kind: "date",
9
+ },
10
+ // Date-time
11
+ "http://www.w3.org/2001/XMLSchema#dateTime": {
12
+ kind: "datetime",
13
+ },
14
+ "http://www.w3.org/2001/XMLSchema#dateTimeStamp": {
15
+ kind: "datetime",
16
+ },
17
+ // Fixed-width floats
18
+ // 32-bit
19
+ "http://www.w3.org/2001/XMLSchema#float": {
20
+ kind: "float",
21
+ range: [-3.4028235e38, 3.4028235e38],
22
+ },
23
+ // 64-bit
24
+ "http://www.w3.org/2001/XMLSchema#double": {
25
+ kind: "float",
26
+ // Number.MIN_VALUE is the smallest positive number greater than 0
27
+ range: [-Number.MAX_VALUE, Number.MAX_VALUE],
28
+ },
29
+ // Arbitrary precision decimal
30
+ "http://www.w3.org/2001/XMLSchema#decimal": {
31
+ kind: "bigdecimal",
32
+ range: [undefined, undefined],
33
+ },
34
+ // Fixed-width integers
35
+ // 8-bit signed
36
+ "http://www.w3.org/2001/XMLSchema#byte": {
37
+ kind: "int",
38
+ range: [-128, 127],
39
+ },
40
+ // 16-bit signed
41
+ "http://www.w3.org/2001/XMLSchema#short": {
42
+ kind: "int",
43
+ range: [-32768, 32767],
44
+ },
45
+ // 32-bit signed
46
+ "http://www.w3.org/2001/XMLSchema#int": {
47
+ kind: "int",
48
+ range: [-2147483648, 2147483647],
49
+ },
50
+ // 64-bit signed
51
+ "http://www.w3.org/2001/XMLSchema#long": {
52
+ kind: "bigint",
53
+ range: [-9223372036854775808n, 9223372036854775807n],
54
+ },
55
+ // 8-bit unsigned
56
+ "http://www.w3.org/2001/XMLSchema#unsignedByte": {
57
+ kind: "int",
58
+ range: [0, 255],
59
+ },
60
+ // 16-bit unsigned
61
+ "http://www.w3.org/2001/XMLSchema#unsignedShort": {
62
+ kind: "int",
63
+ range: [0, 65535],
64
+ },
65
+ // 32-bit unsigned
66
+ "http://www.w3.org/2001/XMLSchema#unsignedInt": {
67
+ kind: "int",
68
+ range: [0, 4294967295],
69
+ },
70
+ // 64-bit unsigned
71
+ "http://www.w3.org/2001/XMLSchema#unsignedLong": {
72
+ kind: "bigint",
73
+ range: [0n, 18446744073709551615n],
74
+ },
75
+ // Arbitrary precision integers
76
+ "http://www.w3.org/2001/XMLSchema#integer": {
77
+ kind: "bigint",
78
+ range: [undefined, undefined],
79
+ },
80
+ "http://www.w3.org/2001/XMLSchema#negativeInteger": {
81
+ kind: "bigint",
82
+ range: [undefined, -1n],
83
+ },
84
+ "http://www.w3.org/2001/XMLSchema#nonNegativeInteger": {
85
+ kind: "bigint",
86
+ range: [0n, undefined],
87
+ },
88
+ "http://www.w3.org/2001/XMLSchema#nonPositiveInteger": {
89
+ kind: "bigint",
90
+ range: [undefined, 0n],
91
+ },
92
+ "http://www.w3.org/2001/XMLSchema#positiveInteger": {
93
+ kind: "bigint",
94
+ range: [1n, undefined],
95
+ },
96
+ // String
97
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString": {
98
+ kind: "string",
99
+ },
100
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString": { kind: "string" },
101
+ "http://www.w3.org/2001/XMLSchema#anyURI": { kind: "string" },
102
+ "http://www.w3.org/2001/XMLSchema#base64Binary": { kind: "string" },
103
+ "http://www.w3.org/2001/XMLSchema#duration": { kind: "string" },
104
+ "http://www.w3.org/2001/XMLSchema#hexBinary": { kind: "string" },
105
+ "http://www.w3.org/2001/XMLSchema#language": { kind: "string" },
106
+ "http://www.w3.org/2001/XMLSchema#Name": { kind: "string" },
107
+ "http://www.w3.org/2001/XMLSchema#NCName": { kind: "string" },
108
+ "http://www.w3.org/2001/XMLSchema#NMTOKEN": { kind: "string" },
109
+ "http://www.w3.org/2001/XMLSchema#NOTATION": { kind: "string" },
110
+ "http://www.w3.org/2001/XMLSchema#normalizedString": { kind: "string" },
111
+ "http://www.w3.org/2001/XMLSchema#QName": { kind: "string" },
112
+ "http://www.w3.org/2001/XMLSchema#string": { kind: "string" },
113
+ "http://www.w3.org/2001/XMLSchema#time": { kind: "string" },
114
+ "http://www.w3.org/2001/XMLSchema#token": { kind: "string" },
115
+ };
116
+ //# sourceMappingURL=literalDatatypeDefinitions.js.map
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "dependencies": {
3
+ "@rdfjs/types": "~2.0.1",
4
+ "purify-ts": "~2.1.4"
5
+ },
6
+ "devDependencies": {
7
+ "@rdfjs/data-model": "~2.1.1",
8
+ "@tpluscode/rdf-ns-builders": "~4.3.0",
9
+ "@types/rdfjs__data-model": "~2.0.9"
10
+ },
11
+ "files": [
12
+ "dist/*.d.ts",
13
+ "dist/*.js"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "main": "./dist/index.js",
17
+ "name": "@rdfx/literal",
18
+ "packageManager": "npm@11.11.0",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/minorg/rdfx.git"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc -b",
25
+ "clean": "rimraf dist",
26
+ "depcheck": "depcheck .",
27
+ "dev": "tsc -w --preserveWatchOutput",
28
+ "dev:tests": "tsc -p __tests__ -w --preserveWatchOutput",
29
+ "test": "cd ../.. && vitest run --project @rdfx/literal"
30
+ },
31
+ "type": "module",
32
+ "types": "./dist/index.d.ts",
33
+ "version": "0.0.1"
34
+ }