@pbkware/fielded-text-web 0.1.2 → 0.2.2
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/README.md +20 -42
- package/dist/api/ft-reader.js +1 -1
- package/dist/api/ft-reader.js.map +1 -1
- package/dist/api/ft-serialization.js +4 -4
- package/dist/api/ft-serialization.js.map +1 -1
- package/dist/factory/ft-field-factory.js +1 -1
- package/dist/factory/ft-field-factory.js.map +1 -1
- package/dist/factory/ft-sequence-redirect-factory.js +3 -3
- package/dist/factory/ft-sequence-redirect-factory.js.map +1 -1
- package/dist/fields/definitions/ft-boolean-field-definition.js +1 -1
- package/dist/fields/definitions/ft-boolean-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-date-time-field-definition.js +1 -1
- package/dist/fields/definitions/ft-date-time-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-decimal-field-definition.js +1 -1
- package/dist/fields/definitions/ft-decimal-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-field-definition.js +1 -1
- package/dist/fields/definitions/ft-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-float-field-definition.js +1 -1
- package/dist/fields/definitions/ft-float-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-integer-field-definition.js +1 -1
- package/dist/fields/definitions/ft-integer-field-definition.js.map +1 -1
- package/dist/fields/definitions/ft-string-field-definition.js +1 -1
- package/dist/fields/definitions/ft-string-field-definition.js.map +1 -1
- package/dist/fields/instances/errors/ft-field-null-error.js +11 -0
- package/dist/fields/instances/errors/ft-field-null-error.js.map +1 -0
- package/dist/fields/instances/errors/ft-field-type-error.js +11 -0
- package/dist/fields/instances/errors/ft-field-type-error.js.map +1 -0
- package/dist/fields/instances/ft-boolean-field.js +14 -6
- package/dist/fields/instances/ft-boolean-field.js.map +1 -1
- package/dist/fields/instances/ft-date-time-field.js +26 -8
- package/dist/fields/instances/ft-date-time-field.js.map +1 -1
- package/dist/fields/instances/ft-decimal-field.js +14 -6
- package/dist/fields/instances/ft-decimal-field.js.map +1 -1
- package/dist/fields/instances/ft-field.js +315 -123
- package/dist/fields/instances/ft-field.js.map +1 -1
- package/dist/fields/instances/ft-float-field.js +14 -6
- package/dist/fields/instances/ft-float-field.js.map +1 -1
- package/dist/fields/instances/ft-generic-field.js +29 -67
- package/dist/fields/instances/ft-generic-field.js.map +1 -1
- package/dist/fields/instances/ft-integer-field.js +24 -8
- package/dist/fields/instances/ft-integer-field.js.map +1 -1
- package/dist/fields/instances/ft-string-field.js +13 -13
- package/dist/fields/instances/ft-string-field.js.map +1 -1
- package/dist/index.d.ts +616 -288
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/meta/sequences/core/ft-meta-sequence-list.js +4 -2
- package/dist/meta/sequences/core/ft-meta-sequence-list.js.map +1 -1
- package/dist/meta/sequences/redirects/ft-meta-sequence-redirect-list.js +1 -1
- package/dist/meta/sequences/redirects/ft-meta-sequence-redirect-list.js.map +1 -1
- package/dist/meta-serialization/format/ft-xml-meta-serialization.js +4 -6
- package/dist/meta-serialization/format/ft-xml-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/styles/ft-number-styles-meta-serialization.js +1 -1
- package/dist/meta-serialization/styles/ft-number-styles-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/types/date-time-meta-serialization.js +1 -1
- package/dist/meta-serialization/types/date-time-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.js +1 -1
- package/dist/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.js.map +1 -1
- package/dist/meta-serialization/types/float-meta-serialization.js +2 -2
- package/dist/meta-serialization/types/float-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/types/integer-float-meta-serialization.js +2 -2
- package/dist/meta-serialization/types/integer-float-meta-serialization.js.map +1 -1
- package/dist/meta-serialization/utils/implicit-explicit-index-sorter.js +4 -10
- package/dist/meta-serialization/utils/implicit-explicit-index-sorter.js.map +1 -1
- package/dist/meta-serialization/utils/meta-serialization-sequence-name-resolver.js +25 -2
- package/dist/meta-serialization/utils/meta-serialization-sequence-name-resolver.js.map +1 -1
- package/dist/meta-serialization/utils/sequence-item-field-indices.js +2 -2
- package/dist/meta-serialization/utils/sequence-item-field-indices.js.map +1 -1
- package/dist/sequences/redirects/ft-case-insensitive-string-sequence-redirect.js +3 -1
- package/dist/sequences/redirects/ft-case-insensitive-string-sequence-redirect.js.map +1 -1
- package/dist/serialization/char-reader.js +2 -2
- package/dist/serialization/char-reader.js.map +1 -1
- package/dist/serialization/declaration-parser.js +1 -1
- package/dist/serialization/declaration-parser.js.map +1 -1
- package/dist/serialization/delimited-field-parser.js.map +1 -1
- package/dist/serialization/events/ft-field-heading-ready-event-args.js.map +1 -0
- package/dist/serialization/events/ft-field-value-ready-event-args.js.map +1 -0
- package/dist/serialization/events/ft-heading-line-finished-event-args.js.map +1 -0
- package/dist/serialization/events/ft-heading-line-started-event-args.js.map +1 -0
- package/dist/serialization/events/ft-record-finished-event-args.js.map +1 -0
- package/dist/serialization/events/ft-record-started-event-args.js.map +1 -0
- package/dist/serialization/events/ft-sequence-redirected-event-args.js.map +1 -0
- package/dist/serialization/fixed-width-field-parser.js +1 -1
- package/dist/serialization/fixed-width-field-parser.js.map +1 -1
- package/dist/serialization/ft-declared-parameters.js +9 -8
- package/dist/serialization/ft-declared-parameters.js.map +1 -1
- package/dist/serialization/{serialization-core.js → ft-serialization-core.js} +114 -11
- package/dist/serialization/ft-serialization-core.js.map +1 -0
- package/dist/{types/errors/ft-serialization-error.js → serialization/ft-serialization-error-code.js} +2 -2
- package/dist/serialization/ft-serialization-error-code.js.map +1 -0
- package/dist/{types/errors/ft-serialization-exception.js → serialization/ft-serialization-error.js} +7 -7
- package/dist/serialization/ft-serialization-error.js.map +1 -0
- package/dist/serialization/ft-serialization-reader.js +19 -47
- package/dist/serialization/ft-serialization-reader.js.map +1 -1
- package/dist/serialization/ft-serialization-writer.js +86 -49
- package/dist/serialization/ft-serialization-writer.js.map +1 -1
- package/dist/serialization/heading-line-record-parser.js +7 -7
- package/dist/serialization/heading-line-record-parser.js.map +1 -1
- package/dist/serialization/line-parser.js +1 -1
- package/dist/serialization/line-parser.js.map +1 -1
- package/dist/serialization/{ft-text-reader.js → text-reader/ft-string-reader.js} +1 -13
- package/dist/serialization/text-reader/ft-string-reader.js.map +1 -0
- package/dist/serialization/text-reader/ft-text-reader.js +13 -0
- package/dist/serialization/text-reader/ft-text-reader.js.map +1 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/enums/ft-heading-constraint.js +5 -0
- package/dist/types/enums/ft-heading-constraint.js.map +1 -1
- package/dist/utils/ft-comma-text.js +247 -0
- package/dist/utils/ft-comma-text.js.map +1 -0
- package/dist/utils/ft-internal-error.js +129 -0
- package/dist/utils/ft-internal-error.js.map +1 -0
- package/dist/utils/ft-result.js +2 -0
- package/dist/utils/ft-result.js.map +1 -0
- package/dist/utils/number-parse.js +33 -0
- package/dist/utils/number-parse.js.map +1 -0
- package/dist/utils/string-builder.js +40 -0
- package/dist/utils/string-builder.js.map +1 -0
- package/package.json +25 -27
- package/src/api/ft-reader.ts +2 -1
- package/src/api/ft-serialization.ts +13 -13
- package/src/factory/ft-field-factory.ts +1 -1
- package/src/factory/ft-sequence-redirect-factory.ts +4 -4
- package/src/fields/definitions/ft-boolean-field-definition.ts +1 -1
- package/src/fields/definitions/ft-date-time-field-definition.ts +1 -1
- package/src/fields/definitions/ft-decimal-field-definition.ts +1 -1
- package/src/fields/definitions/ft-field-definition.ts +1 -1
- package/src/fields/definitions/ft-float-field-definition.ts +1 -1
- package/src/fields/definitions/ft-generic-field-definition.ts +1 -1
- package/src/fields/definitions/ft-integer-field-definition.ts +1 -1
- package/src/fields/definitions/ft-string-field-definition.ts +1 -1
- package/src/fields/instances/errors/ft-field-null-error.ts +10 -0
- package/src/fields/instances/errors/ft-field-type-error.ts +10 -0
- package/src/fields/instances/ft-boolean-field.ts +17 -6
- package/src/fields/instances/ft-date-time-field.ts +28 -7
- package/src/fields/instances/ft-decimal-field.ts +17 -6
- package/src/fields/instances/ft-field.ts +329 -145
- package/src/fields/instances/ft-float-field.ts +17 -6
- package/src/fields/instances/ft-generic-field.ts +32 -88
- package/src/fields/instances/ft-integer-field.ts +29 -7
- package/src/fields/instances/ft-string-field.ts +15 -12
- package/src/index.ts +21 -12
- package/src/meta/sequences/core/ft-meta-sequence-list.ts +4 -3
- package/src/meta/sequences/redirects/ft-meta-sequence-redirect-list.ts +1 -1
- package/src/meta-serialization/format/ft-xml-meta-serialization.ts +4 -7
- package/src/meta-serialization/styles/ft-number-styles-meta-serialization.ts +1 -1
- package/src/meta-serialization/types/date-time-meta-serialization.ts +1 -1
- package/src/meta-serialization/types/enums/meta-element-type-meta-serialization.ts +4 -4
- package/src/meta-serialization/types/enums/sequence-redirect-type-meta-serialisation.ts +1 -1
- package/src/meta-serialization/types/float-meta-serialization.ts +2 -2
- package/src/meta-serialization/types/integer-float-meta-serialization.ts +2 -2
- package/src/meta-serialization/utils/implicit-explicit-index-sorter.ts +18 -12
- package/src/meta-serialization/utils/meta-serialization-sequence-name-resolver.ts +25 -2
- package/src/meta-serialization/utils/sequence-item-field-indices.ts +2 -2
- package/src/sequences/redirects/ft-case-insensitive-string-sequence-redirect.ts +3 -1
- package/src/serialization/char-reader.ts +2 -2
- package/src/serialization/declaration-parser.ts +1 -1
- package/src/serialization/delimited-field-parser.ts +3 -3
- package/src/serialization/fixed-width-field-parser.ts +4 -4
- package/src/serialization/ft-declared-parameters.ts +12 -11
- package/src/serialization/{serialization-core.ts → ft-serialization-core.ts} +133 -17
- package/src/{types/errors/ft-serialization-error.ts → serialization/ft-serialization-error-code.ts} +2 -2
- package/src/{types/errors/ft-serialization-exception.ts → serialization/ft-serialization-error.ts} +14 -9
- package/src/serialization/ft-serialization-reader.ts +21 -54
- package/src/serialization/ft-serialization-writer.ts +97 -64
- package/src/serialization/heading-line-record-parser.ts +10 -10
- package/src/serialization/line-parser.ts +1 -1
- package/src/serialization/{ft-text-reader.ts → text-reader/ft-string-reader.ts} +1 -24
- package/src/serialization/text-reader/ft-text-reader.ts +24 -0
- package/src/types/enums/ft-heading-constraint.ts +5 -0
- package/src/utils/ft-comma-text.ts +285 -0
- package/src/utils/ft-internal-error.ts +143 -0
- package/src/utils/ft-result.ts +1 -0
- package/src/utils/number-parse.ts +35 -0
- package/src/utils/string-builder.ts +47 -0
- package/LICENSE +0 -21
- package/dist/serialization/ft-text-reader.js.map +0 -1
- package/dist/serialization/serialization-core.js.map +0 -1
- package/dist/types/errors/ft-internal-error.js +0 -14
- package/dist/types/errors/ft-internal-error.js.map +0 -1
- package/dist/types/errors/ft-serialization-error.js.map +0 -1
- package/dist/types/errors/ft-serialization-exception.js.map +0 -1
- package/dist/types/events/ft-field-heading-ready-event-args.js.map +0 -1
- package/dist/types/events/ft-field-value-ready-event-args.js.map +0 -1
- package/dist/types/events/ft-heading-line-finished-event-args.js.map +0 -1
- package/dist/types/events/ft-heading-line-started-event-args.js.map +0 -1
- package/dist/types/events/ft-record-finished-event-args.js.map +0 -1
- package/dist/types/events/ft-record-started-event-args.js.map +0 -1
- package/dist/types/events/ft-sequence-redirected-event-args.js.map +0 -1
- package/src/types/errors/ft-internal-error.ts +0 -15
- /package/dist/{types → serialization}/events/ft-field-heading-ready-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-field-value-ready-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-heading-line-finished-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-heading-line-started-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-record-finished-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-record-started-event-args.js +0 -0
- /package/dist/{types → serialization}/events/ft-sequence-redirected-event-args.js +0 -0
- /package/src/{types → serialization}/events/ft-field-heading-ready-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-field-value-ready-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-heading-line-finished-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-heading-line-started-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-record-finished-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-record-started-event-args.ts +0 -0
- /package/src/{types → serialization}/events/ft-sequence-redirected-event-args.ts +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** @public */
|
|
2
|
+
export class FtInternalError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message, errorType) {
|
|
5
|
+
super(message === undefined || message === '' ? `${errorType}: ${code}` : `${errorType}: ${code}: ${message}`);
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** @public */
|
|
10
|
+
(function (FtInternalError) {
|
|
11
|
+
FtInternalError.AssertErrorType = 'FtAssert';
|
|
12
|
+
FtInternalError.UnreachableCaseErrorType = 'FtUnreachableCase';
|
|
13
|
+
FtInternalError.ExtraFormatting = {
|
|
14
|
+
Ignore: 'Ignore',
|
|
15
|
+
PrependWithColonSpace: 'PrependWithColonSpace',
|
|
16
|
+
PrependWithColonSpaceQuoteError: 'PrependWithColonSpaceQuoteError',
|
|
17
|
+
Postpend: 'Postpend',
|
|
18
|
+
PostpendColonSpace: 'PostpendColonSpace',
|
|
19
|
+
PostpendColonSpaceQuoted: 'PostpendColonSpaceQuoted',
|
|
20
|
+
};
|
|
21
|
+
function formatExtra(existingMessage, extraMessage, extraFormatting) {
|
|
22
|
+
switch (extraFormatting) {
|
|
23
|
+
case FtInternalError.ExtraFormatting.Ignore:
|
|
24
|
+
return existingMessage;
|
|
25
|
+
case FtInternalError.ExtraFormatting.PrependWithColonSpace:
|
|
26
|
+
return `${extraMessage}: ${existingMessage}`;
|
|
27
|
+
case FtInternalError.ExtraFormatting.PrependWithColonSpaceQuoteError:
|
|
28
|
+
return `${extraMessage}: "${existingMessage}"`;
|
|
29
|
+
case FtInternalError.ExtraFormatting.Postpend:
|
|
30
|
+
return `${existingMessage}${extraMessage}`;
|
|
31
|
+
case FtInternalError.ExtraFormatting.PostpendColonSpace:
|
|
32
|
+
return `${existingMessage}: ${extraMessage}`;
|
|
33
|
+
case FtInternalError.ExtraFormatting.PostpendColonSpaceQuoted:
|
|
34
|
+
return `${existingMessage}: "${extraMessage}"`;
|
|
35
|
+
default:
|
|
36
|
+
throw new FtUnreachableCaseError('IEAIECINE87339', extraFormatting);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
FtInternalError.formatExtra = formatExtra;
|
|
40
|
+
function appendToErrorMessage(e, appendText) {
|
|
41
|
+
if (e instanceof Error) {
|
|
42
|
+
e.message += appendText;
|
|
43
|
+
return e;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (typeof e === 'string') {
|
|
47
|
+
e += appendText;
|
|
48
|
+
return e;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return e; // Do not know how to append
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
FtInternalError.appendToErrorMessage = appendToErrorMessage;
|
|
56
|
+
function prependErrorMessage(e, prependText) {
|
|
57
|
+
if (e instanceof Error) {
|
|
58
|
+
e.message = prependText + e.message;
|
|
59
|
+
return e;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (typeof e === 'string') {
|
|
63
|
+
e = prependText + e;
|
|
64
|
+
return e;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return e; // Do not know how to prepend
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
FtInternalError.prependErrorMessage = prependErrorMessage;
|
|
72
|
+
function createTypeIfNotError(e, code, errorConstructor, extraMessage, extraFormatting) {
|
|
73
|
+
if (e instanceof Error) {
|
|
74
|
+
let message;
|
|
75
|
+
if (extraMessage === undefined) {
|
|
76
|
+
message = `${code}: ${e.message}`;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (extraFormatting === undefined) {
|
|
80
|
+
extraFormatting = FtInternalError.ExtraFormatting.PostpendColonSpaceQuoted;
|
|
81
|
+
}
|
|
82
|
+
const formattedMessage = FtInternalError.formatExtra(e.message, extraMessage, extraFormatting);
|
|
83
|
+
if (formattedMessage.length === 0) {
|
|
84
|
+
message = code;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
message = `${code}: ${formattedMessage}`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
e.message = message;
|
|
91
|
+
return e;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
if (typeof e === 'string' && extraFormatting !== undefined) {
|
|
95
|
+
if (extraMessage === undefined) {
|
|
96
|
+
extraMessage = code;
|
|
97
|
+
}
|
|
98
|
+
const message = FtInternalError.formatExtra(e, extraMessage, extraFormatting);
|
|
99
|
+
return new errorConstructor(code, message);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return new errorConstructor(code, extraMessage);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
FtInternalError.createTypeIfNotError = createTypeIfNotError;
|
|
107
|
+
function throwErrorTypeIfPromiseRejected(promise, code, errorConstructor, extraMessage, extraFormatting) {
|
|
108
|
+
promise.then(() => {
|
|
109
|
+
/**/
|
|
110
|
+
}, (reason) => {
|
|
111
|
+
throw FtInternalError.createTypeIfNotError(reason, code, errorConstructor, extraMessage, extraFormatting);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
FtInternalError.throwErrorTypeIfPromiseRejected = throwErrorTypeIfPromiseRejected;
|
|
115
|
+
})(FtInternalError || (FtInternalError = {}));
|
|
116
|
+
/** @public */
|
|
117
|
+
export class FtAssertError extends FtInternalError {
|
|
118
|
+
constructor(code, message) {
|
|
119
|
+
super(code, message, 'FtAssert');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** @public */
|
|
123
|
+
export class FtUnreachableCaseError extends FtInternalError {
|
|
124
|
+
constructor(code, value) {
|
|
125
|
+
const errorText = `"${String(value)}"`;
|
|
126
|
+
super(code, errorText, 'FtUnreachableCase');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=ft-internal-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ft-internal-error.js","sourceRoot":"","sources":["../../src/utils/ft-internal-error.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ft-result.js","sourceRoot":"","sources":["../../src/utils/ft-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,KAAK,EAAE,EAAE,IAAI,IAAI,EAAsB,MAAM,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function parseIntStrict(value) {
|
|
2
|
+
return isStringifiedInteger(value) ? parseInt(value, 10) : undefined;
|
|
3
|
+
}
|
|
4
|
+
export function isStringifiedInteger(value) {
|
|
5
|
+
const length = value.length;
|
|
6
|
+
let gotDigit = false;
|
|
7
|
+
for (let i = 0; i < length; i++) {
|
|
8
|
+
const char = value[i];
|
|
9
|
+
switch (char) {
|
|
10
|
+
case '-': {
|
|
11
|
+
if (i !== 0) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
default: {
|
|
19
|
+
if (!isDigitCharCode(char.charCodeAt(0))) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
gotDigit = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return gotDigit;
|
|
29
|
+
}
|
|
30
|
+
export function isDigitCharCode(charCode) {
|
|
31
|
+
return charCode >= 48 && charCode <= 57;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=number-parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-parse.js","sourceRoot":"","sources":["../../src/utils/number-parse.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAE5B,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACZ,OAAO,KAAK,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACN,MAAM;gBACR,CAAC;YACH,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBACzC,OAAO,KAAK,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACN,QAAQ,GAAG,IAAI,CAAC;gBAClB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,IAAI,EAAE,IAAI,QAAQ,IAAI,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export class StringBuilder {
|
|
2
|
+
static _defaultInitialCapacity = 10;
|
|
3
|
+
_initialCapacity;
|
|
4
|
+
_count = 0;
|
|
5
|
+
_values;
|
|
6
|
+
constructor(initialCapacity = StringBuilder._defaultInitialCapacity) {
|
|
7
|
+
this._initialCapacity = initialCapacity;
|
|
8
|
+
this._values = new Array(this._initialCapacity);
|
|
9
|
+
}
|
|
10
|
+
get capacity() {
|
|
11
|
+
return this._values.length;
|
|
12
|
+
}
|
|
13
|
+
set capacity(newCapacity) {
|
|
14
|
+
this._values.length = newCapacity;
|
|
15
|
+
if (this._count > newCapacity) {
|
|
16
|
+
this._count = newCapacity;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
toString() {
|
|
20
|
+
this.capacity = this._count;
|
|
21
|
+
return this._values.join('');
|
|
22
|
+
}
|
|
23
|
+
append(value) {
|
|
24
|
+
if (this._count >= this.capacity) {
|
|
25
|
+
this.growCapacity(1);
|
|
26
|
+
}
|
|
27
|
+
this._values[this._count++] = value;
|
|
28
|
+
}
|
|
29
|
+
appendLine(value = '') {
|
|
30
|
+
this.append(value + '\n');
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this._count = 0;
|
|
34
|
+
this._values.length = this._initialCapacity;
|
|
35
|
+
}
|
|
36
|
+
growCapacity(byAtLeast) {
|
|
37
|
+
this._values.length += (this._values.length + byAtLeast) * 2;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=string-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-builder.js","sourceRoot":"","sources":["../../src/utils/string-builder.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAa;IAChB,MAAM,CAAU,uBAAuB,GAAG,EAAE,CAAC;IAE7C,gBAAgB,CAAS;IACzB,MAAM,GAAG,CAAC,CAAC;IACX,OAAO,CAAW;IAE1B,YAAY,kBAA0B,aAAa,CAAC,uBAAuB;QACzE,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,IAAI,KAAK,CAAS,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IACD,IAAI,QAAQ,CAAC,WAAmB;QAC9B,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC;QAClC,IAAI,IAAI,CAAC,MAAM,GAAG,WAAW,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC;IACtC,CAAC;IAED,UAAU,CAAC,KAAK,GAAG,EAAE;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC;IAC9C,CAAC;IAEO,YAAY,CAAC,SAAiB;QACpC,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAC/D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pbkware/fielded-text-web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "A reader and writer TypeScript library for text data with fields, based on Fielded Text. Browser compatible.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=24"
|
|
9
9
|
},
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
@@ -20,11 +20,18 @@
|
|
|
20
20
|
"README.md",
|
|
21
21
|
"LICENSE"
|
|
22
22
|
],
|
|
23
|
-
"
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"provenance": true
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://pbkware.github.io/fielded-text-ts/Web/",
|
|
24
28
|
"repository": {
|
|
25
29
|
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/pbkware/fielded-text-
|
|
27
|
-
"directory": "
|
|
30
|
+
"url": "git+https://github.com/pbkware/fielded-text-ts.git",
|
|
31
|
+
"directory": "web"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/pbkware/fielded-text-ts/issues"
|
|
28
35
|
},
|
|
29
36
|
"contributors": [
|
|
30
37
|
"Paul Klink (https://paul.klink.au)"
|
|
@@ -56,33 +63,24 @@
|
|
|
56
63
|
"docs:check:nullability": "(command -v rg >/dev/null && rg -n \"nullableValue.*undefined|asNullable.*undefined|nullable value accessors return.*undefined\" README.md docs/guide examples --glob \"*.md\" || grep -R -n -E \"nullableValue.*undefined|asNullable.*undefined|nullable value accessors return.*undefined\" README.md docs/guide examples --include='*.md') && echo \"ERROR: found undefined nullable-value docs pattern\" && exit 1 || true",
|
|
57
64
|
"docs:align": "npm run build && npm test && npm run examples:all && npm run docs && npm run api && npm run docs:check:drift && npm run docs:check:nullability",
|
|
58
65
|
"lint": "eslint",
|
|
59
|
-
"prettier": "npx prettier --write ."
|
|
60
|
-
"docs": "typedoc",
|
|
61
|
-
"docs:watch": "typedoc --watch",
|
|
62
|
-
"docs:serve": "vite --config ./vite.docs-dev.config.mjs --host",
|
|
63
|
-
"publish:pre": "cp ../README.md ./README.md && cp ../LICENSE ./LICENSE && npm run dist",
|
|
64
|
-
"publish:post": "rm ./README.md && rm ./LICENSE",
|
|
65
|
-
"publish": "npm run publish:pre && npm publish --access=public && npm run publish:post"
|
|
66
|
+
"prettier": "npx prettier --write ."
|
|
66
67
|
},
|
|
67
68
|
"dependencies": {
|
|
68
|
-
"@pbkware/dot-net-date-number-formatting": "^0.3.
|
|
69
|
-
"
|
|
70
|
-
"fast-xml-
|
|
71
|
-
"fast-xml-parser": "^5.8.0"
|
|
69
|
+
"@pbkware/dot-net-date-number-formatting": "^0.3.2",
|
|
70
|
+
"fast-xml-builder": "^1.3.1",
|
|
71
|
+
"fast-xml-parser": "^5.11.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@eslint/js": "^10.0.1",
|
|
75
|
-
"@microsoft/api-extractor": "^7.
|
|
75
|
+
"@microsoft/api-extractor": "^7.59.1",
|
|
76
76
|
"del-cli": "^7.0.0",
|
|
77
|
-
"eslint": "^10.
|
|
78
|
-
"eslint-import-resolver-typescript": "^4.4.
|
|
79
|
-
"eslint-plugin-import-x": "^4.
|
|
80
|
-
"prettier": "^3.
|
|
81
|
-
"tsx": "^4.
|
|
82
|
-
"typedoc": "^0.28.19",
|
|
77
|
+
"eslint": "^10.10.0",
|
|
78
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
79
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
80
|
+
"prettier": "^3.9.6",
|
|
81
|
+
"tsx": "^4.23.13",
|
|
83
82
|
"typescript": "^6.0.3",
|
|
84
|
-
"typescript-eslint": "^8.
|
|
85
|
-
"
|
|
86
|
-
"vitest": "^4.1.5"
|
|
83
|
+
"typescript-eslint": "^8.70.0",
|
|
84
|
+
"vitest": "^4.1.11"
|
|
87
85
|
}
|
|
88
86
|
}
|
package/src/api/ft-reader.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FtMeta } from '../meta/ft-meta.js';
|
|
2
2
|
import { FtSerializationReader } from '../serialization/ft-serialization-reader.js';
|
|
3
|
-
import { FtStringReader
|
|
3
|
+
import { FtStringReader } from '../serialization/text-reader/ft-string-reader.js';
|
|
4
|
+
import { FtTextReader } from '../serialization/text-reader/ft-text-reader.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* High-level reader for fielded text files.
|
|
@@ -5,16 +5,16 @@ import { FtSequenceInvokationList } from '../sequences/core/ft-sequence-invokati
|
|
|
5
5
|
import { FtSequenceInvokation } from '../sequences/core/ft-sequence-invokation.js';
|
|
6
6
|
import { FtSequenceList } from '../sequences/core/ft-sequence-list.js';
|
|
7
7
|
import { FtSequence } from '../sequences/core/ft-sequence.js';
|
|
8
|
+
import { FtFieldHeadingReadyEventArgs } from '../serialization/events/ft-field-heading-ready-event-args.js';
|
|
9
|
+
import { FtFieldValueReadyEventArgs } from '../serialization/events/ft-field-value-ready-event-args.js';
|
|
10
|
+
import { FtHeadingLineFinishedEventArgs } from '../serialization/events/ft-heading-line-finished-event-args.js';
|
|
11
|
+
import { FtHeadingLineStartedEventArgs } from '../serialization/events/ft-heading-line-started-event-args.js';
|
|
12
|
+
import { FtRecordFinishedEventArgs } from '../serialization/events/ft-record-finished-event-args.js';
|
|
13
|
+
import { FtRecordStartedEventArgs } from '../serialization/events/ft-record-started-event-args.js';
|
|
14
|
+
import { FtSequenceRedirectedEventArgs } from '../serialization/events/ft-sequence-redirected-event-args.js';
|
|
15
|
+
import { FtSerializationCore } from '../serialization/ft-serialization-core.js';
|
|
8
16
|
import { FtTextWriter } from '../serialization/ft-text-writer.js';
|
|
9
|
-
import { SerializationCore } from '../serialization/serialization-core.js';
|
|
10
17
|
import { FtSubstitutionList } from '../substitutions/ft-substitution-list.js';
|
|
11
|
-
import { FtFieldHeadingReadyEventArgs } from '../types/events/ft-field-heading-ready-event-args.js';
|
|
12
|
-
import { FtFieldValueReadyEventArgs } from '../types/events/ft-field-value-ready-event-args.js';
|
|
13
|
-
import { FtHeadingLineFinishedEventArgs } from '../types/events/ft-heading-line-finished-event-args.js';
|
|
14
|
-
import { FtHeadingLineStartedEventArgs } from '../types/events/ft-heading-line-started-event-args.js';
|
|
15
|
-
import { FtRecordFinishedEventArgs } from '../types/events/ft-record-finished-event-args.js';
|
|
16
|
-
import { FtRecordStartedEventArgs } from '../types/events/ft-record-started-event-args.js';
|
|
17
|
-
import { FtSequenceRedirectedEventArgs } from '../types/events/ft-sequence-redirected-event-args.js';
|
|
18
18
|
import { FtReader } from './ft-reader.js';
|
|
19
19
|
import { FtWriterSettings } from './ft-writer-settings.js';
|
|
20
20
|
import { FtWriter } from './ft-writer.js';
|
|
@@ -36,9 +36,9 @@ export class FtAbortSerializationException extends Error {
|
|
|
36
36
|
* @public
|
|
37
37
|
*/
|
|
38
38
|
export class FtSerialization {
|
|
39
|
-
static readonly VERSION_MAJOR =
|
|
40
|
-
static readonly VERSION_MINOR =
|
|
41
|
-
static readonly PREFIX_SPACE_CHAR =
|
|
39
|
+
static readonly VERSION_MAJOR = FtSerializationCore.VersionMajor;
|
|
40
|
+
static readonly VERSION_MINOR = FtSerializationCore.VersionMinor;
|
|
41
|
+
static readonly PREFIX_SPACE_CHAR = FtSerializationCore.PrefixSpaceChar;
|
|
42
42
|
|
|
43
43
|
// Event hooks
|
|
44
44
|
onFieldHeadingReadReady: ((args: FtFieldHeadingReadyEventArgs) => void) | undefined = undefined;
|
|
@@ -52,7 +52,7 @@ export class FtSerialization {
|
|
|
52
52
|
onSequenceRedirected: ((args: FtSequenceRedirectedEventArgs) => void) | undefined = undefined;
|
|
53
53
|
|
|
54
54
|
private _meta: FtMeta;
|
|
55
|
-
private _core:
|
|
55
|
+
private _core: FtSerializationCore | undefined = undefined;
|
|
56
56
|
|
|
57
57
|
constructor(meta: FtMeta) {
|
|
58
58
|
this._meta = meta;
|
|
@@ -155,7 +155,7 @@ export class FtSerialization {
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
private setCore(core:
|
|
158
|
+
private setCore(core: FtSerializationCore): void {
|
|
159
159
|
this._core = core;
|
|
160
160
|
|
|
161
161
|
// Wire up event handlers
|
|
@@ -22,7 +22,7 @@ import { FtStringMetaField } from '../meta/fields/ft-string-meta-field.js';
|
|
|
22
22
|
import { FtSequenceInvokation } from '../sequences/core/ft-sequence-invokation.js';
|
|
23
23
|
import { FtSequenceItem } from '../sequences/core/ft-sequence-item.js';
|
|
24
24
|
import { FtDataType } from '../types/enums/ft-data-type.js';
|
|
25
|
-
import { FtUnreachableCaseError } from '../
|
|
25
|
+
import { FtUnreachableCaseError } from '../utils/ft-internal-error.js';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Factory for creating field instances based on their definitions.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Err, Ok, Result } from '@pbkware/js-utils';
|
|
2
1
|
import { FtBooleanSequenceRedirect } from '../sequences/redirects/ft-boolean-sequence-redirect.js';
|
|
3
2
|
import { FtCaseInsensitiveStringSequenceRedirect } from '../sequences/redirects/ft-case-insensitive-string-sequence-redirect.js';
|
|
4
3
|
import { FtDateSequenceRedirect } from '../sequences/redirects/ft-date-sequence-redirect.js';
|
|
@@ -10,6 +9,7 @@ import { FtExactStringSequenceRedirect } from '../sequences/redirects/ft-exact-s
|
|
|
10
9
|
import { FtNullSequenceRedirect } from '../sequences/redirects/ft-null-sequence-redirect.js';
|
|
11
10
|
import { FtSequenceRedirect } from '../sequences/redirects/ft-sequence-redirect.js';
|
|
12
11
|
import { FtSequenceRedirectType } from '../types/enums/ft-sequence-redirect-type.js';
|
|
12
|
+
import { FtErr, FtOk, FtResult } from '../utils/ft-result.js';
|
|
13
13
|
import { FtSequenceRedirectConstructor } from './ft-sequence-redirect-constructor.js';
|
|
14
14
|
|
|
15
15
|
// Concrete constructor implementations
|
|
@@ -178,12 +178,12 @@ export class FtSequenceRedirectFactory {
|
|
|
178
178
|
return constructor.sequenceRedirectTypeName;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
static tryGetType(typeName: string):
|
|
181
|
+
static tryGetType(typeName: string): FtResult<FtSequenceRedirectType, boolean> {
|
|
182
182
|
const constructor = FtSequenceRedirectFactory.tryFindConstructorByName(typeName);
|
|
183
183
|
if (constructor) {
|
|
184
|
-
return new
|
|
184
|
+
return new FtOk(constructor.sequenceRedirectType);
|
|
185
185
|
}
|
|
186
|
-
return new
|
|
186
|
+
return new FtErr(false);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
private static tryFindConstructorByType(type: FtSequenceRedirectType): FtSequenceRedirectConstructor | undefined {
|
|
@@ -39,7 +39,7 @@ export class FtBooleanFieldDefinition extends FtGenericFieldDefinition<boolean>
|
|
|
39
39
|
this.formatter.styles = metaField.styles;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
formatValue(value: boolean): string {
|
|
43
43
|
return this.formatter.toText(value);
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -42,7 +42,7 @@ export class FtDateTimeFieldDefinition extends FtGenericFieldDefinition<Date> {
|
|
|
42
42
|
this._constantValue = dateTimeMetaField.value;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
formatValue(value: Date): string {
|
|
46
46
|
return this.formatter.toText(value);
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -33,7 +33,7 @@ export class FtDecimalFieldDefinition extends FtGenericFieldDefinition<number> {
|
|
|
33
33
|
this.formatter.styles = metaField.styles;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
formatValue(value: number): string {
|
|
37
37
|
return this.formatter.toText(value);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -8,7 +8,7 @@ import { FtPadAlignment } from '../../types/enums/ft-pad-alignment.js';
|
|
|
8
8
|
import { FtPadCharType } from '../../types/enums/ft-pad-char-type.js';
|
|
9
9
|
import { FtQuotedType } from '../../types/enums/ft-quoted-type.js';
|
|
10
10
|
import { FtTruncateType } from '../../types/enums/ft-truncate-type.js';
|
|
11
|
-
import { FtUnreachableCaseError } from '../../
|
|
11
|
+
import { FtUnreachableCaseError } from '../../utils/ft-internal-error.js';
|
|
12
12
|
|
|
13
13
|
const InternalError = {
|
|
14
14
|
FtFieldFieldDefinition_LoadMeta_UnsupportedHeadingPadAlignment: 'FtFieldFieldDefinition_LoadMeta_UnsupportedHeadingPadAlignment',
|
|
@@ -33,7 +33,7 @@ export class FtFloatFieldDefinition extends FtGenericFieldDefinition<number> {
|
|
|
33
33
|
this.formatter.styles = metaField.styles;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
formatValue(value: number): string {
|
|
37
37
|
return this.formatter.toText(value);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -38,7 +38,7 @@ export abstract class FtGenericFieldDefinition<T> extends FtFieldDefinition {
|
|
|
38
38
|
* @param value - The value to convert
|
|
39
39
|
* @returns The text representation
|
|
40
40
|
*/
|
|
41
|
-
abstract
|
|
41
|
+
abstract formatValue(value: T): string;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Parse text into a typed value.
|
|
@@ -34,7 +34,7 @@ export class FtIntegerFieldDefinition extends FtGenericFieldDefinition<bigint> {
|
|
|
34
34
|
this.formatter.styles = metaField.styles;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
formatValue(value: bigint): string {
|
|
38
38
|
return this.formatter.toText(value);
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -16,7 +16,7 @@ export class FtStringFieldDefinition extends FtGenericFieldDefinition<string> {
|
|
|
16
16
|
super(FtDataType.String, 'string', formatter, FtStringFieldDefinition.AUTO_LEFT_PAD, index);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
formatValue(value: string): string {
|
|
20
20
|
return this.formatter.toText(value);
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a field value is null and an operation is attempted that requires a non-null value.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export class FtFieldNullError extends Error {
|
|
6
|
+
constructor(message: string) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'FtFieldNullError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FtSequenceInvokation } from '../../sequences/core/ft-sequence-invokation.js';
|
|
2
2
|
import { FtSequenceItem } from '../../sequences/core/ft-sequence-item.js';
|
|
3
3
|
import { FtBooleanStyles } from '../../types/enums/ft-boolean-styles.js';
|
|
4
|
+
import { FtDataType } from '../../types/enums/ft-data-type.js';
|
|
4
5
|
import { FtBooleanFieldDefinition } from '../definitions/ft-boolean-field-definition.js';
|
|
6
|
+
import { FtFieldTypeError } from './errors/ft-field-type-error.js';
|
|
7
|
+
import { FtField } from './ft-field.js';
|
|
5
8
|
import { FtGenericField } from './ft-generic-field.js';
|
|
6
9
|
|
|
7
10
|
/**
|
|
@@ -31,18 +34,26 @@ export class FtBooleanField extends FtGenericField<boolean> {
|
|
|
31
34
|
return this.definition.styles;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
return
|
|
37
|
+
static cast(field: FtField): field is FtBooleanField {
|
|
38
|
+
return field.dataType === FtDataType.Boolean;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
+
override setValue(newValue: FtField.Value): number {
|
|
42
|
+
if (typeof newValue === 'boolean') {
|
|
43
|
+
return super.setValue(newValue);
|
|
41
44
|
} else {
|
|
42
|
-
this.
|
|
45
|
+
throw new FtFieldTypeError(`Invalid type (${typeof newValue}) for boolean field: ${this.name}`);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
protected override getAsBoolean(): boolean {
|
|
50
|
+
return this.getValue();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected override setAsBoolean(newValue: boolean): void {
|
|
54
|
+
super.setValue(newValue);
|
|
55
|
+
}
|
|
56
|
+
|
|
46
57
|
protected isValueEqual(left: boolean, right: boolean): boolean {
|
|
47
58
|
return left === right;
|
|
48
59
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { FtSequenceInvokation } from '../../sequences/core/ft-sequence-invokation.js';
|
|
2
2
|
import { FtSequenceItem } from '../../sequences/core/ft-sequence-item.js';
|
|
3
|
+
import { FtDataType } from '../../types/enums/ft-data-type.js';
|
|
3
4
|
import { FtDateTimeFieldDefinition } from '../definitions/ft-date-time-field-definition.js';
|
|
5
|
+
import { FtFieldTypeError } from './errors/ft-field-type-error.js';
|
|
6
|
+
import { FtField } from './ft-field.js';
|
|
4
7
|
import { FtGenericField } from './ft-generic-field.js';
|
|
5
8
|
|
|
6
9
|
/**
|
|
@@ -26,18 +29,36 @@ export class FtDateTimeField extends FtGenericField<Date> {
|
|
|
26
29
|
return this.definition.styles;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
return
|
|
32
|
+
static cast(field: FtField): field is FtDateTimeField {
|
|
33
|
+
return field.dataType === FtDataType.DateTime;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
override setValue(newValue: FtField.Value): number {
|
|
37
|
+
switch (typeof newValue) {
|
|
38
|
+
case 'string':
|
|
39
|
+
case 'number':
|
|
40
|
+
return super.setValue(new Date(newValue));
|
|
41
|
+
break;
|
|
42
|
+
case 'object':
|
|
43
|
+
if (newValue instanceof Date) {
|
|
44
|
+
return super.setValue(newValue);
|
|
45
|
+
} else {
|
|
46
|
+
throw new FtFieldTypeError(`Invalid object for DateTime field: ${this.name}`);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
throw new FtFieldTypeError(`Invalid type (${typeof newValue}) for date-time field: ${this.name}`);
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
|
|
54
|
+
protected override getAsDateTime(): Date {
|
|
55
|
+
return this.getValue();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected override setAsDateTime(newValue: Date): void {
|
|
59
|
+
super.setValue(newValue);
|
|
60
|
+
}
|
|
61
|
+
|
|
41
62
|
protected isValueEqual(left: Date, right: Date): boolean {
|
|
42
63
|
return left.getTime() === right.getTime();
|
|
43
64
|
}
|