@outburn/format-converter 1.0.1 → 1.0.4
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/LICENSE +20 -20
- package/README.md +355 -170
- package/dist/browser/browser.js +2 -0
- package/dist/browser/browser.js.map +1 -0
- package/dist/index.cjs +85 -0
- package/dist/index.d.ts +123 -2
- package/dist/index.mjs +85 -1
- package/package.json +18 -6
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -76
- package/dist/index.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -583,7 +583,92 @@ var FormatConverter = class _FormatConverter {
|
|
|
583
583
|
}
|
|
584
584
|
};
|
|
585
585
|
|
|
586
|
+
// src/FormatDetector.ts
|
|
587
|
+
var isPossiblyHL7 = (input) => typeof input === "string" && input.trimStart().startsWith("MSH|");
|
|
588
|
+
var isValidJson = (input) => {
|
|
589
|
+
try {
|
|
590
|
+
JSON.parse(input);
|
|
591
|
+
return true;
|
|
592
|
+
} catch (e) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var isJsonLikely = (input) => {
|
|
597
|
+
const inputWithoutStrings = input;
|
|
598
|
+
const jsonStats = {
|
|
599
|
+
curlyBraces: (inputWithoutStrings.match(/[{}]/g) || []).length,
|
|
600
|
+
colons: (inputWithoutStrings.match(/:/g) || []).length,
|
|
601
|
+
keyValueStructure: /{[^}]*:[^}]*}/.test(input)
|
|
602
|
+
// Key-value pattern
|
|
603
|
+
};
|
|
604
|
+
const hasIncompleteJsonPattern = /{[^}]*"[^"]*"\s*:\s*/.test(input);
|
|
605
|
+
const isJsonLikely2 = (jsonStats.curlyBraces >= 2 || jsonStats.curlyBraces >= 1 && hasIncompleteJsonPattern) && jsonStats.colons >= 1 && (jsonStats.keyValueStructure || /{.*:.*}/.test(input) || hasIncompleteJsonPattern);
|
|
606
|
+
return isJsonLikely2;
|
|
607
|
+
};
|
|
608
|
+
var isXmlLikely = (input) => {
|
|
609
|
+
const xmlStats = {
|
|
610
|
+
openingTags: (input.match(/<[^/!?][^>]*?>/g) || []).length,
|
|
611
|
+
closingTags: (input.match(/<\/[^>]+>/g) || []).length,
|
|
612
|
+
selfClosingTags: (input.match(/<[^>]+\/>/g) || []).length,
|
|
613
|
+
xmlNamespaces: (input.match(/xmlns(:[a-zA-Z0-9]+)?=/g) || []).length
|
|
614
|
+
};
|
|
615
|
+
const hasXmlHeader = /^<\?xml.*?\?>/.test(input);
|
|
616
|
+
const isXmlLikely2 = (hasXmlHeader || xmlStats.xmlNamespaces >= 1 || xmlStats.openingTags >= 1) && (xmlStats.openingTags === xmlStats.closingTags || xmlStats.selfClosingTags >= 1);
|
|
617
|
+
return isXmlLikely2;
|
|
618
|
+
};
|
|
619
|
+
var isCsvLikely = (input) => {
|
|
620
|
+
const lines = input.split(/\r?\n/);
|
|
621
|
+
const headerRow = lines[0];
|
|
622
|
+
const csvStats = {
|
|
623
|
+
rowCount: lines.length,
|
|
624
|
+
commaCounts: lines.map((line) => (line.match(/,/g) || []).length)
|
|
625
|
+
};
|
|
626
|
+
const headerStats = {
|
|
627
|
+
curlyBraces: (headerRow.match(/[{}]/g) || []).length,
|
|
628
|
+
squareBrackets: (headerRow.match(/[\[\]]/g) || []).length,
|
|
629
|
+
angularBrackets: (headerRow.match(/[<>]/g) || []).length,
|
|
630
|
+
colons: (headerRow.match(/:/g) || []).length
|
|
631
|
+
};
|
|
632
|
+
const isCsvLikely2 = (csvStats.rowCount > 1 || csvStats.commaCounts.some((count) => count > 0)) && headerStats.curlyBraces === 0 && headerStats.squareBrackets === 0 && headerStats.angularBrackets === 0 && headerStats.colons === 0;
|
|
633
|
+
return isCsvLikely2;
|
|
634
|
+
};
|
|
635
|
+
var FormatDetector = class _FormatDetector {
|
|
636
|
+
static {
|
|
637
|
+
this.typeConverter = new TypeConverter();
|
|
638
|
+
}
|
|
639
|
+
detectContentType(input) {
|
|
640
|
+
const format = this.detectFormat(input);
|
|
641
|
+
return _FormatDetector.typeConverter.contentFormatToContentType(format);
|
|
642
|
+
}
|
|
643
|
+
detectFormat(input) {
|
|
644
|
+
try {
|
|
645
|
+
const trimmedInput = input?.trim();
|
|
646
|
+
if (!trimmedInput) return "unknown" /* UNKNOWN */;
|
|
647
|
+
if (isValidJson(input)) return "json" /* JSON */;
|
|
648
|
+
if (isPossiblyHL7(input)) return "hl7" /* HL7 */;
|
|
649
|
+
if (isJsonLikely(input)) return "json" /* JSON */;
|
|
650
|
+
if (isXmlLikely(input)) return "xml" /* XML */;
|
|
651
|
+
if (isCsvLikely(input)) return "csv" /* CSV */;
|
|
652
|
+
return "unknown" /* UNKNOWN */;
|
|
653
|
+
} catch (e) {
|
|
654
|
+
return "unknown" /* UNKNOWN */;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
detectEditorLanguage(input) {
|
|
658
|
+
const format = this.detectFormat(input);
|
|
659
|
+
switch (format) {
|
|
660
|
+
case "json" /* JSON */:
|
|
661
|
+
return "json" /* JSON */;
|
|
662
|
+
case "xml" /* XML */:
|
|
663
|
+
return "xml" /* XML */;
|
|
664
|
+
default:
|
|
665
|
+
return "plaintext" /* PLAINTEXT */;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
|
|
586
670
|
exports.FormatConverter = FormatConverter;
|
|
671
|
+
exports.FormatDetector = FormatDetector;
|
|
587
672
|
exports.TypeConverter = TypeConverter;
|
|
588
673
|
//# sourceMappingURL=index.cjs.map
|
|
589
674
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -4,46 +4,160 @@ interface ILogger {
|
|
|
4
4
|
error: (msg: any) => void;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Enumeration of supported content formats for detection and conversion.
|
|
9
|
+
* Used by format detection algorithms to categorize input data and determine
|
|
10
|
+
* appropriate conversion strategies.
|
|
11
|
+
*/
|
|
7
12
|
declare const enum ContentFormat {
|
|
13
|
+
/** JavaScript Object Notation format */
|
|
8
14
|
JSON = "json",
|
|
15
|
+
/** Comma-Separated Values format */
|
|
9
16
|
CSV = "csv",
|
|
17
|
+
/** eXtensible Markup Language format */
|
|
10
18
|
XML = "xml",
|
|
19
|
+
/** Health Level 7 Version 2.x message format */
|
|
11
20
|
HL7 = "hl7",
|
|
21
|
+
/** Unknown or unsupported format */
|
|
12
22
|
UNKNOWN = "unknown"
|
|
13
23
|
}
|
|
14
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Enumeration of supported MIME types/content types for data format identification.
|
|
27
|
+
* These values correspond to standard HTTP Content-Type header values and are used
|
|
28
|
+
* for format detection and conversion operations.
|
|
29
|
+
*/
|
|
15
30
|
declare const enum ContentType {
|
|
31
|
+
/** Standard MIME type for JSON data */
|
|
16
32
|
JSON = "application/json",
|
|
33
|
+
/** Standard MIME type for CSV data */
|
|
17
34
|
CSV = "text/csv",
|
|
35
|
+
/** Standard MIME type for XML data */
|
|
18
36
|
XML = "application/xml",
|
|
37
|
+
/** Custom MIME type for HL7 Version 2.x messages in ER7 encoding */
|
|
19
38
|
HL7V2 = "x-application/hl7-v2+er7"
|
|
20
39
|
}
|
|
21
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Enumeration of supported editor language identifiers for syntax highlighting and editor configuration.
|
|
43
|
+
* These values are used to determine the appropriate language mode for displaying content
|
|
44
|
+
* in code editors or other text editing interfaces.
|
|
45
|
+
*/
|
|
22
46
|
declare const enum EditorLanguage {
|
|
47
|
+
/** JSON language mode for syntax highlighting */
|
|
23
48
|
JSON = "json",
|
|
49
|
+
/** XML language mode for syntax highlighting */
|
|
24
50
|
XML = "xml",
|
|
51
|
+
/** Plain text mode with no syntax highlighting */
|
|
25
52
|
PLAINTEXT = "plaintext"
|
|
26
53
|
}
|
|
27
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Interface for format detection operations, providing methods to analyze and identify
|
|
57
|
+
* various aspects of input data including content type, format, and appropriate editor language.
|
|
58
|
+
*/
|
|
59
|
+
interface IFormatDetector {
|
|
60
|
+
/**
|
|
61
|
+
* Detects the content type of the given input string.
|
|
62
|
+
* @param input Input string to analyze
|
|
63
|
+
* @returns Detected ContentType or null if undetectable
|
|
64
|
+
*/
|
|
65
|
+
detectContentType: (input: string) => ContentType | null;
|
|
66
|
+
/**
|
|
67
|
+
* Detects the content format of the given input string.
|
|
68
|
+
* @param input Input string to analyze
|
|
69
|
+
* @returns Detected ContentFormat
|
|
70
|
+
*/
|
|
71
|
+
detectFormat: (input: string) => ContentFormat;
|
|
72
|
+
/**
|
|
73
|
+
* Detects the appropriate editor language for the given input string.
|
|
74
|
+
* @param input Input string to analyze
|
|
75
|
+
* @returns Detected EditorLanguage
|
|
76
|
+
*/
|
|
77
|
+
detectEditorLanguage: (input: string) => EditorLanguage;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Interface for format conversion operations, providing methods to convert various data formats to JSON.
|
|
82
|
+
* Supports conversion from CSV, XML, and HL7 V2.x message formats.
|
|
83
|
+
*/
|
|
28
84
|
interface IFormatConverter {
|
|
85
|
+
/**
|
|
86
|
+
* Converts input data to JSON format based on the specified content type.
|
|
87
|
+
* If content type is not provided, defaults to `application/json`.
|
|
88
|
+
* @param input Data to be converted
|
|
89
|
+
* @param contentType Optional content type indicating the format of the input data
|
|
90
|
+
* @returns Promise resolving to JSON object
|
|
91
|
+
* @throws Error if the content type is unsupported or conversion fails
|
|
92
|
+
*/
|
|
29
93
|
toJson: (input: any, contentType?: ContentType | string) => Promise<any>;
|
|
30
94
|
/**
|
|
31
|
-
* Converts CSV string to JSON object. If conversion fails, returns empty array.
|
|
95
|
+
* Converts CSV string to JSON object. If conversion fails, returns an empty array.
|
|
32
96
|
* @param input CSV string to be converted
|
|
33
97
|
* @returns Promise resolving to JSON object
|
|
34
98
|
*/
|
|
35
99
|
csvToJson: (input: string) => Promise<any>;
|
|
100
|
+
/**
|
|
101
|
+
* Converts XML string to JSON object. If the input is empty, returns an empty object.
|
|
102
|
+
* @param input XML string to be converted
|
|
103
|
+
* @returns Promise resolving to JSON object
|
|
104
|
+
* @throws Error if XML parsing fails
|
|
105
|
+
*/
|
|
36
106
|
xmlToJson: (input: string) => Promise<any>;
|
|
107
|
+
/**
|
|
108
|
+
* Converts HL7 V2.x message string to JSON object.
|
|
109
|
+
* @param message HL7 V2.x message string to be converted
|
|
110
|
+
* @returns Promise resolving to JSON object
|
|
111
|
+
*/
|
|
37
112
|
hl7v2ToJson: (message: string) => Promise<any>;
|
|
38
113
|
}
|
|
39
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Interface for type conversion operations, providing methods to convert between
|
|
117
|
+
* different content type representations (ContentType, ContentFormat, EditorLanguage, and string).
|
|
118
|
+
*/
|
|
40
119
|
interface ITypeConverter {
|
|
120
|
+
/**
|
|
121
|
+
* Converts a ContentType to its corresponding ContentFormat.
|
|
122
|
+
* @param contentType The ContentType to convert
|
|
123
|
+
* @returns The corresponding ContentFormat
|
|
124
|
+
*/
|
|
41
125
|
contentTypeToContentFormat: (contentType: ContentType) => ContentFormat;
|
|
126
|
+
/**
|
|
127
|
+
* Converts a ContentType to its corresponding EditorLanguage.
|
|
128
|
+
* @param contentType The ContentType to convert
|
|
129
|
+
* @returns The corresponding EditorLanguage
|
|
130
|
+
*/
|
|
42
131
|
contentTypeToEditorLanguage: (contentType: ContentType) => EditorLanguage;
|
|
132
|
+
/**
|
|
133
|
+
* Converts a ContentFormat to its corresponding ContentType.
|
|
134
|
+
* @param format The ContentFormat to convert
|
|
135
|
+
* @returns The corresponding ContentType, or null if conversion is not possible
|
|
136
|
+
*/
|
|
43
137
|
contentFormatToContentType: (format: ContentFormat) => ContentType | null;
|
|
138
|
+
/**
|
|
139
|
+
* Converts a ContentFormat to its corresponding EditorLanguage.
|
|
140
|
+
* @param format The ContentFormat to convert
|
|
141
|
+
* @returns The corresponding EditorLanguage
|
|
142
|
+
*/
|
|
44
143
|
contentFormatToEditorLanguage: (format: ContentFormat) => EditorLanguage;
|
|
144
|
+
/**
|
|
145
|
+
* Converts a string representation to its corresponding ContentFormat.
|
|
146
|
+
* @param format The string representation of a format
|
|
147
|
+
* @returns The corresponding ContentFormat, or null if conversion is not possible
|
|
148
|
+
*/
|
|
45
149
|
stringToContentFormat: (format: string) => ContentFormat | null;
|
|
150
|
+
/**
|
|
151
|
+
* Converts a string representation to its corresponding ContentType.
|
|
152
|
+
* @param contentType The string representation of a content type
|
|
153
|
+
* @returns The corresponding ContentType, or null if conversion is not possible
|
|
154
|
+
*/
|
|
46
155
|
stringToContentType: (contentType: string) => ContentType | null;
|
|
156
|
+
/**
|
|
157
|
+
* Converts a string representation to its corresponding EditorLanguage.
|
|
158
|
+
* @param editorLanguage The string representation of an editor language
|
|
159
|
+
* @returns The corresponding EditorLanguage, or null if conversion is not possible
|
|
160
|
+
*/
|
|
47
161
|
stringToEditorLanguage: (editorLanguage: string) => EditorLanguage | null;
|
|
48
162
|
}
|
|
49
163
|
|
|
@@ -73,4 +187,11 @@ declare class FormatConverter implements IFormatConverter {
|
|
|
73
187
|
hl7v2ToJson: (message: string) => Promise<any>;
|
|
74
188
|
}
|
|
75
189
|
|
|
76
|
-
|
|
190
|
+
declare class FormatDetector implements IFormatDetector {
|
|
191
|
+
private static readonly typeConverter;
|
|
192
|
+
detectContentType(input: string): ContentType | null;
|
|
193
|
+
detectFormat(input: string): ContentFormat;
|
|
194
|
+
detectEditorLanguage(input: string): EditorLanguage;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { FormatConverter, FormatDetector, TypeConverter };
|
package/dist/index.mjs
CHANGED
|
@@ -574,6 +574,90 @@ var FormatConverter = class _FormatConverter {
|
|
|
574
574
|
}
|
|
575
575
|
};
|
|
576
576
|
|
|
577
|
-
|
|
577
|
+
// src/FormatDetector.ts
|
|
578
|
+
var isPossiblyHL7 = (input) => typeof input === "string" && input.trimStart().startsWith("MSH|");
|
|
579
|
+
var isValidJson = (input) => {
|
|
580
|
+
try {
|
|
581
|
+
JSON.parse(input);
|
|
582
|
+
return true;
|
|
583
|
+
} catch (e) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var isJsonLikely = (input) => {
|
|
588
|
+
const inputWithoutStrings = input;
|
|
589
|
+
const jsonStats = {
|
|
590
|
+
curlyBraces: (inputWithoutStrings.match(/[{}]/g) || []).length,
|
|
591
|
+
colons: (inputWithoutStrings.match(/:/g) || []).length,
|
|
592
|
+
keyValueStructure: /{[^}]*:[^}]*}/.test(input)
|
|
593
|
+
// Key-value pattern
|
|
594
|
+
};
|
|
595
|
+
const hasIncompleteJsonPattern = /{[^}]*"[^"]*"\s*:\s*/.test(input);
|
|
596
|
+
const isJsonLikely2 = (jsonStats.curlyBraces >= 2 || jsonStats.curlyBraces >= 1 && hasIncompleteJsonPattern) && jsonStats.colons >= 1 && (jsonStats.keyValueStructure || /{.*:.*}/.test(input) || hasIncompleteJsonPattern);
|
|
597
|
+
return isJsonLikely2;
|
|
598
|
+
};
|
|
599
|
+
var isXmlLikely = (input) => {
|
|
600
|
+
const xmlStats = {
|
|
601
|
+
openingTags: (input.match(/<[^/!?][^>]*?>/g) || []).length,
|
|
602
|
+
closingTags: (input.match(/<\/[^>]+>/g) || []).length,
|
|
603
|
+
selfClosingTags: (input.match(/<[^>]+\/>/g) || []).length,
|
|
604
|
+
xmlNamespaces: (input.match(/xmlns(:[a-zA-Z0-9]+)?=/g) || []).length
|
|
605
|
+
};
|
|
606
|
+
const hasXmlHeader = /^<\?xml.*?\?>/.test(input);
|
|
607
|
+
const isXmlLikely2 = (hasXmlHeader || xmlStats.xmlNamespaces >= 1 || xmlStats.openingTags >= 1) && (xmlStats.openingTags === xmlStats.closingTags || xmlStats.selfClosingTags >= 1);
|
|
608
|
+
return isXmlLikely2;
|
|
609
|
+
};
|
|
610
|
+
var isCsvLikely = (input) => {
|
|
611
|
+
const lines = input.split(/\r?\n/);
|
|
612
|
+
const headerRow = lines[0];
|
|
613
|
+
const csvStats = {
|
|
614
|
+
rowCount: lines.length,
|
|
615
|
+
commaCounts: lines.map((line) => (line.match(/,/g) || []).length)
|
|
616
|
+
};
|
|
617
|
+
const headerStats = {
|
|
618
|
+
curlyBraces: (headerRow.match(/[{}]/g) || []).length,
|
|
619
|
+
squareBrackets: (headerRow.match(/[\[\]]/g) || []).length,
|
|
620
|
+
angularBrackets: (headerRow.match(/[<>]/g) || []).length,
|
|
621
|
+
colons: (headerRow.match(/:/g) || []).length
|
|
622
|
+
};
|
|
623
|
+
const isCsvLikely2 = (csvStats.rowCount > 1 || csvStats.commaCounts.some((count) => count > 0)) && headerStats.curlyBraces === 0 && headerStats.squareBrackets === 0 && headerStats.angularBrackets === 0 && headerStats.colons === 0;
|
|
624
|
+
return isCsvLikely2;
|
|
625
|
+
};
|
|
626
|
+
var FormatDetector = class _FormatDetector {
|
|
627
|
+
static {
|
|
628
|
+
this.typeConverter = new TypeConverter();
|
|
629
|
+
}
|
|
630
|
+
detectContentType(input) {
|
|
631
|
+
const format = this.detectFormat(input);
|
|
632
|
+
return _FormatDetector.typeConverter.contentFormatToContentType(format);
|
|
633
|
+
}
|
|
634
|
+
detectFormat(input) {
|
|
635
|
+
try {
|
|
636
|
+
const trimmedInput = input?.trim();
|
|
637
|
+
if (!trimmedInput) return "unknown" /* UNKNOWN */;
|
|
638
|
+
if (isValidJson(input)) return "json" /* JSON */;
|
|
639
|
+
if (isPossiblyHL7(input)) return "hl7" /* HL7 */;
|
|
640
|
+
if (isJsonLikely(input)) return "json" /* JSON */;
|
|
641
|
+
if (isXmlLikely(input)) return "xml" /* XML */;
|
|
642
|
+
if (isCsvLikely(input)) return "csv" /* CSV */;
|
|
643
|
+
return "unknown" /* UNKNOWN */;
|
|
644
|
+
} catch (e) {
|
|
645
|
+
return "unknown" /* UNKNOWN */;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
detectEditorLanguage(input) {
|
|
649
|
+
const format = this.detectFormat(input);
|
|
650
|
+
switch (format) {
|
|
651
|
+
case "json" /* JSON */:
|
|
652
|
+
return "json" /* JSON */;
|
|
653
|
+
case "xml" /* XML */:
|
|
654
|
+
return "xml" /* XML */;
|
|
655
|
+
default:
|
|
656
|
+
return "plaintext" /* PLAINTEXT */;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
export { FormatConverter, FormatDetector, TypeConverter };
|
|
578
662
|
//# sourceMappingURL=index.mjs.map
|
|
579
663
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outburn/format-converter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A TypeScript library for converting between various data formats including CSV, XML, HL7 v2, and JSON with specialized healthcare message parsing",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
|
+
"browser": "./dist/browser/browser.js",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
9
|
"type": "module",
|
|
9
10
|
"exports": {
|
|
@@ -11,15 +12,25 @@
|
|
|
11
12
|
"types": "./dist/index.d.ts",
|
|
12
13
|
"import": "./dist/index.mjs",
|
|
13
14
|
"require": "./dist/index.cjs"
|
|
14
|
-
}
|
|
15
|
+
},
|
|
16
|
+
"./browser": "./dist/browser/browser.js"
|
|
15
17
|
},
|
|
16
18
|
"scripts": {
|
|
17
19
|
"clean": "rimraf dist",
|
|
18
20
|
"lint": "eslint src",
|
|
19
21
|
"build": "npm run clean && tsup",
|
|
20
22
|
"prepublishOnly": "npm run build",
|
|
21
|
-
"test": "vitest run"
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"demo": "node scripts/browser-demo.mjs"
|
|
22
25
|
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/**/*.cjs",
|
|
28
|
+
"dist/**/*.mjs",
|
|
29
|
+
"dist/**/*.d.ts",
|
|
30
|
+
"dist/browser/**",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
23
34
|
"keywords": [
|
|
24
35
|
"format-converter",
|
|
25
36
|
"data-conversion",
|
|
@@ -28,6 +39,8 @@
|
|
|
28
39
|
"json",
|
|
29
40
|
"hl7",
|
|
30
41
|
"hl7v2",
|
|
42
|
+
"hl7json",
|
|
43
|
+
"hl7toJson",
|
|
31
44
|
"healthcare",
|
|
32
45
|
"parser",
|
|
33
46
|
"typescript",
|
|
@@ -49,13 +62,12 @@
|
|
|
49
62
|
"devDependencies": {
|
|
50
63
|
"@types/node": "^24.10.1",
|
|
51
64
|
"eslint": "^9.39.1",
|
|
52
|
-
"prettier": "^3.7.3",
|
|
53
65
|
"rimraf": "^6.1.2",
|
|
54
66
|
"tsup": "^8.5.1",
|
|
55
67
|
"tsx": "^4.21.0",
|
|
56
68
|
"typescript": "^5.9.3",
|
|
57
69
|
"typescript-eslint": "^8.48.1",
|
|
58
|
-
"vitest": "^4.0.
|
|
70
|
+
"vitest": "^4.0.15"
|
|
59
71
|
},
|
|
60
72
|
"repository": {
|
|
61
73
|
"type": "git",
|
|
@@ -63,4 +75,4 @@
|
|
|
63
75
|
},
|
|
64
76
|
"bugs": "https://github.com/Outburn-IL/format-converter/issues",
|
|
65
77
|
"homepage": "https://github.com/Outburn-IL/format-converter#readme"
|
|
66
|
-
}
|
|
78
|
+
}
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/TypeConverter.ts","../src/converters/csvToJson.ts","../src/converters/xmlToJson.ts","../src/converters/hl7v2/v2parse.ts","../src/converters/hl7v2/getV2DatatypeDef.ts","../src/converters/hl7v2/cache.ts","../src/converters/hl7v2/jsonataExpressions.ts","../src/converters/hl7v2/registerV2key.ts","../src/converters/hl7v2/stringFuncations.ts","../src/converters/hl7v2/v2normalizeKey.ts","../src/converters/hl7v2/v2json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CAAA;AAAA,IAClE,WAAW,oBAAA,KAAA,UAAA,YAA0C;AACnD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,iCAAiC,CAAA;AAClD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,gCAAgC,CAAA;AACjD,MAAA,UAAA,GAAa,MAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA;AACvC,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,kCAAkC,CAAA;AAAA,IACrD,WAAW,oBAAA,KAAA,iBAAA,YAA0C;AACnD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,iCAAiC,CAAA;AAClD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,gCAAgC,CAAA;AACjD,MAAA,UAAA,GAAa,MAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA;AACvC,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,kCAAkC,CAAA;AAAA,IACrD,WAAW,oBAAA,KAAA,kBAAA,aAA2C;AACpD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,kCAAkC,CAAA;AACnD,MAAA,UAAA,GAAa,KAAA;AACb,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,oCAAoC,CAAA;AAAA,IACvD,CAAA,MAAO;AAEL,MAAA,MAAM,IAAI,MAAM,yDAAyD,CAAA;AAAA,IAC3E;AAEA,IAAA,OAAO,UAAA;AAAA,EACT;AAAA,EAIA,UAAU,KAAA,EAA6B;AACrC,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EACxC;AAGF","file":"index.cjs","sourcesContent":["import { ContentFormat, ContentType, EditorLanguage, ITypeConverter } from './types';\r\n\r\nexport class TypeConverter implements ITypeConverter {\r\n private static contentTypeToContentFormatMap: { [key in ContentType]: ContentFormat } = {\r\n [ContentType.JSON]: ContentFormat.JSON,\r\n [ContentType.CSV]: ContentFormat.CSV,\r\n [ContentType.XML]: ContentFormat.XML,\r\n [ContentType.HL7V2]: ContentFormat.HL7\r\n };\r\n\r\n private static contentFormatToContentTypeMap: { [key in ContentFormat]: ContentType | null } = {\r\n [ContentFormat.JSON]: ContentType.JSON,\r\n [ContentFormat.CSV]: ContentType.CSV,\r\n [ContentFormat.XML]: ContentType.XML,\r\n [ContentFormat.HL7]: ContentType.HL7V2,\r\n [ContentFormat.UNKNOWN]: null\r\n };\r\n\r\n private static contentFormatToEditorLanguageMap: { [key in ContentFormat]: EditorLanguage } = {\r\n [ContentFormat.JSON]: EditorLanguage.JSON,\r\n [ContentFormat.XML]: EditorLanguage.XML,\r\n [ContentFormat.CSV]: EditorLanguage.PLAINTEXT,\r\n [ContentFormat.HL7]: EditorLanguage.PLAINTEXT,\r\n [ContentFormat.UNKNOWN]: EditorLanguage.PLAINTEXT\r\n };\r\n\r\n private static contentFormats: ContentFormat[] = [\r\n ContentFormat.JSON,\r\n ContentFormat.CSV,\r\n ContentFormat.XML,\r\n ContentFormat.HL7,\r\n ContentFormat.UNKNOWN\r\n ];\r\n\r\n private static contentTypes: ContentType[] = [\r\n ContentType.JSON,\r\n ContentType.CSV,\r\n ContentType.XML,\r\n ContentType.HL7V2\r\n ];\r\n\r\n private static editorLanguages: EditorLanguage[] = [\r\n EditorLanguage.JSON,\r\n EditorLanguage.XML,\r\n EditorLanguage.PLAINTEXT\r\n ];\r\n\r\n contentTypeToContentFormat(contentType: ContentType): ContentFormat {\r\n return TypeConverter.contentTypeToContentFormatMap[contentType];\r\n }\r\n\r\n contentTypeToEditorLanguage(contentType: ContentType): EditorLanguage {\r\n const format = this.contentTypeToContentFormat(contentType);\r\n return this.contentFormatToEditorLanguage(format);\r\n }\r\n\r\n contentFormatToContentType(format: ContentFormat): ContentType | null {\r\n return TypeConverter.contentFormatToContentTypeMap[format] || null;\r\n }\r\n\r\n contentFormatToEditorLanguage(format: ContentFormat): EditorLanguage {\r\n return TypeConverter.contentFormatToEditorLanguageMap[format];\r\n }\r\n\r\n stringToContentFormat(format: string): ContentFormat | null {\r\n const normalizedFormat = format.toLowerCase();\r\n return TypeConverter.contentFormats.find(value => value === normalizedFormat) || null;\r\n }\r\n\r\n stringToContentType(contentType: string): ContentType | null {\r\n const normalizedContentType = contentType.toLowerCase();\r\n return TypeConverter.contentTypes.find(value => normalizedContentType.startsWith(value)) || null;\r\n }\r\n\r\n stringToEditorLanguage(editorLanguage: string): EditorLanguage | null {\r\n const normalizedLanguage = editorLanguage.toLowerCase();\r\n return TypeConverter.editorLanguages.find(value => value === normalizedLanguage) || null;\r\n }\r\n\r\n}","import csvToJson from 'csvtojson';\r\n\r\nexport const parseCsv = async (csv: string): Promise<any> => {\r\n let json = {};\r\n try {\r\n json = await csvToJson().fromString(csv);\r\n } catch {\r\n json = [];\r\n }\r\n return json;\r\n};","import { XMLParser } from 'fast-xml-parser';\r\n\r\nconst ATTRIBUTE_PREFIX = '@_';\r\n\r\nexport const parseXml = (xml: string) => {\r\n xml = xml?.trim() || '';\r\n if (xml === '') {\r\n return {};\r\n }\r\n \r\n const json = parseXmlWithXhtmlHandling(xml);\r\n\r\n const values: any[] = [];\r\n if (Object.keys(json).length === 1) {\r\n const rootKey = Object.keys(json)[0];\r\n if (Array.isArray(json[rootKey])) {\r\n for (const jsonValue of json[rootKey]) {\r\n values.push(standardizeJson(jsonValue, rootKey));\r\n }\r\n } else {\r\n values.push(standardizeJson(json[rootKey], rootKey));\r\n }\r\n }\r\n\r\n if (Object.keys(json).length > 1) {\r\n for (const rootKey of Object.keys(json)) {\r\n values.push(standardizeJson(json[rootKey], rootKey));\r\n }\r\n }\r\n\r\n return values.length === 1 ? values[0] : values;\r\n};\r\n\r\nconst parseXmlWithXhtmlHandling = (xml: string): any => {\r\n const options: Record<string, any> = {\r\n ignoreAttributes: false,\r\n ignoreDeclaration: true,\r\n attributeNamePrefix: ATTRIBUTE_PREFIX,\r\n allowBooleanAttributes: true,\r\n alwaysCreateTextNode: true,\r\n numberParseOptions: {\r\n leadingZeros: false,\r\n hex: false,\r\n skipLike: /\\*/\r\n }\r\n };\r\n const firstParser = new XMLParser(options);\r\n const firstParsing = firstParser.parse(xml, true);\r\n const xhtmlPaths = getXhtmlPaths('', firstParsing, []);\r\n\r\n if (xhtmlPaths.length === 0) {\r\n return firstParsing;\r\n }\r\n\r\n options.stopNodes = [...new Set(xhtmlPaths)]; // remove duplications;\r\n const secondParser = new XMLParser(options);\r\n const secondParsing = secondParser.parse(xml);\r\n return secondParsing;\r\n};\r\n\r\nconst getXhtmlPaths = (currentPath, currentValue, xhtmlPaths) => {\r\n if (Array.isArray(currentValue)) {\r\n for (let i = 0; i < currentValue.length; i++) {\r\n getXhtmlPaths(`${currentPath}`, currentValue[i], xhtmlPaths);\r\n }\r\n } else if (typeof currentValue === 'object') {\r\n if (currentValue[`${ATTRIBUTE_PREFIX}xmlns`] === 'http://www.w3.org/1999/xhtml') {\r\n xhtmlPaths.push(currentPath);\r\n } else {\r\n for (const key of Object.keys(currentValue)) {\r\n getXhtmlPaths(`${currentPath ? `${currentPath}.` : ''}${key}`, currentValue[key], xhtmlPaths);\r\n }\r\n }\r\n }\r\n return xhtmlPaths;\r\n};\r\n\r\nconst standardizeJson = (json, rootKey: string): Record<string, any> => {\r\n const parsedXml = recursiveStandardize(json, rootKey);\r\n\r\n const namespaceIndex = rootKey.indexOf(':');\r\n const baseRootKey = namespaceIndex === -1 ? rootKey : rootKey.slice(namespaceIndex + 1);\r\n\r\n const value = parsedXml[baseRootKey];\r\n if (typeof value === 'object') {\r\n const namespaceIndex = rootKey.indexOf(':');\r\n if (namespaceIndex !== -1) {\r\n value._namespace = rootKey.slice(0, namespaceIndex);\r\n if (!value.resourceType) {\r\n value._xmlTagName = baseRootKey;\r\n }\r\n } else if (!value.resourceType) {\r\n value._xmlTagName = baseRootKey;\r\n }\r\n }\r\n return value;\r\n};\r\n\r\nconst recursiveStandardize = (node: any, key: string) => {\r\n const newNode: Record<string, any | any[]> = {};\r\n let newKey: string = key;\r\n\r\n // extract values and attributes\r\n let textValue: any | undefined;\r\n const complexValue = {};\r\n let valueAttribute: string | undefined;\r\n const attributes: Record<string, any> = {};\r\n for (const key of Object.keys(node)) {\r\n if (key === '#text' && (typeof node[key] !== 'string' || node[key].length > 0)) {\r\n textValue = String(node[key]);\r\n } else if (key.startsWith(ATTRIBUTE_PREFIX)) {\r\n attributes[key.slice(ATTRIBUTE_PREFIX.length)] = node[key];\r\n if (key === `${ATTRIBUTE_PREFIX}value`) {\r\n valueAttribute = node[key];\r\n }\r\n } else {\r\n complexValue[key] = node[key];\r\n }\r\n }\r\n\r\n // extract namespace\r\n const namespaceIndex = key.indexOf(':');\r\n let namespaceValue;\r\n if (namespaceIndex !== -1) {\r\n newKey = key.slice(namespaceIndex + 1);\r\n namespaceValue = key.slice(0, namespaceIndex);\r\n }\r\n\r\n // extract complex childs\r\n const complexChildsObject = createComplexChildsObject(complexValue);\r\n\r\n // replace xmlns=\"http://hl7.org/fhir\" with resourceType\r\n if (attributes.xmlns === 'http://hl7.org/fhir') {\r\n attributes.resourceType = newKey;\r\n delete attributes.xmlns;\r\n }\r\n\r\n // build new node\r\n if (textValue && attributes.xmlns === 'http://www.w3.org/1999/xhtml') {\r\n textValue = `<${key}${buildAttributesString(attributes)}>${textValue}</${key}>`;\r\n newNode[newKey] = textValue;\r\n } else if (textValue) {\r\n newNode[newKey] = textValue;\r\n addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, `_${newKey}`, attributes);\r\n } else if (valueAttribute) {\r\n newNode[newKey] = valueAttribute;\r\n addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });\r\n delete attributes.value;\r\n addInnerKeys(newNode, `_${newKey}`, attributes);\r\n addInnerKeys(newNode, `_${newKey}`, complexChildsObject);\r\n } else if (Object.keys(complexChildsObject).length > 0) {\r\n addInnerKeys(newNode, newKey, complexChildsObject);\r\n addInnerKeys(newNode, newKey, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, newKey, attributes);\r\n } else if (Object.keys(attributes).length > 0) {\r\n addInnerKeys(newNode, newKey, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, newKey, attributes);\r\n }\r\n return newNode;\r\n};\r\n\r\nconst createComplexChildsObject = (complexChilds) => {\r\n const complexChildsObject = {};\r\n for (const childKey of Object.keys(complexChilds)) {\r\n if (Array.isArray(complexChilds[childKey])) {\r\n const childValues = complexChilds[childKey];\r\n for (const childValue of childValues) {\r\n const child = recursiveStandardize(childValue, childKey);\r\n addChildToParent(complexChildsObject, child);\r\n }\r\n } else {\r\n const child = recursiveStandardize(complexChilds[childKey], childKey);\r\n addChildToParent(complexChildsObject, child);\r\n }\r\n }\r\n return complexChildsObject;\r\n};\r\n// /_xmlTagName\r\n\r\nconst addChildToParent = (parentNode, child) => {\r\n const childKey: string | undefined = Object.keys(child).find(key => !key.startsWith('_'));\r\n const childAttKey: string | undefined = Object.keys(child).find(key => key.startsWith('_'));\r\n\r\n if (childKey === undefined && childAttKey === undefined) return;\r\n const key = childKey ?? childAttKey!.slice(1);\r\n const attKey = childAttKey ?? `_${childKey}`;\r\n\r\n if ((parentNode[key]) || (parentNode[attKey])) {\r\n const keySize = parentNode[key] ? (Array.isArray(parentNode[key]) ? parentNode[key].length : 1) : 0;\r\n const attKeySize = parentNode[attKey] ? (Array.isArray(parentNode[attKey]) ? parentNode[attKey].length : 1) : 0;\r\n\r\n if (keySize > 1) {\r\n parentNode[key].push(child[key] ?? null);\r\n } else if (keySize === 1) {\r\n parentNode[key] = [parentNode[key], child[key] ?? null];\r\n } else if (childKey) {\r\n parentNode[key] = Array.from({ length: attKeySize }, (x, i) => null);\r\n parentNode[key].push(child[key] ?? null);\r\n }\r\n\r\n if (attKeySize > 1) {\r\n parentNode[attKey].push(child[attKey] ?? null);\r\n } else if (attKeySize === 1) {\r\n parentNode[attKey] = [parentNode[attKey], child[attKey] ?? null];\r\n } else if (childAttKey) {\r\n parentNode[attKey] = Array.from({ length: keySize }, (x, i) => null);\r\n parentNode[attKey].push(child[attKey] ?? null);\r\n }\r\n } else {\r\n if (childKey) {\r\n parentNode[key] = child[key];\r\n }\r\n if (childAttKey) {\r\n parentNode[attKey] = child[attKey];\r\n }\r\n }\r\n};\r\n\r\nconst addInnerKeys = (object, key, innerObject) => {\r\n for (const innerKey of Object.keys(innerObject)) {\r\n addInnerKey(object, key, innerKey, innerObject[innerKey]);\r\n }\r\n};\r\n\r\nconst addInnerKey = (object, key, innerKey, innerValue) => {\r\n if (innerValue === undefined) return;\r\n if (object[key] === undefined) {\r\n object[key] = {};\r\n }\r\n\r\n if (innerKey === 'resourceType') {\r\n object[key] = {\r\n resourceType: innerValue,\r\n ...object[key]\r\n };\r\n } else {\r\n object[key][innerKey] = innerValue;\r\n }\r\n};\r\n\r\nconst buildAttributesString = (attributs) => {\r\n let string = '';\r\n for (const key of Object.keys(attributs)) {\r\n string += ` ${key}=\"${attributs[key]}\"`;\r\n }\r\n return string;\r\n};\r\n","import hl7js from 'hl7js';\r\n\r\nexport const v2parse = async (msg: string): Promise<object> => {\r\n // parses hl7 v2 to raw json (without field names, only numbers)\r\n msg = msg.replace(/(?:\\r\\n|\\r|\\n)/g, '\\r\\n');\r\n\r\n // Create a new Reader instance for each parse operation to avoid race conditions\r\n const v2reader = new hl7js.Reader('BASIC');\r\n\r\n return await new Promise<object>((resolve, reject) => {\r\n v2reader.read(msg, function (err, hl7Data) {\r\n if (err) {\r\n reject(new Error(`Transformation error: ${JSON.stringify(err)}`));\r\n return;\r\n };\r\n return resolve(hl7Data);\r\n });\r\n });\r\n};","import HL7Dictionary from 'hl7-dictionary';\r\n\r\nexport const getV2DatatypeDef = (datatype: string, v2version: string) => {\r\n return HL7Dictionary.definitions[v2version].fields[datatype];\r\n};\r\n","export interface ICache<T> {\r\n get: (key: string) => T\r\n set: (key: string, value: T) => void\r\n getDict: () => Record<string, T>\r\n}\r\n\r\nclass SimpleCache<T> implements ICache<T> {\r\n private cache: Record<string, any> = {};\r\n\r\n get = (key: string) => this.cache[key];\r\n set = (key: string, value: any) => this.cache[key] = value;\r\n getDict = () => this.cache;\r\n}\r\n\r\nconst v2keyMap: ICache<string> = new SimpleCache<string>();\r\n\r\nconst cache = { v2keyMap };\r\n\r\nexport const getCache = () => cache;","import jsonata from 'jsonata';\r\n\r\nexport const expressions = {\r\n\r\n v2jsonExpression: jsonata(`(\r\n $rawJson := $v2parse($);\r\n $v2version := $rawJson.segments[0].\\`12\\`;\r\n\r\n $dtToIso := function($dt){(\r\n $y := $substring($dt,0,4);\r\n $m := $substring($dt,4,2);\r\n $d := $substring($dt,6,2);\r\n $join([$y,$m,$d],'-')\r\n )};\r\n\r\n $dtmToIso := function($dtm){(\r\n $dt := $dtToIso($dtm);\r\n $hh := $substring($dtm,8,2);\r\n $mm := $substring($dtm,10,2);\r\n $ss := $substring($dtm,12,2);\r\n $tm := $join([($hh!=''?$hh),($mm!=''?$mm),($ss!=''?$ss)],':');\r\n $dt & ($tm!=''? 'T' & $tm)\r\n )};\r\n\r\n $parseValue := function($value, $datatype){( \r\n $value = '' \r\n ? \r\n undefined \r\n : $value.(\r\n $datatype = 'DT' ? $dtToIso($) : ($datatype = 'DTM' ? $dtmToIso($) : $)\r\n )\r\n )};\r\n\r\n $translateSubfield := function($subfield, $datatypeDef, $sfi){(\r\n $subfieldDef := $datatypeDef.subfields[$sfi];\r\n $subfieldDesc := $subfieldDef.desc;\r\n $subfieldDatatype := $subfieldDef.datatype;\r\n $sfDataTypeDef := $getDatatypeDef($subfieldDatatype, $v2version);\r\n $isComplex := $count($sfDataTypeDef.subfields)>0;\r\n $hasChildren := $count($subfield.fields)>0;\r\n\r\n $value := (\r\n $isComplex = false \r\n ? $parseValue($subfield.value, $subfieldDatatype)\r\n : (\r\n /* it's a complex type */\r\n $hasChildren \r\n ? ( \r\n /* input has children */\r\n $subfield.fields@$subsubfield#$ssfi.$translateSubfield($subsubfield, $sfDataTypeDef, $ssfi){\r\n $normalizeKey(name): value\r\n };\r\n )\r\n : ( \r\n /* input doesn't have children */\r\n $translateSubfield({'value': $subfield.value}, $sfDataTypeDef, 0){\r\n $normalizeKey(name): value\r\n }\r\n )\r\n ) \r\n );\r\n\r\n {\r\n 'name': $subfieldDesc,\r\n 'value': $value != {} ? $value\r\n }\r\n )};\r\n\r\n $translateField := function($field, $segDef, $fieldIndex){(\r\n $fieldDef := $segDef.fields[$fieldIndex];\r\n $fieldDef := $exists($fieldDef)=false ? {'name': $segDef.segmentId & ($fieldIndex + 1)} : $fieldDef;\r\n $fieldDesc := $fieldDef.desc ? $fieldDef.desc : $fieldDef.name;\r\n $fieldDesc := $type($fieldDesc) = 'string' and $startsWith($fieldDesc,'Set ID - ') and $fieldIndex=0 ? 'SetID' : $fieldDesc;\r\n $fieldDatatype := $fieldDef.datatype;\r\n $datatypeDef := $getDatatypeDef($fieldDatatype, $v2version);\r\n $isEnc := $segDef.segmentId='MSH' and $fieldIndex=1;\r\n $isComplex := $count($datatypeDef.subfields)>0;\r\n $hasChildren := $count($field.fields)>0;\r\n\r\n $value := (\r\n $isEnc ? $field.value : (\r\n $isComplex = false \r\n ? $parseValue($field.value, $fieldDatatype)\r\n : (\r\n /* it's a complex type */\r\n $hasChildren \r\n ? ( \r\n /* input has children */\r\n $field.fields@$subfield#$sfi.$translateSubfield($subfield, $datatypeDef, $sfi){\r\n $normalizeKey(name): value\r\n };\r\n )\r\n : ( \r\n /* input doesn't have children */\r\n $translateSubfield({'value': $field.value}, $datatypeDef, 0){\r\n $normalizeKey(name): value\r\n }\r\n )\r\n )\r\n )\r\n );\r\n $value := $value = {} ? undefined : $value;\r\n \r\n {\r\n 'name': $fieldDesc,\r\n 'value': $value\r\n };\r\n )};\r\n\r\n $translateSegment := function($segment){(\r\n $line := $segment.MessageLine;\r\n $segId := $segment.\\`0\\`;\r\n $segDef := $getSegmentDef($segId, $v2version);\r\n $segment.fields#$i[$i>0].$translateField($, $segDef, $i-1){\r\n 'SegmentDescription': $segDef.desc,\r\n 'MessageLine': $line,\r\n $normalizeKey(name): value\r\n }\r\n )};\r\n \r\n $segmentsWithLines := $rawJson.segments#$line.($merge([$, {'MessageLine': $line+1}]));\r\n\r\n $segmentsWithLines@$s.$translateSegment($s){\r\n $s.\\`0\\`: $\r\n };\r\n )`),\r\n\r\n v2normalizeKey: jsonata(`(\r\n $cached := $lookup($keyMap, $);\r\n $exists($cached) = false \r\n ? (\r\n $titleCased := ($split($initCap($replace($,\"'\", '')), ' ')~>$join);\r\n $dtmFixed := $titleCased.$replace('Date/Time', 'DateTime') ~> $replace('Date / Time', 'DateTime');$underscored := $replace($dtmFixed, /[-\\+\".()\\\\//]/, '_');\r\n $registerV2key($, $underscored);\r\n $underscored;\r\n )\r\n : ($cached);\r\n )`),\r\n\r\n initCap: jsonata(`(\r\n $words := $trim($)~>$split(\" \");\r\n ($words.$initCapOnce($))~>$join(' ')\r\n )`)\r\n};","import { getCache } from './cache';\r\n\r\nexport const registerV2key = (key, normalized) => {\r\n getCache().v2keyMap.set(key, normalized);\r\n};\r\n","import { expressions } from './jsonataExpressions';\r\n\r\nexport const startsWith = (str: string | undefined, startStr: string): boolean | undefined => {\r\n if (typeof str === 'undefined') return undefined;\r\n return str.startsWith(startStr);\r\n};\r\n\r\nexport const initCapOnce = (str: string): string => {\r\n return str[0].toUpperCase() + str.slice(1);\r\n};\r\n\r\nexport const initCap = (str: string): Promise<string> => {\r\n return expressions.initCap.evaluate(str, { initCapOnce });\r\n};","import { getCache } from './cache';\r\nimport { expressions } from './jsonataExpressions';\r\nimport { registerV2key } from './registerV2key';\r\nimport { initCap } from './stringFuncations';\r\n\r\nexport const v2normalizeKey = async (key: string) => {\r\n const bindings = {\r\n initCap,\r\n registerV2key,\r\n keyMap: getCache().v2keyMap.getDict()\r\n };\r\n const res = await expressions.v2normalizeKey.evaluate(key, bindings);\r\n return res;\r\n};\r\n","import HL7Dictionary from 'hl7-dictionary';\r\n\r\nimport { v2parse } from './v2parse';\r\nimport { getV2DatatypeDef } from './getV2DatatypeDef';\r\nimport { v2normalizeKey } from './v2normalizeKey';\r\nimport { startsWith } from './stringFuncations';\r\nimport { expressions } from './jsonataExpressions';\r\n\r\nconst getV2SegmentDef = (segmentId: string, v2version: string) => {\r\n const segDef = HL7Dictionary.definitions[v2version].segments[segmentId];\r\n return { segmentId, ...segDef };\r\n};\r\n\r\nexport const v2json = async (message: string) => {\r\n const bindings = {\r\n v2parse,\r\n startsWith,\r\n normalizeKey: v2normalizeKey,\r\n getSegmentDef: getV2SegmentDef,\r\n getDatatypeDef: getV2DatatypeDef\r\n };\r\n\r\n const res = await expressions.v2jsonExpression.evaluate(message, bindings);\r\n return res;\r\n};\r\n","import { parseCsv, parseXml, v2json } from './converters';\r\nimport { TypeConverter } from './TypeConverter';\r\nimport { ContentType, IFormatConverter, ILogger, ITypeConverter } from './types';\r\n\r\nconst noopLogger: ILogger = {\r\n info: () => {},\r\n warn: () => {},\r\n error: () => {},\r\n};\r\n\r\nexport class FormatConverter implements IFormatConverter {\r\n private static readonly typeConverter: ITypeConverter = new TypeConverter();\r\n private logger: ILogger;\r\n\r\n constructor(logger?: ILogger) {\r\n this.logger = logger || noopLogger;\r\n }\r\n\r\n async toJson(input: any, contentType?: ContentType | string): Promise<any> {\r\n if (!contentType || contentType === '') {\r\n this.logger.info('No content type provided, defaulting to \\'application/json\\'');\r\n contentType = ContentType.JSON;\r\n }\r\n const suggestedContentType = typeof contentType === 'string'\r\n ? FormatConverter.typeConverter.stringToContentType(contentType)\r\n : contentType;\r\n if (!suggestedContentType) {\r\n throw new Error(`Unsupported Content-Type: ${suggestedContentType}`);\r\n }\r\n\r\n let parsedJson: any;\r\n if (suggestedContentType === ContentType.HL7V2) {\r\n this.logger.info('Content-Type suggests HL7 V2.x message');\r\n this.logger.info('Trying to parse HL7 V2.x message as JSON...');\r\n parsedJson = await this.hl7v2ToJson(input);\r\n this.logger.info('Parsed HL7 V2.x message to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.CSV) {\r\n this.logger.info('Content-Type suggests CSV input');\r\n this.logger.info('Trying to parse CSV as JSON...');\r\n parsedJson = await this.csvToJson(input);\r\n this.logger.info('Parsed CSV to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.XML) {\r\n this.logger.info('Content-Type suggests XML input');\r\n this.logger.info('Trying to parse XML as JSON...');\r\n parsedJson = await this.xmlToJson(input);\r\n this.logger.info('Parsed XML to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.JSON) {\r\n this.logger.info('Content-Type suggests JSON input');\r\n parsedJson = input;\r\n this.logger.info('Parsed input to JSON successfully.');\r\n } else {\r\n // should never reach here\r\n throw new Error('Unsupported Content-Type encountered during processing.');\r\n }\r\n\r\n return parsedJson;\r\n }\r\n\r\n csvToJson = parseCsv;\r\n\r\n xmlToJson(input: string): Promise<any> {\r\n return Promise.resolve(parseXml(input));\r\n }\r\n\r\n hl7v2ToJson = v2json;\r\n}"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
interface ILogger {
|
|
2
|
-
info: (msg: any) => void;
|
|
3
|
-
warn: (msg: any) => void;
|
|
4
|
-
error: (msg: any) => void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
declare const enum ContentFormat {
|
|
8
|
-
JSON = "json",
|
|
9
|
-
CSV = "csv",
|
|
10
|
-
XML = "xml",
|
|
11
|
-
HL7 = "hl7",
|
|
12
|
-
UNKNOWN = "unknown"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare const enum ContentType {
|
|
16
|
-
JSON = "application/json",
|
|
17
|
-
CSV = "text/csv",
|
|
18
|
-
XML = "application/xml",
|
|
19
|
-
HL7V2 = "x-application/hl7-v2+er7"
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declare const enum EditorLanguage {
|
|
23
|
-
JSON = "json",
|
|
24
|
-
XML = "xml",
|
|
25
|
-
PLAINTEXT = "plaintext"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface IFormatConverter {
|
|
29
|
-
toJson: (input: any, contentType?: ContentType | string) => Promise<any>;
|
|
30
|
-
/**
|
|
31
|
-
* Converts CSV string to JSON object. If conversion fails, returns empty array.
|
|
32
|
-
* @param input CSV string to be converted
|
|
33
|
-
* @returns Promise resolving to JSON object
|
|
34
|
-
*/
|
|
35
|
-
csvToJson: (input: string) => Promise<any>;
|
|
36
|
-
xmlToJson: (input: string) => Promise<any>;
|
|
37
|
-
hl7v2ToJson: (message: string) => Promise<any>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface ITypeConverter {
|
|
41
|
-
contentTypeToContentFormat: (contentType: ContentType) => ContentFormat;
|
|
42
|
-
contentTypeToEditorLanguage: (contentType: ContentType) => EditorLanguage;
|
|
43
|
-
contentFormatToContentType: (format: ContentFormat) => ContentType | null;
|
|
44
|
-
contentFormatToEditorLanguage: (format: ContentFormat) => EditorLanguage;
|
|
45
|
-
stringToContentFormat: (format: string) => ContentFormat | null;
|
|
46
|
-
stringToContentType: (contentType: string) => ContentType | null;
|
|
47
|
-
stringToEditorLanguage: (editorLanguage: string) => EditorLanguage | null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
declare class TypeConverter implements ITypeConverter {
|
|
51
|
-
private static contentTypeToContentFormatMap;
|
|
52
|
-
private static contentFormatToContentTypeMap;
|
|
53
|
-
private static contentFormatToEditorLanguageMap;
|
|
54
|
-
private static contentFormats;
|
|
55
|
-
private static contentTypes;
|
|
56
|
-
private static editorLanguages;
|
|
57
|
-
contentTypeToContentFormat(contentType: ContentType): ContentFormat;
|
|
58
|
-
contentTypeToEditorLanguage(contentType: ContentType): EditorLanguage;
|
|
59
|
-
contentFormatToContentType(format: ContentFormat): ContentType | null;
|
|
60
|
-
contentFormatToEditorLanguage(format: ContentFormat): EditorLanguage;
|
|
61
|
-
stringToContentFormat(format: string): ContentFormat | null;
|
|
62
|
-
stringToContentType(contentType: string): ContentType | null;
|
|
63
|
-
stringToEditorLanguage(editorLanguage: string): EditorLanguage | null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declare class FormatConverter implements IFormatConverter {
|
|
67
|
-
private static readonly typeConverter;
|
|
68
|
-
private logger;
|
|
69
|
-
constructor(logger?: ILogger);
|
|
70
|
-
toJson(input: any, contentType?: ContentType | string): Promise<any>;
|
|
71
|
-
csvToJson: (csv: string) => Promise<any>;
|
|
72
|
-
xmlToJson(input: string): Promise<any>;
|
|
73
|
-
hl7v2ToJson: (message: string) => Promise<any>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export { FormatConverter, TypeConverter };
|