rdflib 2.2.35 → 2.2.36

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 (90) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +0 -2
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +57 -82
  5. package/esm/class-order.js +1 -1
  6. package/esm/collection.js +70 -103
  7. package/esm/default-graph.js +13 -30
  8. package/esm/empty.js +8 -23
  9. package/esm/factories/canonical-data-factory.js +33 -29
  10. package/esm/factories/extended-term-factory.js +18 -13
  11. package/esm/factories/factory-types.js +1 -1
  12. package/esm/factories/rdflib-data-factory.js +9 -11
  13. package/esm/fetcher.js +1366 -1651
  14. package/esm/formula.js +631 -736
  15. package/esm/index.js +31 -48
  16. package/esm/jsonldparser.js +19 -26
  17. package/esm/jsonparser.js +1 -1
  18. package/esm/lists.js +38 -86
  19. package/esm/literal.js +120 -154
  20. package/esm/log.js +7 -7
  21. package/esm/n3parser.js +1009 -1086
  22. package/esm/named-node.js +69 -96
  23. package/esm/namespace.js +2 -4
  24. package/esm/node-internal.js +73 -96
  25. package/esm/node.js +1 -1
  26. package/esm/parse.js +3 -3
  27. package/esm/patch-parser.js +1 -1
  28. package/esm/query.js +15 -16
  29. package/esm/rdfaparser.js +775 -841
  30. package/esm/rdfxmlparser.js +348 -364
  31. package/esm/serialize.js +2 -2
  32. package/esm/serializer.js +835 -877
  33. package/esm/statement.js +52 -71
  34. package/esm/store.js +853 -957
  35. package/esm/types.js +21 -21
  36. package/esm/update-manager.js +965 -1100
  37. package/esm/updates-via.js +104 -132
  38. package/esm/uri.js +3 -3
  39. package/esm/utils/default-graph-uri.js +2 -2
  40. package/esm/utils/terms.js +4 -5
  41. package/esm/utils-js.js +5 -5
  42. package/esm/utils.js +6 -6
  43. package/esm/variable.js +32 -55
  44. package/esm/xsd.js +2 -2
  45. package/lib/blank-node.js +57 -80
  46. package/lib/class-order.js +1 -1
  47. package/lib/collection.js +70 -101
  48. package/lib/default-graph.js +14 -29
  49. package/lib/empty.js +9 -22
  50. package/lib/factories/canonical-data-factory.js +35 -31
  51. package/lib/factories/extended-term-factory.js +18 -13
  52. package/lib/factories/factory-types.js +1 -1
  53. package/lib/factories/rdflib-data-factory.js +9 -11
  54. package/lib/fetcher.js +1375 -1654
  55. package/lib/formula.js +632 -735
  56. package/lib/index.js +80 -84
  57. package/lib/jsonldparser.js +21 -32
  58. package/lib/jsonparser.js +1 -1
  59. package/lib/lists.js +47 -87
  60. package/lib/literal.js +121 -153
  61. package/lib/log.js +7 -7
  62. package/lib/n3parser.js +1012 -1090
  63. package/lib/named-node.js +70 -95
  64. package/lib/namespace.js +2 -4
  65. package/lib/node-internal.js +73 -94
  66. package/lib/node.js +1 -1
  67. package/lib/parse.js +5 -6
  68. package/lib/patch-parser.js +1 -1
  69. package/lib/query.js +20 -18
  70. package/lib/rdfaparser.js +778 -843
  71. package/lib/rdfxmlparser.js +351 -365
  72. package/lib/serialize.js +2 -2
  73. package/lib/serializer.js +840 -880
  74. package/lib/statement.js +55 -73
  75. package/lib/store.js +860 -958
  76. package/lib/types.js +21 -21
  77. package/lib/update-manager.js +970 -1102
  78. package/lib/updates-via.js +107 -132
  79. package/lib/uri.js +3 -3
  80. package/lib/utils/default-graph-uri.js +2 -2
  81. package/lib/utils/terms.js +4 -6
  82. package/lib/utils-js.js +8 -9
  83. package/lib/utils.js +6 -6
  84. package/lib/variable.js +35 -57
  85. package/lib/xsd.js +2 -2
  86. package/package.json +2 -2
  87. package/src/n3parser.js +1 -1
  88. package/src/serializer.js +1 -1
  89. package/src/update-manager.ts +2 -1
  90. package/.babelrc +0 -20
