treedoc 0.3.49 → 0.3.51
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/lib/Bookmark.js +1 -1
- package/lib/Bookmark.js.map +1 -1
- package/lib/TD.d.ts +2 -2
- package/lib/TD.js +8 -6
- package/lib/TD.js.map +1 -1
- package/lib/TDNode.d.ts +1 -1
- package/lib/TDNode.js +11 -9
- package/lib/TDNode.js.map +1 -1
- package/lib/TDNodeProxyHandler.js +1 -1
- package/lib/TDNodeProxyHandler.js.map +1 -1
- package/lib/TDPath.js +1 -1
- package/lib/TDPath.js.map +1 -1
- package/lib/TreeDoc.js +4 -4
- package/lib/TreeDoc.js.map +1 -1
- package/lib/core/CharSource.js +1 -1
- package/lib/core/CharSource.js.map +1 -1
- package/lib/core/ClassUtil.js.map +1 -1
- package/lib/core/EOFRuntimeException.js +2 -0
- package/lib/core/EOFRuntimeException.js.map +1 -1
- package/lib/core/LangUtil.d.ts +8 -8
- package/lib/core/LangUtil.js +11 -9
- package/lib/core/LangUtil.js.map +1 -1
- package/lib/core/ParseRuntimeException.js +2 -0
- package/lib/core/ParseRuntimeException.js.map +1 -1
- package/lib/core/StringBuilder.js.map +1 -1
- package/lib/core/StringCharSource.js +2 -0
- package/lib/core/StringCharSource.js.map +1 -1
- package/lib/core/StringUtil.js.map +1 -1
- package/lib/csv/CSVParser.js.map +1 -1
- package/lib/csv/CSVWriter.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/json/JSONPointer.js.map +1 -1
- package/lib/json/NodeFilter.js +12 -8
- package/lib/json/NodeFilter.js.map +1 -1
- package/lib/json/TDJSONOption.js.map +1 -1
- package/lib/json/TDJSONParser.js +5 -5
- package/lib/json/TDJSONParser.js.map +1 -1
- package/lib/json/TDJSONParserOption.js +2 -0
- package/lib/json/TDJSONParserOption.js.map +1 -1
- package/lib/json/TDJSONWriter.js.map +1 -1
- package/lib/json/TDJSONWriterOption.js +3 -1
- package/lib/json/TDJSONWriterOption.js.map +1 -1
- package/lib/objcoder/TDObjectCoder.d.ts +1 -1
- package/lib/objcoder/TDObjectCoder.js +2 -2
- package/lib/objcoder/TDObjectCoder.js.map +1 -1
- package/lib/src/Bookmark.d.ts +9 -0
- package/lib/src/Bookmark.js +31 -0
- package/lib/src/Bookmark.js.map +1 -0
- package/lib/src/TD.d.ts +20 -0
- package/lib/src/TD.js +53 -0
- package/lib/src/TD.js.map +1 -0
- package/lib/src/TDNode.d.ts +84 -0
- package/lib/src/TDNode.js +378 -0
- package/lib/src/TDNode.js.map +1 -0
- package/lib/src/TDNodeProxyHandler.d.ts +7 -0
- package/lib/src/TDNodeProxyHandler.js +50 -0
- package/lib/src/TDNodeProxyHandler.js.map +1 -0
- package/lib/src/TDPath.d.ts +31 -0
- package/lib/src/TDPath.js +87 -0
- package/lib/src/TDPath.js.map +1 -0
- package/lib/src/TreeDoc.d.ts +27 -0
- package/lib/src/TreeDoc.js +93 -0
- package/lib/src/TreeDoc.js.map +1 -0
- package/lib/src/__tests__/TD.spec.d.ts +1 -0
- package/lib/src/__tests__/TD.spec.js +90 -0
- package/lib/src/__tests__/TD.spec.js.map +1 -0
- package/lib/src/__tests__/TDNode.spec.d.ts +1 -0
- package/lib/src/__tests__/TDNode.spec.js +49 -0
- package/lib/src/__tests__/TDNode.spec.js.map +1 -0
- package/lib/src/__tests__/TDPath.spec.d.ts +1 -0
- package/lib/src/__tests__/TDPath.spec.js +15 -0
- package/lib/src/__tests__/TDPath.spec.js.map +1 -0
- package/lib/src/core/Appendable.d.ts +3 -0
- package/lib/src/core/Appendable.js +3 -0
- package/lib/src/core/Appendable.js.map +1 -0
- package/lib/src/core/CharSource.d.ts +47 -0
- package/lib/src/core/CharSource.js +199 -0
- package/lib/src/core/CharSource.js.map +1 -0
- package/lib/src/core/ClassUtil.d.ts +9 -0
- package/lib/src/core/ClassUtil.js +34 -0
- package/lib/src/core/ClassUtil.js.map +1 -0
- package/lib/src/core/EOFRuntimeException.d.ts +5 -0
- package/lib/src/core/EOFRuntimeException.js +32 -0
- package/lib/src/core/EOFRuntimeException.js.map +1 -0
- package/lib/src/core/LangUtil.d.ts +38 -0
- package/lib/src/core/LangUtil.js +110 -0
- package/lib/src/core/LangUtil.js.map +1 -0
- package/lib/src/core/ListUtil.d.ts +19 -0
- package/lib/src/core/ListUtil.js +38 -0
- package/lib/src/core/ListUtil.js.map +1 -0
- package/lib/src/core/ParseRuntimeException.d.ts +11 -0
- package/lib/src/core/ParseRuntimeException.js +40 -0
- package/lib/src/core/ParseRuntimeException.js.map +1 -0
- package/lib/src/core/StringBuilder.d.ts +9 -0
- package/lib/src/core/StringBuilder.js +30 -0
- package/lib/src/core/StringBuilder.js.map +1 -0
- package/lib/src/core/StringCharSource.d.ts +11 -0
- package/lib/src/core/StringCharSource.js +60 -0
- package/lib/src/core/StringCharSource.js.map +1 -0
- package/lib/src/core/StringUtil.d.ts +16 -0
- package/lib/src/core/StringUtil.js +75 -0
- package/lib/src/core/StringUtil.js.map +1 -0
- package/lib/src/core/__test__/ClassUtil.spec.d.ts +1 -0
- package/lib/src/core/__test__/ClassUtil.spec.js +16 -0
- package/lib/src/core/__test__/ClassUtil.spec.js.map +1 -0
- package/lib/src/core/__test__/StringCharSource.spec.d.ts +1 -0
- package/lib/src/core/__test__/StringCharSource.spec.js +18 -0
- package/lib/src/core/__test__/StringCharSource.spec.js.map +1 -0
- package/lib/src/core/__test__/StringUtil.spec.d.ts +1 -0
- package/lib/src/core/__test__/StringUtil.spec.js +23 -0
- package/lib/src/core/__test__/StringUtil.spec.js.map +1 -0
- package/lib/src/csv/CSV.spec.d.ts +1 -0
- package/lib/src/csv/CSV.spec.js +45 -0
- package/lib/src/csv/CSV.spec.js.map +1 -0
- package/lib/src/csv/CSVOption.d.ts +12 -0
- package/lib/src/csv/CSVOption.js +23 -0
- package/lib/src/csv/CSVOption.js.map +1 -0
- package/lib/src/csv/CSVParser.d.ts +13 -0
- package/lib/src/csv/CSVParser.js +133 -0
- package/lib/src/csv/CSVParser.js.map +1 -0
- package/lib/src/csv/CSVWriter.d.ts +14 -0
- package/lib/src/csv/CSVWriter.js +77 -0
- package/lib/src/csv/CSVWriter.js.map +1 -0
- package/lib/src/index.d.ts +21 -0
- package/lib/src/index.js +34 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/json/JSONPointer.d.ts +30 -0
- package/lib/src/json/JSONPointer.js +87 -0
- package/lib/src/json/JSONPointer.js.map +1 -0
- package/lib/src/json/NodeFilter.d.ts +25 -0
- package/lib/src/json/NodeFilter.js +115 -0
- package/lib/src/json/NodeFilter.js.map +1 -0
- package/lib/src/json/TDJSONOption.d.ts +26 -0
- package/lib/src/json/TDJSONOption.js +56 -0
- package/lib/src/json/TDJSONOption.js.map +1 -0
- package/lib/src/json/TDJSONParser.d.ts +19 -0
- package/lib/src/json/TDJSONParser.js +233 -0
- package/lib/src/json/TDJSONParser.js.map +1 -0
- package/lib/src/json/TDJSONParserOption.d.ts +24 -0
- package/lib/src/json/TDJSONParserOption.js +50 -0
- package/lib/src/json/TDJSONParserOption.js.map +1 -0
- package/lib/src/json/TDJSONWriter.d.ts +17 -0
- package/lib/src/json/TDJSONWriter.js +143 -0
- package/lib/src/json/TDJSONWriter.js.map +1 -0
- package/lib/src/json/TDJSONWriterOption.d.ts +36 -0
- package/lib/src/json/TDJSONWriterOption.js +88 -0
- package/lib/src/json/TDJSONWriterOption.js.map +1 -0
- package/lib/src/json/__test__/CharSource.spec.d.ts +1 -0
- package/lib/src/json/__test__/CharSource.spec.js +58 -0
- package/lib/src/json/__test__/CharSource.spec.js.map +1 -0
- package/lib/src/json/__test__/JSONPointer.spec.d.ts +1 -0
- package/lib/src/json/__test__/JSONPointer.spec.js +16 -0
- package/lib/src/json/__test__/JSONPointer.spec.js.map +1 -0
- package/lib/src/json/__test__/TDJsonParser.spec.d.ts +1 -0
- package/lib/src/json/__test__/TDJsonParser.spec.js +183 -0
- package/lib/src/json/__test__/TDJsonParser.spec.js.map +1 -0
- package/lib/src/json/__test__/TDJsonWriter.spec.d.ts +1 -0
- package/lib/src/json/__test__/TDJsonWriter.spec.js +71 -0
- package/lib/src/json/__test__/TDJsonWriter.spec.js.map +1 -0
- package/lib/src/json/__test__/TDNode.spec.d.ts +1 -0
- package/lib/src/json/__test__/TDNode.spec.js +17 -0
- package/lib/src/json/__test__/TDNode.spec.js.map +1 -0
- package/lib/src/json/__test__/TestData.d.ts +7 -0
- package/lib/src/json/__test__/TestData.js +15 -0
- package/lib/src/json/__test__/TestData.js.map +1 -0
- package/lib/src/objcoder/CustomCoder.d.ts +7 -0
- package/lib/src/objcoder/CustomCoder.js +27 -0
- package/lib/src/objcoder/CustomCoder.js.map +1 -0
- package/lib/src/objcoder/TDObjectCoder.d.ts +35 -0
- package/lib/src/objcoder/TDObjectCoder.js +141 -0
- package/lib/src/objcoder/TDObjectCoder.js.map +1 -0
- package/lib/vitest.config.d.ts +2 -0
- package/lib/vitest.config.js +10 -0
- package/lib/vitest.config.js.map +1 -0
- package/package.json +10 -12
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
16
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
17
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
18
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
19
|
+
r[k] = a[j];
|
|
20
|
+
return r;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.NodeFilter = void 0;
|
|
24
|
+
var __1 = require("..");
|
|
25
|
+
var ListUtil_1 = require("../core/ListUtil");
|
|
26
|
+
/** if it returns undefined, node will be skipped */
|
|
27
|
+
var NodeFilter = /** @class */ (function () {
|
|
28
|
+
function NodeFilter() {
|
|
29
|
+
}
|
|
30
|
+
NodeFilter.exclude = function () {
|
|
31
|
+
var patterns = [];
|
|
32
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
33
|
+
patterns[_i] = arguments[_i];
|
|
34
|
+
}
|
|
35
|
+
return new (ExcludeFilter.bind.apply(ExcludeFilter, __spreadArrays([void 0], patterns)))();
|
|
36
|
+
};
|
|
37
|
+
NodeFilter.mask = function () {
|
|
38
|
+
var patterns = [];
|
|
39
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
40
|
+
patterns[_i] = arguments[_i];
|
|
41
|
+
}
|
|
42
|
+
return new (MaskFilter.bind.apply(MaskFilter, __spreadArrays([void 0], patterns)))();
|
|
43
|
+
};
|
|
44
|
+
return NodeFilter;
|
|
45
|
+
}());
|
|
46
|
+
exports.NodeFilter = NodeFilter;
|
|
47
|
+
;
|
|
48
|
+
var RegexFilter = /** @class */ (function () {
|
|
49
|
+
function RegexFilter() {
|
|
50
|
+
var strPatterns = [];
|
|
51
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
52
|
+
strPatterns[_i] = arguments[_i];
|
|
53
|
+
}
|
|
54
|
+
this.pathPatterns = [];
|
|
55
|
+
this.addPatterns.apply(this, strPatterns);
|
|
56
|
+
}
|
|
57
|
+
RegexFilter.prototype.apply = function (n) {
|
|
58
|
+
if (!this.matches(n.pathAsString))
|
|
59
|
+
return n;
|
|
60
|
+
return this.transform(n);
|
|
61
|
+
};
|
|
62
|
+
RegexFilter.prototype.addPatterns = function () {
|
|
63
|
+
var patterns = [];
|
|
64
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
65
|
+
patterns[_i] = arguments[_i];
|
|
66
|
+
}
|
|
67
|
+
if (patterns != null)
|
|
68
|
+
for (var _a = 0, patterns_1 = patterns; _a < patterns_1.length; _a++) {
|
|
69
|
+
var ptn = patterns_1[_a];
|
|
70
|
+
this.pathPatterns.push(new RegExp(ptn));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
RegexFilter.prototype.matches = function (path) {
|
|
74
|
+
return ListUtil_1.ListUtil.exists(this.pathPatterns, function (p) { return p.test(path); });
|
|
75
|
+
};
|
|
76
|
+
return RegexFilter;
|
|
77
|
+
}());
|
|
78
|
+
var ExcludeFilter = /** @class */ (function (_super) {
|
|
79
|
+
__extends(ExcludeFilter, _super);
|
|
80
|
+
function ExcludeFilter() {
|
|
81
|
+
var patterns = [];
|
|
82
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
83
|
+
patterns[_i] = arguments[_i];
|
|
84
|
+
}
|
|
85
|
+
return _super.apply(this, patterns) || this;
|
|
86
|
+
}
|
|
87
|
+
ExcludeFilter.prototype.transform = function (n) { return undefined; };
|
|
88
|
+
return ExcludeFilter;
|
|
89
|
+
}(RegexFilter));
|
|
90
|
+
var MaskFilter = /** @class */ (function (_super) {
|
|
91
|
+
__extends(MaskFilter, _super);
|
|
92
|
+
function MaskFilter() {
|
|
93
|
+
var patterns = [];
|
|
94
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
95
|
+
patterns[_i] = arguments[_i];
|
|
96
|
+
}
|
|
97
|
+
return _super.apply(this, patterns) || this;
|
|
98
|
+
}
|
|
99
|
+
MaskFilter.prototype.transform = function (n) {
|
|
100
|
+
if (n.value == null && !n.hasChildren())
|
|
101
|
+
return n;
|
|
102
|
+
return n.cloneOfSimpleType(this.getMaskStr(n));
|
|
103
|
+
};
|
|
104
|
+
MaskFilter.prototype.getMaskStr = function (n) {
|
|
105
|
+
var _a;
|
|
106
|
+
switch (n.type) {
|
|
107
|
+
case __1.TDNodeType.SIMPLE: return "<Masked:len=" + ((_a = n.value) === null || _a === void 0 ? void 0 : _a.toString().length) + ">";
|
|
108
|
+
case __1.TDNodeType.MAP: return "{Masked:size=" + n.getChildrenSize() + "}";
|
|
109
|
+
case __1.TDNodeType.ARRAY: return "[Masked:length=" + n.getChildrenSize() + "]";
|
|
110
|
+
}
|
|
111
|
+
return "[Masked]"; // Shouldn't happen
|
|
112
|
+
};
|
|
113
|
+
return MaskFilter;
|
|
114
|
+
}(RegexFilter));
|
|
115
|
+
//# sourceMappingURL=NodeFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeFilter.js","sourceRoot":"","sources":["../../../src/json/NodeFilter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,wBAAwC;AACxC,6CAA4C;AAE5C,oDAAoD;AACpD;IAAA;IAIA,CAAC;IAFQ,kBAAO,GAAd;QAAe,kBAAqB;aAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;YAArB,6BAAqB;;QAAmB,YAAW,aAAa,YAAb,aAAa,2BAAI,QAAQ,MAAE;IAAC,CAAC;IACxF,eAAI,GAAX;QAAY,kBAAqB;aAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;YAArB,6BAAqB;;QAAgB,YAAW,UAAU,YAAV,UAAU,2BAAI,QAAQ,MAAE;IAAC,CAAC;IACxF,iBAAC;AAAD,CAAC,AAJD,IAIC;AAJqB,gCAAU;AAI/B,CAAC;AAEF;IAGE;QAAmB,qBAAwB;aAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;YAAxB,gCAAwB;;QAF3B,iBAAY,GAAY,EAAE,CAAC;QAEI,IAAI,CAAC,WAAW,OAAhB,IAAI,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AAC,CAAC,WAAW,EAAE;YACrC,OAAO,CAAC,CAAC;QACX,OAAO,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IACO,+BAAU,GAAlB,UAAmB,CAAS;;QAC1B,QAAQ,CAAC,CAAC,IAAI,EAAE;YACd,KAAK,cAAU,CAAC,MAAM,CAAC,CAAC,OAAO,cAAc,UAAG,CAAC,CAAC,KAAK,0CAAE,QAAQ,GAAG,MAAM,CAAA,GAAG,GAAG,CAAC;YACjF,KAAK,cAAU,CAAC,GAAG,CAAC,CAAC,OAAO,eAAe,GAAG,CAAC,CAAC,eAAe,EAAE,GAAG,GAAG,CAAC;YACxE,KAAK,cAAU,CAAC,KAAK,CAAC,CAAC,OAAO,iBAAiB,GAAG,CAAC,CAAC,eAAe,EAAE,GAAG,GAAG,CAAC;SAC7E;QACD,OAAO,UAAU,CAAC,CAAE,mBAAmB;IACzC,CAAC;IACH,iBAAC;AAAD,CAAC,AAfD,CAAyB,WAAW,GAenC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class TDJSONOption {
|
|
2
|
+
KEY_ID: string;
|
|
3
|
+
KEY_TYPE: string;
|
|
4
|
+
deliminatorKey: string;
|
|
5
|
+
deliminatorValue: string;
|
|
6
|
+
deliminatorObjectStart: string;
|
|
7
|
+
deliminatorObjectEnd: string;
|
|
8
|
+
deliminatorArrayStart: string;
|
|
9
|
+
deliminatorArrayEnd: string;
|
|
10
|
+
commentStartChar: string;
|
|
11
|
+
/**
|
|
12
|
+
* QuoteChar can have multiple value. When multiple value is provided, it will dynamically choose the best one
|
|
13
|
+
* to minimize the escape. For example "\"\'", if the string contains a lot of single quote, it will use double quote.
|
|
14
|
+
*/
|
|
15
|
+
quoteChars: string;
|
|
16
|
+
setQuoteChars(quoteChars: string): this;
|
|
17
|
+
_termValue: string;
|
|
18
|
+
_termValueInMap: string;
|
|
19
|
+
_termValueInArray: string;
|
|
20
|
+
_termKey: string;
|
|
21
|
+
/** Quote need if a string contains any chars */
|
|
22
|
+
_quoteNeededChars: string;
|
|
23
|
+
_termValueStrs: string[];
|
|
24
|
+
_termKeyStrs: string[];
|
|
25
|
+
buildTerms(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TDJSONOption = void 0;
|
|
4
|
+
var TDJSONOption = /** @class */ (function () {
|
|
5
|
+
function TDJSONOption() {
|
|
6
|
+
this.KEY_ID = "$id";
|
|
7
|
+
this.KEY_TYPE = "$type";
|
|
8
|
+
this.deliminatorKey = ":";
|
|
9
|
+
this.deliminatorValue = ",";
|
|
10
|
+
this.deliminatorObjectStart = "{";
|
|
11
|
+
this.deliminatorObjectEnd = "}";
|
|
12
|
+
this.deliminatorArrayStart = "[";
|
|
13
|
+
this.deliminatorArrayEnd = "]";
|
|
14
|
+
this.commentStartChar = "/#";
|
|
15
|
+
/**
|
|
16
|
+
* QuoteChar can have multiple value. When multiple value is provided, it will dynamically choose the best one
|
|
17
|
+
* to minimize the escape. For example "\"\'", if the string contains a lot of single quote, it will use double quote.
|
|
18
|
+
*/
|
|
19
|
+
this.quoteChars = '"';
|
|
20
|
+
// Package scopes used by parser
|
|
21
|
+
this._termValue = "";
|
|
22
|
+
this._termValueInMap = "";
|
|
23
|
+
this._termValueInArray = "";
|
|
24
|
+
this._termKey = "";
|
|
25
|
+
/** Quote need if a string contains any chars */
|
|
26
|
+
this._quoteNeededChars = "";
|
|
27
|
+
this._termValueStrs = [];
|
|
28
|
+
this._termKeyStrs = [];
|
|
29
|
+
}
|
|
30
|
+
TDJSONOption.prototype.setQuoteChars = function (quoteChars) { this.quoteChars = quoteChars; return this; };
|
|
31
|
+
TDJSONOption.prototype.buildTerms = function () {
|
|
32
|
+
this._termValue = "\n\r" + this.deliminatorKey + this.deliminatorObjectStart; // support tree with a type in the form of "type{attr1:val1}", key1:key2:type{att1:val1}
|
|
33
|
+
this._termKey = this.deliminatorObjectStart + this.deliminatorObjectEnd + this.deliminatorArrayStart;
|
|
34
|
+
this._termValueStrs = [];
|
|
35
|
+
this._termKeyStrs = [];
|
|
36
|
+
if (this.deliminatorValue.length === 1) { // If more than 1, will use separate string collection as term
|
|
37
|
+
this._termValue += this.deliminatorValue;
|
|
38
|
+
this._termKey += this.deliminatorValue;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this._termValueStrs.push(this.deliminatorValue);
|
|
42
|
+
this._termKeyStrs.push(this.deliminatorValue);
|
|
43
|
+
}
|
|
44
|
+
if (this.deliminatorKey.length === 1)
|
|
45
|
+
this._termKey += this.deliminatorKey;
|
|
46
|
+
else
|
|
47
|
+
this._termKeyStrs.push(this.deliminatorKey);
|
|
48
|
+
this._termValueInMap = this._termValue + this.deliminatorObjectEnd + this.deliminatorArrayEnd; // It's possible object end is omitted for path compression. e.g [a:b:c]
|
|
49
|
+
this._termValueInMap = this._termValue + this.deliminatorObjectEnd;
|
|
50
|
+
this._termValueInArray = this._termValue + this.deliminatorArrayEnd;
|
|
51
|
+
this._quoteNeededChars = this._termValue + this._termKey + this.deliminatorObjectEnd + this.deliminatorObjectEnd + this.deliminatorArrayEnd + this.deliminatorKey + this.deliminatorValue + this.quoteChars + this.commentStartChar;
|
|
52
|
+
};
|
|
53
|
+
return TDJSONOption;
|
|
54
|
+
}());
|
|
55
|
+
exports.TDJSONOption = TDJSONOption;
|
|
56
|
+
//# sourceMappingURL=TDJSONOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TDJSONOption.js","sourceRoot":"","sources":["../../../src/json/TDJSONOption.ts"],"names":[],"mappings":";;;AAEA;IAAA;QACE,WAAM,GAAG,KAAK,CAAC;QACf,aAAQ,GAAG,OAAO,CAAC;QACnB,mBAAc,GAAG,GAAG,CAAC;QACrB,qBAAgB,GAAG,GAAG,CAAC;QACvB,2BAAs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BAAgB,CAAC,CAAC;SAC/C;QACD,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;YAClC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,cAAc,CAAC;;YAErC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAE9C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC,wEAAwE;QACvK,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAC;QACnE,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACpE,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC;IACtO,CAAC;IACL,mBAAC;AAAD,CAAC,AAlDD,IAkDC;AAlDY,oCAAY"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TDNode } from '../TDNode';
|
|
2
|
+
import { TDJSONParserOption } from './TDJSONParserOption';
|
|
3
|
+
import { CharSource } from '../core/CharSource';
|
|
4
|
+
import { RecursivePartial } from '../core/LangUtil';
|
|
5
|
+
export declare class TDJSONParser {
|
|
6
|
+
static readonly instance: TDJSONParser;
|
|
7
|
+
static get(): TDJSONParser;
|
|
8
|
+
/** Parse all the JSON objects in the input stream until EOF and store them inside an root node with array type */
|
|
9
|
+
parseAll(src: CharSource | string, option?: RecursivePartial<TDJSONParserOption>, node?: TDNode, isRoot?: boolean): TDNode;
|
|
10
|
+
private contains;
|
|
11
|
+
parse(src: CharSource | string, option?: RecursivePartial<TDJSONParserOption>, node?: TDNode, isRoot?: boolean): TDNode;
|
|
12
|
+
private readContinuousString;
|
|
13
|
+
/**
|
|
14
|
+
* @return char next char to read (peeked), if '\uFFFF' indicate it's EOF
|
|
15
|
+
*/
|
|
16
|
+
static skipSpaceAndComments(src: CharSource): string;
|
|
17
|
+
parseMap(src: CharSource, opt: TDJSONParserOption, node: TDNode, withStartBracket: boolean): TDNode;
|
|
18
|
+
private parseArray;
|
|
19
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TDJSONParser = void 0;
|
|
4
|
+
var TDNode_1 = require("../TDNode");
|
|
5
|
+
var TDJSONParserOption_1 = require("./TDJSONParserOption");
|
|
6
|
+
var EOFRuntimeException_1 = require("../core/EOFRuntimeException");
|
|
7
|
+
var ParseRuntimeException_1 = require("../core/ParseRuntimeException");
|
|
8
|
+
var StringCharSource_1 = require("../core/StringCharSource");
|
|
9
|
+
var StringBuilder_1 = require("../core/StringBuilder");
|
|
10
|
+
var TreeDoc_1 = require("../TreeDoc");
|
|
11
|
+
var ClassUtil_1 = require("../core/ClassUtil");
|
|
12
|
+
var __1 = require("..");
|
|
13
|
+
var EOF = '\uFFFF';
|
|
14
|
+
var TDJSONParser = /** @class */ (function () {
|
|
15
|
+
function TDJSONParser() {
|
|
16
|
+
}
|
|
17
|
+
TDJSONParser.get = function () {
|
|
18
|
+
return TDJSONParser.instance;
|
|
19
|
+
};
|
|
20
|
+
/** Parse all the JSON objects in the input stream until EOF and store them inside an root node with array type */
|
|
21
|
+
TDJSONParser.prototype.parseAll = function (src, option, node, isRoot) {
|
|
22
|
+
if (option === void 0) { option = new TDJSONParserOption_1.TDJSONParserOption(); }
|
|
23
|
+
if (node === void 0) { node = new TreeDoc_1.TreeDoc('root', option.uri).root; }
|
|
24
|
+
if (isRoot === void 0) { isRoot = true; }
|
|
25
|
+
var opt = option instanceof TDJSONParserOption_1.TDJSONParserOption ? option : __1.LangUtil.mergeDeep(new TDJSONParserOption_1.TDJSONParserOption(), option);
|
|
26
|
+
opt.setDefaultRootType(TDNode_1.TDNodeType.MAP);
|
|
27
|
+
if (typeof src === 'string')
|
|
28
|
+
src = new StringCharSource_1.StringCharSource(src);
|
|
29
|
+
var doc = TreeDoc_1.TreeDoc.ofArray();
|
|
30
|
+
var docId = 0;
|
|
31
|
+
while (src.skipSpacesAndReturnsAndCommas())
|
|
32
|
+
TDJSONParser.get().parse(src, opt.setDocId(docId++), doc.root.createChild());
|
|
33
|
+
return doc.root;
|
|
34
|
+
};
|
|
35
|
+
TDJSONParser.prototype.contains = function (str, c) {
|
|
36
|
+
return str.indexOf(c) >= 0;
|
|
37
|
+
};
|
|
38
|
+
TDJSONParser.prototype.parse = function (src, option, node, isRoot) {
|
|
39
|
+
if (option === void 0) { option = new TDJSONParserOption_1.TDJSONParserOption(); }
|
|
40
|
+
if (node === void 0) { node = new TreeDoc_1.TreeDoc('root', option.uri).root; }
|
|
41
|
+
if (isRoot === void 0) { isRoot = true; }
|
|
42
|
+
var opt = option instanceof TDJSONParserOption_1.TDJSONParserOption ? option : __1.LangUtil.mergeDeep(new TDJSONParserOption_1.TDJSONParserOption(), option);
|
|
43
|
+
opt.buildTerms();
|
|
44
|
+
if (typeof src === 'string')
|
|
45
|
+
src = new StringCharSource_1.StringCharSource(src);
|
|
46
|
+
var c = TDJSONParser.skipSpaceAndComments(src);
|
|
47
|
+
if (c === EOF)
|
|
48
|
+
return node;
|
|
49
|
+
try {
|
|
50
|
+
node.start = src.getBookmark();
|
|
51
|
+
if (this.contains(opt.deliminatorObjectStart, c))
|
|
52
|
+
return this.parseMap(src, opt, node, true);
|
|
53
|
+
if (this.contains(opt.deliminatorArrayStart, c))
|
|
54
|
+
return this.parseArray(src, opt, node, true);
|
|
55
|
+
if (node.isRoot() && opt.defaultRootType !== undefined) {
|
|
56
|
+
switch (opt.defaultRootType) {
|
|
57
|
+
case TDNode_1.TDNodeType.MAP:
|
|
58
|
+
return this.parseMap(src, opt, node, false);
|
|
59
|
+
case TDNode_1.TDNodeType.ARRAY:
|
|
60
|
+
return this.parseArray(src, opt, node, false);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (c === '"' || c === "'" || c === '`') {
|
|
64
|
+
src.read();
|
|
65
|
+
var sb = new StringBuilder_1.StringBuilder();
|
|
66
|
+
try {
|
|
67
|
+
src.readQuotedToString(sb, c);
|
|
68
|
+
this.readContinuousString(src, sb);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (EOFRuntimeException_1.EOFRuntimeException.is(e) || ParseRuntimeException_1.ParseRuntimeException.is(e))
|
|
72
|
+
throw src.createParseRuntimeException("Error read quoted string", node.setValue(sb.toString()), e);
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
return node.setValue(sb.toString());
|
|
76
|
+
}
|
|
77
|
+
if (isRoot && opt.defaultRootType === TDNode_1.TDNodeType.SIMPLE) {
|
|
78
|
+
return node.setValue(ClassUtil_1.ClassUtil.toSimpleObject(src.readUntilTerminator("\r\n")));
|
|
79
|
+
}
|
|
80
|
+
var term = opt._termValue;
|
|
81
|
+
if (node.parent != null)
|
|
82
|
+
// parent.type can either be ARRAY or MAP.
|
|
83
|
+
term = node.parent.type === TDNode_1.TDNodeType.ARRAY ? opt._termValueInArray : opt._termValueInMap;
|
|
84
|
+
var str = src.readUntilTerminator(term, opt._termValueStrs).trim();
|
|
85
|
+
if (!src.isEof() && this.contains(opt.deliminatorKey, src.peek())) { // it's a path compression such as: a:b:c,d:e -> {a: {b: c}}
|
|
86
|
+
src.skip();
|
|
87
|
+
node.setType(TDNode_1.TDNodeType.MAP);
|
|
88
|
+
this.parse(src, opt, node.createChild(str), false);
|
|
89
|
+
return node;
|
|
90
|
+
}
|
|
91
|
+
if (!src.isEof() && this.contains(opt.deliminatorObjectStart, src.peek())) {
|
|
92
|
+
// Type wrapper: A value with type in the form of `type{attr1:val1:attr2:val2}
|
|
93
|
+
node.createChild(opt.KEY_TYPE).setValue(str);
|
|
94
|
+
return this.parseMap(src, opt, node, true);
|
|
95
|
+
}
|
|
96
|
+
// A simple value
|
|
97
|
+
node.setValue(ClassUtil_1.ClassUtil.toSimpleObject(str));
|
|
98
|
+
return node;
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
node.end = src.getBookmark();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
TDJSONParser.prototype.readContinuousString = function (src, sb) {
|
|
105
|
+
var c;
|
|
106
|
+
while ((c = TDJSONParser.skipSpaceAndComments(src)) !== EOF) {
|
|
107
|
+
if ('"`\''.indexOf(c) < 0)
|
|
108
|
+
break;
|
|
109
|
+
src.read();
|
|
110
|
+
src.readQuotedToString(sb, c);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* @return char next char to read (peeked), if '\uFFFF' indicate it's EOF
|
|
115
|
+
*/
|
|
116
|
+
TDJSONParser.skipSpaceAndComments = function (src) {
|
|
117
|
+
while (src.skipSpacesAndReturns()) {
|
|
118
|
+
var c = src.peek();
|
|
119
|
+
if (c === '#') {
|
|
120
|
+
if (src.skipUntilTerminator('\n'))
|
|
121
|
+
src.skip(1);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (c !== '/' || src.isEof(1))
|
|
125
|
+
return c;
|
|
126
|
+
var c1 = src.peek(1);
|
|
127
|
+
switch (c1) {
|
|
128
|
+
case '/': // line comments
|
|
129
|
+
if (src.skipUntilTerminator('\n'))
|
|
130
|
+
src.skip(1);
|
|
131
|
+
break;
|
|
132
|
+
case '*': // block comments
|
|
133
|
+
src.skip(2);
|
|
134
|
+
src.skipUntilMatch('*/', true);
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
return c1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return EOF;
|
|
141
|
+
};
|
|
142
|
+
TDJSONParser.prototype.parseMap = function (src, opt, node, withStartBracket) {
|
|
143
|
+
node.type = TDNode_1.TDNodeType.MAP;
|
|
144
|
+
if (withStartBracket)
|
|
145
|
+
src.skip();
|
|
146
|
+
for (var i = 0;;) {
|
|
147
|
+
var c = TDJSONParser.skipSpaceAndComments(src);
|
|
148
|
+
if (c === EOF) {
|
|
149
|
+
if (withStartBracket)
|
|
150
|
+
throw src.createParseRuntimeException("EOF while expecting matching '}' with '{' at " + node.start, node);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
if (this.contains(opt.deliminatorObjectEnd, c)) {
|
|
154
|
+
src.skip();
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (src.startsWith(opt.deliminatorValue)) { // Skip ,
|
|
158
|
+
src.skip(opt.deliminatorValue.length);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
var key = void 0;
|
|
162
|
+
if (c === '"' || c === "'" || c === '`') {
|
|
163
|
+
src.skip();
|
|
164
|
+
key = src.readQuotedString(c);
|
|
165
|
+
c = TDJSONParser.skipSpaceAndComments(src);
|
|
166
|
+
// if (c === EOF)
|
|
167
|
+
// break;
|
|
168
|
+
// if (c == EOF)
|
|
169
|
+
// break;
|
|
170
|
+
if (!src.startsWith(opt.deliminatorKey)
|
|
171
|
+
&& !this.contains(opt.deliminatorObjectStart, c)
|
|
172
|
+
&& !this.contains(opt.deliminatorArrayStart, c)
|
|
173
|
+
&& !this.contains(opt.deliminatorValue, c)
|
|
174
|
+
&& !this.contains(opt.deliminatorObjectEnd, c))
|
|
175
|
+
throw src.createParseRuntimeException("No '" + opt.deliminatorKey + "' after key:" + key, node);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
key = src.readUntilTerminator(opt._termKey, opt._termKeyStrs, 1, Number.MAX_VALUE).trim();
|
|
179
|
+
if (src.isEof())
|
|
180
|
+
throw src.createParseRuntimeException("No '" + opt.deliminatorKey + "' after key:" + key, node);
|
|
181
|
+
c = src.peek();
|
|
182
|
+
}
|
|
183
|
+
if (src.startsWith(opt.deliminatorKey))
|
|
184
|
+
src.skip(opt.deliminatorKey.length);
|
|
185
|
+
if (src.startsWith(opt.deliminatorValue) || this.contains(opt.deliminatorObjectEnd, c)) // If there's no ':', we consider it as indexed value (array)
|
|
186
|
+
node.createChild(i + '').setValue(key);
|
|
187
|
+
else {
|
|
188
|
+
var childNode = this.parse(src, opt, node.createChild(key), false);
|
|
189
|
+
if (opt.KEY_ID === key && childNode.type === TDNode_1.TDNodeType.SIMPLE) {
|
|
190
|
+
var id = childNode.value + '';
|
|
191
|
+
if (opt.docId !== undefined) {
|
|
192
|
+
id += "_" + opt.docId;
|
|
193
|
+
childNode.value = id;
|
|
194
|
+
}
|
|
195
|
+
node.doc.idMap[id] = node;
|
|
196
|
+
}
|
|
197
|
+
else if (TDNode_1.TDNode.REF_KEY === key && childNode.type === TDNode_1.TDNodeType.SIMPLE) {
|
|
198
|
+
if (opt.docId !== undefined)
|
|
199
|
+
childNode.value += "_" + opt.docId;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
i++;
|
|
203
|
+
}
|
|
204
|
+
return node;
|
|
205
|
+
};
|
|
206
|
+
TDJSONParser.prototype.parseArray = function (src, opt, node, withStartBracket) {
|
|
207
|
+
node.type = TDNode_1.TDNodeType.ARRAY;
|
|
208
|
+
if (withStartBracket)
|
|
209
|
+
src.skip();
|
|
210
|
+
while (true) {
|
|
211
|
+
var c = TDJSONParser.skipSpaceAndComments(src);
|
|
212
|
+
if (c === EOF) {
|
|
213
|
+
if (withStartBracket)
|
|
214
|
+
throw src.createParseRuntimeException("EOF while expecting matching ']' with '[' at " + node.start, node);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (this.contains(opt.deliminatorArrayEnd, c)) {
|
|
218
|
+
src.skip();
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
this.parse(src, opt, node.createChild(), false);
|
|
222
|
+
c = TDJSONParser.skipSpaceAndComments(src);
|
|
223
|
+
if (src.startsWith(opt.deliminatorValue)) {
|
|
224
|
+
src.skip(opt.deliminatorValue.length);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return node;
|
|
228
|
+
};
|
|
229
|
+
TDJSONParser.instance = new TDJSONParser();
|
|
230
|
+
return TDJSONParser;
|
|
231
|
+
}());
|
|
232
|
+
exports.TDJSONParser = TDJSONParser;
|
|
233
|
+
//# sourceMappingURL=TDJSONParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TDJSONParser.js","sourceRoot":"","sources":["../../../src/json/TDJSONParser.ts"],"names":[],"mappings":";;;AAAA,oCAA+C;AAC/C,2DAA0D;AAE1D,mEAAkE;AAClE,uEAAsE;AACtE,6DAA4D;AAC5D,uDAAsD;AACtD,sCAAqC;AACrC,+CAA8C;AAE9C,wBAA8B;AAE9B,IAAM,GAAG,GAAG,QAAQ,CAAC;AAErB;IAAA;IA6OA,CAAC;IA3Oe,gBAAG,GAAjB;QACE,OAAO,YAAY,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAED,kHAAkH;IAC3G,+BAAQ,GAAf,UAAgB,GAAwB,EACpC,MAAuE,EACvE,IAA2C,EAAE,MAAa;QAD1D,uBAAA,EAAA,aAAmD,uCAAkB,EAAE;QACvE,qBAAA,EAAA,OAAO,IAAI,iBAAO,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI;QAAE,uBAAA,EAAA,aAAa;QAC5D,IAAM,GAAG,GAAG,MAAM,YAAY,uCAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAQ,CAAC,SAAS,CAAC,IAAI,uCAAkB,EAAE,EAAE,MAAM,CAAC,CAAC;QACjH,GAAG,CAAC,kBAAkB,CAAC,mBAAU,CAAC,GAAG,CAAC,CAAC;QAEvC,IAAI,OAAO,GAAG,KAAK,QAAQ;YACzB,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IAAI,GAAG,mBAAU,CAAC,KAAK,CAAC;QAC7B,IAAI,gBAAgB;YAClB,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,OAAO,IAAI,EAAE;YACX,IAAI,CAAC,GAAG,YAAY,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,GAAG,EAAE;gBACb,IAAI,gBAAgB;oBAClB,MAAM,GAAG,CAAC,2BAA2B,CAAC,+CAA+C,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAC5G,MAAM;aACP;YAED,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE;gBAC7C,GAAG,CAAC,IAAI,EAAE,CAAC;gBACX,MAAM;aACP;YAED,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;YAChD,CAAC,GAAG,YAAY,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;YAC3C,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE;gBACxC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;aACvC;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IA3OsB,qBAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IA4OvD,mBAAC;CAAA,AA7OD,IA6OC;AA7OY,oCAAY"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TDNodeType } from '../TDNode';
|
|
2
|
+
import { TDJSONOption } from './TDJSONOption';
|
|
3
|
+
export declare class TDJSONParserOption extends TDJSONOption {
|
|
4
|
+
static ofDefaultRootType(type: TDNodeType): TDJSONParserOption;
|
|
5
|
+
static ofMapToString(): TDJSONParserOption;
|
|
6
|
+
uri?: string;
|
|
7
|
+
/**
|
|
8
|
+
* In case there's no enclosed '[' of '{' on the root level, the default type.
|
|
9
|
+
* By default, it will try to interpreter as a single value (either map, if there's ":", or a simple value.)
|
|
10
|
+
*/
|
|
11
|
+
defaultRootType: TDNodeType | undefined;
|
|
12
|
+
constructor();
|
|
13
|
+
setDefaultRootType(type: TDNodeType): this;
|
|
14
|
+
/**
|
|
15
|
+
* if this is set, all the id in $id and $ref will be suffixed with "_" + docId, this is to avoid collision when merge
|
|
16
|
+
* multiple docs as stream
|
|
17
|
+
*/
|
|
18
|
+
docId?: string | number;
|
|
19
|
+
setDocId(id: string | number): this;
|
|
20
|
+
setDeliminatorKey(val: string): TDJSONParserOption;
|
|
21
|
+
setDeliminatorValue(val: string): TDJSONParserOption;
|
|
22
|
+
setDeliminatorObject(start: string, end: string): TDJSONParserOption;
|
|
23
|
+
setDeliminatorArray(start: string, end: string): TDJSONParserOption;
|
|
24
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TDJSONParserOption = void 0;
|
|
17
|
+
var TDJSONOption_1 = require("./TDJSONOption");
|
|
18
|
+
var TDJSONParserOption = /** @class */ (function (_super) {
|
|
19
|
+
__extends(TDJSONParserOption, _super);
|
|
20
|
+
function TDJSONParserOption() {
|
|
21
|
+
var _this = _super.call(this) || this;
|
|
22
|
+
_this.buildTerms();
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
TDJSONParserOption.ofDefaultRootType = function (type) { return new TDJSONParserOption().setDefaultRootType(type); };
|
|
26
|
+
TDJSONParserOption.ofMapToString = function () { return new TDJSONParserOption().setDeliminatorKey("=").setDeliminatorValue(", "); };
|
|
27
|
+
TDJSONParserOption.prototype.setDefaultRootType = function (type) {
|
|
28
|
+
this.defaultRootType = type;
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
TDJSONParserOption.prototype.setDocId = function (id) {
|
|
32
|
+
this.docId = id;
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
TDJSONParserOption.prototype.setDeliminatorKey = function (val) { this.deliminatorKey = val; return this; };
|
|
36
|
+
TDJSONParserOption.prototype.setDeliminatorValue = function (val) { this.deliminatorValue = val; return this; };
|
|
37
|
+
TDJSONParserOption.prototype.setDeliminatorObject = function (start, end) {
|
|
38
|
+
this.deliminatorObjectStart = start;
|
|
39
|
+
this.deliminatorObjectEnd = end;
|
|
40
|
+
return this;
|
|
41
|
+
};
|
|
42
|
+
TDJSONParserOption.prototype.setDeliminatorArray = function (start, end) {
|
|
43
|
+
this.deliminatorArrayStart = start;
|
|
44
|
+
this.deliminatorArrayEnd = end;
|
|
45
|
+
return this;
|
|
46
|
+
};
|
|
47
|
+
return TDJSONParserOption;
|
|
48
|
+
}(TDJSONOption_1.TDJSONOption));
|
|
49
|
+
exports.TDJSONParserOption = TDJSONParserOption;
|
|
50
|
+
//# sourceMappingURL=TDJSONParserOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TDJSONParserOption.js","sourceRoot":"","sources":["../../../src/json/TDJSONParserOption.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,+CAA8C;AAE9C;IAAwC,sCAAY;IAYlD;QAAA,YAAgB,iBAAO,SAAsB;Q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Option } from './TDJSONWriterOption';
|
|
2
|
+
import { TDNode } from '../TDNode';
|
|
3
|
+
import { Appendable } from '../core/Appendable';
|
|
4
|
+
export declare class TDJSONWriter {
|
|
5
|
+
static readonly instance: TDJSONWriter;
|
|
6
|
+
static get(): TDJSONWriter;
|
|
7
|
+
static writeAsString(node: TDNode, opt?: Partial<TDJSONWriterOption>): string;
|
|
8
|
+
static write(out: Appendable, node: TDNode, opt?: Partial<TDJSONWriterOption>, indentStr?: string): Appendable;
|
|
9
|
+
writeAsString(node: TDNode, opt?: Partial<TDJSONWriterOption>): string;
|
|
10
|
+
write(out: Appendable, node: TDNode, option?: Partial<TDJSONWriterOption>, indentStr?: string): Appendable;
|
|
11
|
+
private writeMap;
|
|
12
|
+
private writeArray;
|
|
13
|
+
private writeSimple;
|
|
14
|
+
private writeQuotedString;
|
|
15
|
+
/** return '' indicate quote is not necessary */
|
|
16
|
+
private determineQuoteChar;
|
|
17
|
+
}
|