package/lib/lists.js CHANGED
@@ -10,10 +10,10 @@ exports.substituteNillsInDoc = substituteNillsInDoc;
10
10
  var _collection = _interopRequireDefault(require("./collection"));
11
11
  var _statement = _interopRequireDefault(require("./statement"));
12
12
  var _namespace = _interopRequireDefault(require("./namespace"));
13
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
14
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /* Lists form conversion
16
- */ // import DataFactory from './factories/extended-term-factory'
13
+ /* Lists form conversion
14
+ */
15
+
16
+ // import DataFactory from './factories/extended-term-factory'
17
17
  // import jsonldParser from './jsonldparser'
18
18
  // @ts-ignore is this injected?
19
19
  // @@ Goal: remove this dependency
@@ -22,12 +22,17 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
22
22
  // import RDFParser from './rdfxmlparser'
23
23
  // import sparqlUpdateParser from './patch-parser'
24
24
  // import * as Util from './utils-js'
25
+
25
26
  // import BlankNode from './blank-node'
26
27
  // import NamedNode from './named-node'
28
+
27
29
  // import Formula from './formula'
30
+
28
31
  // import { ContentType, TurtleContentType, N3ContentType, RDFXMLContentType, XHTMLContentType, HTMLContentType, SPARQLUpdateContentType, SPARQLUpdateSingleMatchContentType, JSONLDContentType, NQuadsContentType, NQuadsAltContentType } from './types'
32
+
29
33
  // import { Quad } from './tf-types'
30
- var RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
34
+
35
+ const RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
31
36
 
32
37
  /* Replace a given node with another node throughout a given document
33
38
  *
@@ -35,83 +40,38 @@ var RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
35
40
  */
36
41
  function substituteInDoc(store, x, y, doc) {
37
42
  // console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
38
- var _iterator = _createForOfIteratorHelper(store.statementsMatching(y, null, null, doc)),
39
- _step;
40
- try {
41
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
- var quad = _step.value;
43
- var newStatement = new _statement.default(x, quad.predicate, quad.object, doc);
44
- store.remove(quad);
45
- store.add(newStatement);
46
- }
47
- } catch (err) {
48
- _iterator.e(err);
49
- } finally {
50
- _iterator.f();
43
+ for (const quad of store.statementsMatching(y, null, null, doc)) {
44
+ const newStatement = new _statement.default(x, quad.predicate, quad.object, doc);
45
+ store.remove(quad);
46
+ store.add(newStatement);
51
47
  }
52
- var _iterator2 = _createForOfIteratorHelper(store.statementsMatching(null, y, null, doc)),
53
- _step2;
54
- try {
55
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
56
- var _quad = _step2.value;
57
- store.remove(_quad);
58
- // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
59
- store.add(new _statement.default(_quad.subject, x, _quad.object, doc));
60
- }
61
- } catch (err) {
62
- _iterator2.e(err);
63
- } finally {
64
- _iterator2.f();
48
+ for (const quad of store.statementsMatching(null, y, null, doc)) {
49
+ store.remove(quad);
50
+ // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
51
+ store.add(new _statement.default(quad.subject, x, quad.object, doc));
65
52
  }
66
- var _iterator3 = _createForOfIteratorHelper(store.statementsMatching(null, null, y, doc)),
67
- _step3;
68
- try {
69
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
70
- var _quad2 = _step3.value;
71
- store.remove(_quad2);
72
- store.add(new _statement.default(_quad2.subject, _quad2.predicate, x, doc));
73
- }
74
- } catch (err) {
75
- _iterator3.e(err);
76
- } finally {
77
- _iterator3.f();
53
+ for (const quad of store.statementsMatching(null, null, y, doc)) {
54
+ store.remove(quad);
55
+ store.add(new _statement.default(quad.subject, quad.predicate, x, doc));
78
56
  }
79
57
  }
80
58
 
81
59
  /* Change all lone rdf:nil nodes into empty Collections
82
60
  */
83
61
  function substituteNillsInDoc(store, doc) {
84
- var x = RDF('nil');
85
- var _iterator4 = _createForOfIteratorHelper(store.statementsMatching(x, null, null, doc)),
86
- _step4;
87
- try {
88
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
89
- var quad = _step4.value;
90
- store.remove(quad);
91
- var y = new _collection.default();
92
- store.add(new _statement.default(y, quad.predicate, quad.object, doc));
93
- }
94
- } catch (err) {
95
- _iterator4.e(err);
96
- } finally {
97
- _iterator4.f();
62
+ const x = RDF('nil');
63
+ for (const quad of store.statementsMatching(x, null, null, doc)) {
64
+ store.remove(quad);
65
+ const y = new _collection.default();
66
+ store.add(new _statement.default(y, quad.predicate, quad.object, doc));
98
67
  }
99
- var _iterator5 = _createForOfIteratorHelper(store.statementsMatching(null, null, x, doc)),
100
- _step5;
101
- try {
102
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
103
- var _quad3 = _step5.value;
104
- if (!_quad3.predicate.sameTerm(RDF('rest'))) {
105
- // If not a tail
106
- store.remove(_quad3);
107
- var _y = new _collection.default();
108
- store.add(new _statement.default(_quad3.subject, _quad3.predicate, _y, doc));
109
- }
68
+ for (const quad of store.statementsMatching(null, null, x, doc)) {
69
+ if (!quad.predicate.sameTerm(RDF('rest'))) {
70
+ // If not a tail
71
+ store.remove(quad);
72
+ const y = new _collection.default();
73
+ store.add(new _statement.default(quad.subject, quad.predicate, y, doc));
110
74
  }
111
- } catch (err) {
112
- _iterator5.e(err);
113
- } finally {
114
- _iterator5.f();
115
75
  }
116
76
  }
117
77
  /**
@@ -126,34 +86,34 @@ function substituteNillsInDoc(store, doc) {
126
86
  function convertFirstRestNil(store, doc // Do whole store?
127
87
  ) {
128
88
  function preceding(ele, listSoFar, trash) {
129
- var rests = store.statementsMatching(ele, RDF('rest'), null, doc);
130
- if (rests.length !== 1) throw new Error("Bad list structure: no rest at ".concat(ele));
131
- var firsts = store.statementsMatching(ele, RDF('first'), null, doc);
132
- if (firsts.length !== 1) throw new Error("Bad list structure: rest but ".concat(firsts.length, " firsts at ").concat(ele));
133
- var value = firsts[0].object;
134
- var total = [value].concat(listSoFar);
89
+ const rests = store.statementsMatching(ele, RDF('rest'), null, doc);
90
+ if (rests.length !== 1) throw new Error(`Bad list structure: no rest at ${ele}`);
91
+ const firsts = store.statementsMatching(ele, RDF('first'), null, doc);
92
+ if (firsts.length !== 1) throw new Error(`Bad list structure: rest but ${firsts.length} firsts at ${ele}`);
93
+ const value = firsts[0].object;
94
+ const total = [value].concat(listSoFar);
135
95
  // console.log(' List now is: ', total)
136
- var totalTrash = trash.concat(rests).concat(firsts);
137
- var pres = store.statementsMatching(null, RDF('rest'), ele, doc);
96
+ const totalTrash = trash.concat(rests).concat(firsts);
97
+ const pres = store.statementsMatching(null, RDF('rest'), ele, doc);
138
98
  if (pres.length === 0) {
139
99
  // Head of the list
140
- var newList = new _collection.default(total);
100
+ const newList = new _collection.default(total);
141
101
  store.remove(totalTrash);
142
102
  // Replace old list with new list:
143
103
  substituteInDoc(store, newList, ele, doc);
144
104
  return;
145
105
  }
146
- if (pres.length !== 1) throw new Error("Bad list structure: ".concat(pres.length, " pres at ").concat(ele));
147
- var pre = pres[0].subject;
148
- if (pre.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(pre, " type: ").concat(pre.termType, " "));
106
+ if (pres.length !== 1) throw new Error(`Bad list structure: ${pres.length} pres at ${ele}`);
107
+ const pre = pres[0].subject;
108
+ if (pre.termType !== 'BlankNode') throw new Error(`Bad list element node ${pre} type: ${pre.termType} `);
149
109
  preceding(pre, total, totalTrash);
150
110
  return;
151
111
  }
152
112
  substituteNillsInDoc(store, doc); // lone ones only
153
113
 
154
- var tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
155
- tails.forEach(function (tail) {
156
- if (tail.subject.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(tail.subject, " type: ").concat(tail.subject.termType, " "));
114
+ const tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
115
+ tails.forEach(tail => {
116
+ if (tail.subject.termType !== 'BlankNode') throw new Error(`Bad list element node ${tail.subject} type: ${tail.subject.termType} `);
157
117
  preceding(tail.subject, [], []);
158
118
  });
159
119
  }
package/lib/literal.js CHANGED
@@ -5,12 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
9
  var _classOrder = _interopRequireDefault(require("./class-order"));
16
10
  var _namedNode = _interopRequireDefault(require("./named-node"));
@@ -18,188 +12,162 @@ var _nodeInternal = _interopRequireDefault(require("./node-internal"));
18
12
  var _types = require("./types");
19
13
  var _terms = require("./utils/terms");
20
14
  var _xsdInternal = _interopRequireDefault(require("./xsd-internal"));
21
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
22
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
23
15
  /**
24
16
  * An RDF literal, containing some value which isn't expressed as an IRI.
25
17
  * @link https://rdf.js.org/data-model-spec/#literal-interface
26
18
  */
27
- var Literal = exports.default = /*#__PURE__*/function (_Node) {
19
+ class Literal extends _nodeInternal.default {
28
20
  /**
29
21
  * Initializes a literal
30
22
  * @param value - The literal's lexical value
31
23
  * @param language - The language for the literal. Defaults to ''.
32
24
  * @param datatype - The literal's datatype as a named node. Defaults to xsd:string.
33
25
  */
34
- function Literal(value, language, datatype) {
35
- var _this;
36
- (0, _classCallCheck2.default)(this, Literal);
37
- _this = _callSuper(this, Literal, [value]);
38
- (0, _defineProperty2.default)(_this, "termType", _types.LiteralTermType);
39
- (0, _defineProperty2.default)(_this, "classOrder", _classOrder.default.Literal);
26
+ constructor(value, language, datatype) {
27
+ super(value);
28
+ (0, _defineProperty2.default)(this, "termType", _types.LiteralTermType);
29
+ (0, _defineProperty2.default)(this, "classOrder", _classOrder.default.Literal);
40
30
  /**
41
31
  * The literal's datatype as a named node
42
32
  */
43
- (0, _defineProperty2.default)(_this, "datatype", _xsdInternal.default.string);
44
- (0, _defineProperty2.default)(_this, "isVar", 0);
33
+ (0, _defineProperty2.default)(this, "datatype", _xsdInternal.default.string);
34
+ (0, _defineProperty2.default)(this, "isVar", 0);
45
35
  /**
46
36
  * The language for the literal
47
37
  */
48
- (0, _defineProperty2.default)(_this, "language", '');
38
+ (0, _defineProperty2.default)(this, "language", '');
49
39
  if (language) {
50
- _this.language = language;
51
- _this.datatype = _xsdInternal.default.langString;
40
+ this.language = language;
41
+ this.datatype = _xsdInternal.default.langString;
52
42
  } else if (datatype) {
53
- _this.datatype = _namedNode.default.fromValue(datatype);
43
+ this.datatype = _namedNode.default.fromValue(datatype);
54
44
  } else {
55
- _this.datatype = _xsdInternal.default.string;
45
+ this.datatype = _xsdInternal.default.string;
56
46
  }
57
- return _this;
58
47
  }
59
48
 
60
49
  /**
61
50
  * Gets a copy of this literal
62
51
  */
63
- (0, _inherits2.default)(Literal, _Node);
64
- return (0, _createClass2.default)(Literal, [{
65
- key: "copy",
66
- value: function copy() {
67
- return new Literal(this.value, this.lang, this.datatype);
68
- }
52
+ copy() {
53
+ return new Literal(this.value, this.lang, this.datatype);
54
+ }
69
55
 
70
- /**
71
- * Gets whether two literals are the same
72
- * @param other The other statement
73
- */
74
- }, {
75
- key: "equals",
76
- value: function equals(other) {
77
- if (!other) {
78
- return false;
79
- }
80
- return this.termType === other.termType && this.value === other.value && this.language === other.language && (!this.datatype && !other.datatype || this.datatype && this.datatype.equals(other.datatype));
56
+ /**
57
+ * Gets whether two literals are the same
58
+ * @param other The other statement
59
+ */
60
+ equals(other) {
61
+ if (!other) {
62
+ return false;
81
63
  }
64
+ return this.termType === other.termType && this.value === other.value && this.language === other.language && (!this.datatype && !other.datatype || this.datatype && this.datatype.equals(other.datatype));
65
+ }
82
66
 
83
- /**
84
- * The language for the literal
85
- * @deprecated use {language} instead
86
- */
87
- }, {
88
- key: "lang",
89
- get: function get() {
90
- return this.language;
91
- },
92
- set: function set(language) {
93
- this.language = language || '';
67
+ /**
68
+ * The language for the literal
69
+ * @deprecated use {language} instead
70
+ */
71
+ get lang() {
72
+ return this.language;
73
+ }
74
+ set lang(language) {
75
+ this.language = language || '';
76
+ }
77
+ toNT() {
78
+ return Literal.toNT(this);
79
+ }
80
+
81
+ /** Serializes a literal to an N-Triples string */
82
+ static toNT(literal) {
83
+ if (typeof literal.value === 'number') {
84
+ return '' + literal.value;
85
+ } else if (typeof literal.value !== 'string') {
86
+ throw new Error('Value of RDF literal is not string or number: ' + literal.value);
94
87
  }
95
- }, {
96
- key: "toNT",
97
- value: function toNT() {
98
- return Literal.toNT(this);
88
+ var str = literal.value;
89
+ // #x22 ("), #x5C (\), #x0A (\n) and #xD (\r) are disallowed and need to be replaced
90
+ // see https://www.w3.org/TR/n-triples/#grammar-production-STRING_LITERAL_QUOTE
91
+ str = str.replace(/\\/g, '\\\\');
92
+ str = str.replace(/\"/g, '\\"');
93
+ str = str.replace(/\n/g, '\\n');
94
+ str = str.replace(/\r/g, '\\r');
95
+ str = '"' + str + '"';
96
+ if (literal.language) {
97
+ str += '@' + literal.language;
98
+ } else if (!literal.datatype.equals(_xsdInternal.default.string)) {
99
+ // Only add datatype if it's not a string
100
+ str += '^^' + literal.datatype.toCanonical();
99
101
  }
102
+ return str;
103
+ }
104
+ toString() {
105
+ return '' + this.value;
106
+ }
100
107
 
101
- /** Serializes a literal to an N-Triples string */
102
- }, {
103
- key: "toString",
104
- value: function toString() {
105
- return '' + this.value;
106
- }
108
+ /**
109
+ * Builds a literal node from a boolean value
110
+ * @param value - The value
111
+ */
112
+ static fromBoolean(value) {
113
+ let strValue = value ? '1' : '0';
114
+ return new Literal(strValue, null, _xsdInternal.default.boolean);
115
+ }
107
116
 
108
- /**
109
- * Builds a literal node from a boolean value
110
- * @param value - The value
111
- */
112
- }], [{
113
- key: "toNT",
114
- value: function toNT(literal) {
115
- if (typeof literal.value === 'number') {
116
- return '' + literal.value;
117
- } else if (typeof literal.value !== 'string') {
118
- throw new Error('Value of RDF literal is not string or number: ' + literal.value);
119
- }
120
- var str = literal.value;
121
- // #x22 ("), #x5C (\), #x0A (\n) and #xD (\r) are disallowed and need to be replaced
122
- // see https://www.w3.org/TR/n-triples/#grammar-production-STRING_LITERAL_QUOTE
123
- str = str.replace(/\\/g, '\\\\');
124
- str = str.replace(/\"/g, '\\"');
125
- str = str.replace(/\n/g, '\\n');
126
- str = str.replace(/\r/g, '\\r');
127
- str = '"' + str + '"';
128
- if (literal.language) {
129
- str += '@' + literal.language;
130
- } else if (!literal.datatype.equals(_xsdInternal.default.string)) {
131
- // Only add datatype if it's not a string
132
- str += '^^' + literal.datatype.toCanonical();
133
- }
134
- return str;
135
- }
136
- }, {
137
- key: "fromBoolean",
138
- value: function fromBoolean(value) {
139
- var strValue = value ? '1' : '0';
140
- return new Literal(strValue, null, _xsdInternal.default.boolean);
117
+ /**
118
+ * Builds a literal node from a date value
119
+ * @param value The value
120
+ */
121
+ static fromDate(value) {
122
+ if (!(value instanceof Date)) {
123
+ throw new TypeError('Invalid argument to Literal.fromDate()');
141
124
  }
125
+ let d2 = function (x) {
126
+ return ('' + (100 + x)).slice(1, 3);
127
+ };
128
+ let date = '' + value.getUTCFullYear() + '-' + d2(value.getUTCMonth() + 1) + '-' + d2(value.getUTCDate()) + 'T' + d2(value.getUTCHours()) + ':' + d2(value.getUTCMinutes()) + ':' + d2(value.getUTCSeconds()) + 'Z';
129
+ return new Literal(date, null, _xsdInternal.default.dateTime);
130
+ }
142
131
 
143
- /**
144
- * Builds a literal node from a date value
145
- * @param value The value
146
- */
147
- }, {
148
- key: "fromDate",
149
- value: function fromDate(value) {
150
- if (!(value instanceof Date)) {
151
- throw new TypeError('Invalid argument to Literal.fromDate()');
152
- }
153
- var d2 = function d2(x) {
154
- return ('' + (100 + x)).slice(1, 3);
155
- };
156
- var date = '' + value.getUTCFullYear() + '-' + d2(value.getUTCMonth() + 1) + '-' + d2(value.getUTCDate()) + 'T' + d2(value.getUTCHours()) + ':' + d2(value.getUTCMinutes()) + ':' + d2(value.getUTCSeconds()) + 'Z';
157
- return new Literal(date, null, _xsdInternal.default.dateTime);
132
+ /**
133
+ * Builds a literal node from a number value
134
+ * @param value - The value
135
+ */
136
+ static fromNumber(value) {
137
+ if (typeof value !== 'number') {
138
+ throw new TypeError('Invalid argument to Literal.fromNumber()');
158
139
  }
159
-
160
- /**
161
- * Builds a literal node from a number value
162
- * @param value - The value
163
- */
164
- }, {
165
- key: "fromNumber",
166
- value: function fromNumber(value) {
167
- if (typeof value !== 'number') {
168
- throw new TypeError('Invalid argument to Literal.fromNumber()');
169
- }
170
- var datatype;
171
- var strValue = value.toString();
172
- if (strValue.indexOf('e') < 0 && Math.abs(value) <= Number.MAX_SAFE_INTEGER) {
173
- datatype = Number.isInteger(value) ? _xsdInternal.default.integer : _xsdInternal.default.decimal;
174
- } else {
175
- datatype = _xsdInternal.default.double;
176
- }
177
- return new Literal(strValue, null, datatype);
140
+ let datatype;
141
+ const strValue = value.toString();
142
+ if (strValue.indexOf('e') < 0 && Math.abs(value) <= Number.MAX_SAFE_INTEGER) {
143
+ datatype = Number.isInteger(value) ? _xsdInternal.default.integer : _xsdInternal.default.decimal;
144
+ } else {
145
+ datatype = _xsdInternal.default.double;
178
146
  }
147
+ return new Literal(strValue, null, datatype);
148
+ }
179
149
 
180
- /**
181
- * Builds a literal node from an input value
182
- * @param value - The input value
183
- */
184
- }, {
185
- key: "fromValue",
186
- value: function fromValue(value) {
187
- if ((0, _terms.isLiteral)(value)) {
188
- return value;
189
- }
190
- switch ((0, _typeof2.default)(value)) {
191
- case 'object':
192
- if (value instanceof Date) {
193
- return Literal.fromDate(value);
194
- }
195
- case 'boolean':
196
- return Literal.fromBoolean(value);
197
- case 'number':
198
- return Literal.fromNumber(value);
199
- case 'string':
200
- return new Literal(value);
201
- }
202
- throw new Error("Can't make literal from " + value + ' of type ' + (0, _typeof2.default)(value));
150
+ /**
151
+ * Builds a literal node from an input value
152
+ * @param value - The input value
153
+ */
154
+ static fromValue(value) {
155
+ if ((0, _terms.isLiteral)(value)) {
156
+ return value;
203
157
  }
204
- }]);
205
- }(_nodeInternal.default);
158
+ switch (typeof value) {
159
+ case 'object':
160
+ if (value instanceof Date) {
161
+ return Literal.fromDate(value);
162
+ }
163
+ case 'boolean':
164
+ return Literal.fromBoolean(value);
165
+ case 'number':
166
+ return Literal.fromNumber(value);
167
+ case 'string':
168
+ return new Literal(value);
169
+ }
170
+ throw new Error("Can't make literal from " + value + ' of type ' + typeof value);
171
+ }
172
+ }
173
+ exports.default = Literal;
package/lib/log.js CHANGED
@@ -8,12 +8,12 @@ exports.default = void 0;
8
8
  * A Dummy log
9
9
  * @module log
10
10
  */
11
- var log = {
12
- debug: function debug(x) {},
13
- warn: function warn(x) {},
14
- info: function info(x) {},
15
- error: function error(x) {},
16
- success: function success(x) {},
17
- msg: function msg(x) {}
11
+ const log = {
12
+ debug(x) {},
13
+ warn(x) {},
14
+ info(x) {},
15
+ error(x) {},
16
+ success(x) {},
17
+ msg(x) {}
18
18
  };
19
19
  var _default = exports.default = log;