@outburn/format-converter 1.0.6 → 2.0.0
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 +23 -2
- package/dist/browser.d.ts +166 -0
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +2 -0
- package/dist/index.cjs +81 -45
- package/dist/index.d.ts +50 -18
- package/dist/index.mjs +81 -45
- package/package.json +12 -8
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ import { FormatConverter, TypeConverter, FormatDetector } from '@outburn/format-
|
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
### Browser (Limited functionality)
|
|
30
|
+
|
|
31
|
+
**Using IIFE (script tag):**
|
|
30
32
|
```html
|
|
31
33
|
<script src="node_modules/@outburn/format-converter/dist/browser.js"></script>
|
|
32
34
|
<script>
|
|
@@ -35,12 +37,31 @@ const { TypeConverter, FormatDetector } = FormatUtils;
|
|
|
35
37
|
</script>
|
|
36
38
|
```
|
|
37
39
|
|
|
40
|
+
**Using ESM (module import):**
|
|
41
|
+
```typescript
|
|
42
|
+
import { TypeConverter, FormatDetector } from '@outburn/format-converter/browser';
|
|
43
|
+
// FormatConverter is not available in browser due to HL7.js dependency
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Available exports:**
|
|
47
|
+
```typescript
|
|
48
|
+
// Classes
|
|
49
|
+
import { TypeConverter, FormatDetector } from '@outburn/format-converter/browser';
|
|
50
|
+
|
|
51
|
+
// Types
|
|
52
|
+
import type { ITypeConverter, IFormatDetector } from '@outburn/format-converter/browser';
|
|
53
|
+
|
|
54
|
+
// Enums
|
|
55
|
+
import { ContentType, ContentFormat, EditorLanguage } from '@outburn/format-converter/browser';
|
|
56
|
+
```
|
|
57
|
+
|
|
38
58
|
**Browser limitations:**
|
|
39
59
|
- ❌ `FormatConverter` is not available (requires HL7.js which is not browser-compatible)
|
|
40
60
|
- ❌ HL7 v2 parsing and conversion
|
|
41
61
|
- ✅ `TypeConverter` for type detection and conversion
|
|
42
62
|
- ✅ `FormatDetector` for format detection (JSON, XML, CSV, HL7)
|
|
43
|
-
- ✅ All type definitions and enums
|
|
63
|
+
- ✅ All type definitions and enums (`ContentType`, `ContentFormat`, `EditorLanguage`)
|
|
64
|
+
- ✅ TypeScript interfaces (`ITypeConverter`, `IFormatDetector`)
|
|
44
65
|
|
|
45
66
|
For full functionality including HL7 processing, use the Node.js version.
|
|
46
67
|
|
|
@@ -346,7 +367,7 @@ npm run lint
|
|
|
346
367
|
|
|
347
368
|
## License
|
|
348
369
|
MIT
|
|
349
|
-
© Outburn Ltd.
|
|
370
|
+
© Outburn Ltd. 2025. All Rights Reserved.
|
|
350
371
|
|
|
351
372
|
## Disclaimer
|
|
352
373
|
This project is part of the [FUME](https://github.com/Outburn-IL/fume-community) open-source initiative and intended for use in FHIR tooling and development environments.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of supported content formats for detection and conversion.
|
|
3
|
+
* Used by format detection algorithms to categorize input data and determine
|
|
4
|
+
* appropriate conversion strategies.
|
|
5
|
+
*/
|
|
6
|
+
declare const ContentFormat: {
|
|
7
|
+
/** JavaScript Object Notation format */
|
|
8
|
+
readonly JSON: "json";
|
|
9
|
+
/** Comma-Separated Values format */
|
|
10
|
+
readonly CSV: "csv";
|
|
11
|
+
/** eXtensible Markup Language format */
|
|
12
|
+
readonly XML: "xml";
|
|
13
|
+
/** Health Level 7 Version 2.x message format */
|
|
14
|
+
readonly HL7: "hl7";
|
|
15
|
+
/** Unknown or unsupported format */
|
|
16
|
+
readonly UNKNOWN: "unknown";
|
|
17
|
+
};
|
|
18
|
+
type ContentFormat = typeof ContentFormat[keyof typeof ContentFormat];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Enumeration of supported MIME types/content types for data format identification.
|
|
22
|
+
* These values correspond to standard HTTP Content-Type header values and are used
|
|
23
|
+
* for format detection and conversion operations.
|
|
24
|
+
*/
|
|
25
|
+
declare const ContentType: {
|
|
26
|
+
/** Standard MIME type for JSON data */
|
|
27
|
+
readonly JSON: "application/json";
|
|
28
|
+
/** Standard MIME type for CSV data */
|
|
29
|
+
readonly CSV: "text/csv";
|
|
30
|
+
/** Standard MIME type for XML data */
|
|
31
|
+
readonly XML: "application/xml";
|
|
32
|
+
/** Custom MIME type for HL7 Version 2.x messages in ER7 encoding */
|
|
33
|
+
readonly HL7V2: "x-application/hl7-v2+er7";
|
|
34
|
+
};
|
|
35
|
+
type ContentType = typeof ContentType[keyof typeof ContentType];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Enumeration of supported editor language identifiers for syntax highlighting and editor configuration.
|
|
39
|
+
* These values are used to determine the appropriate language mode for displaying content
|
|
40
|
+
* in code editors or other text editing interfaces.
|
|
41
|
+
*/
|
|
42
|
+
declare const EditorLanguage: {
|
|
43
|
+
/** JSON language mode for syntax highlighting */
|
|
44
|
+
readonly JSON: "json";
|
|
45
|
+
/** XML language mode for syntax highlighting */
|
|
46
|
+
readonly XML: "xml";
|
|
47
|
+
/** Plain text mode with no syntax highlighting */
|
|
48
|
+
readonly PLAINTEXT: "plaintext";
|
|
49
|
+
};
|
|
50
|
+
type EditorLanguage = typeof EditorLanguage[keyof typeof EditorLanguage];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Interface for format detection operations, providing methods to analyze and identify
|
|
54
|
+
* various aspects of input data including content type, format, and appropriate editor language.
|
|
55
|
+
*/
|
|
56
|
+
interface IFormatDetector {
|
|
57
|
+
/**
|
|
58
|
+
* Detects the content type of the given input string.
|
|
59
|
+
* @param input Input string to analyze
|
|
60
|
+
* @returns Detected ContentType or null if undetectable
|
|
61
|
+
*/
|
|
62
|
+
detectContentType: (input: string) => ContentType | null;
|
|
63
|
+
/**
|
|
64
|
+
* Detects the content format of the given input string.
|
|
65
|
+
* @param input Input string to analyze
|
|
66
|
+
* @returns Detected ContentFormat
|
|
67
|
+
*/
|
|
68
|
+
detectFormat: (input: string) => ContentFormat;
|
|
69
|
+
/**
|
|
70
|
+
* Detects the appropriate editor language for the given input string.
|
|
71
|
+
* @param input Input string to analyze
|
|
72
|
+
* @returns Detected EditorLanguage
|
|
73
|
+
*/
|
|
74
|
+
detectEditorLanguage: (input: string) => EditorLanguage;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Interface for type conversion operations, providing methods to convert between
|
|
79
|
+
* different content type representations (ContentType, ContentFormat, EditorLanguage, and string).
|
|
80
|
+
*/
|
|
81
|
+
interface ITypeConverter {
|
|
82
|
+
/**
|
|
83
|
+
* Converts a ContentType to its corresponding ContentFormat.
|
|
84
|
+
* @param contentType The ContentType to convert
|
|
85
|
+
* @returns The corresponding ContentFormat
|
|
86
|
+
*/
|
|
87
|
+
contentTypeToContentFormat: (contentType: ContentType) => ContentFormat;
|
|
88
|
+
/**
|
|
89
|
+
* Converts a ContentType to its corresponding EditorLanguage.
|
|
90
|
+
* @param contentType The ContentType to convert
|
|
91
|
+
* @returns The corresponding EditorLanguage
|
|
92
|
+
*/
|
|
93
|
+
contentTypeToEditorLanguage: (contentType: ContentType) => EditorLanguage;
|
|
94
|
+
/**
|
|
95
|
+
* Converts a ContentFormat to its corresponding ContentType.
|
|
96
|
+
* @param format The ContentFormat to convert
|
|
97
|
+
* @returns The corresponding ContentType, or null if conversion is not possible
|
|
98
|
+
*/
|
|
99
|
+
contentFormatToContentType: (format: ContentFormat) => ContentType | null;
|
|
100
|
+
/**
|
|
101
|
+
* Converts a ContentFormat to its corresponding EditorLanguage.
|
|
102
|
+
* @param format The ContentFormat to convert
|
|
103
|
+
* @returns The corresponding EditorLanguage
|
|
104
|
+
*/
|
|
105
|
+
contentFormatToEditorLanguage: (format: ContentFormat) => EditorLanguage;
|
|
106
|
+
/**
|
|
107
|
+
* Converts a string representation to its corresponding ContentFormat.
|
|
108
|
+
* @param format The string representation of a format
|
|
109
|
+
* @returns The corresponding ContentFormat, or null if conversion is not possible
|
|
110
|
+
*/
|
|
111
|
+
stringToContentFormat: (format: string) => ContentFormat | null;
|
|
112
|
+
/**
|
|
113
|
+
* Converts a string representation to its corresponding ContentType.
|
|
114
|
+
* @param contentType The string representation of a content type
|
|
115
|
+
* @returns The corresponding ContentType, or null if conversion is not possible
|
|
116
|
+
*/
|
|
117
|
+
stringToContentType: (contentType: string) => ContentType | null;
|
|
118
|
+
/**
|
|
119
|
+
* Converts a string representation to its corresponding EditorLanguage.
|
|
120
|
+
* @param editorLanguage The string representation of an editor language
|
|
121
|
+
* @returns The corresponding EditorLanguage, or null if conversion is not possible
|
|
122
|
+
*/
|
|
123
|
+
stringToEditorLanguage: (editorLanguage: string) => EditorLanguage | null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
declare class TypeConverter implements ITypeConverter {
|
|
127
|
+
private static contentTypeToContentFormatMap;
|
|
128
|
+
private static contentFormatToContentTypeMap;
|
|
129
|
+
private static contentFormatToEditorLanguageMap;
|
|
130
|
+
private static contentFormats;
|
|
131
|
+
private static contentTypes;
|
|
132
|
+
private static editorLanguages;
|
|
133
|
+
contentTypeToContentFormat(contentType: ContentType): ContentFormat;
|
|
134
|
+
contentTypeToEditorLanguage(contentType: ContentType): EditorLanguage;
|
|
135
|
+
contentFormatToContentType(format: ContentFormat): ContentType | null;
|
|
136
|
+
contentFormatToEditorLanguage(format: ContentFormat): EditorLanguage;
|
|
137
|
+
stringToContentFormat(format: string): ContentFormat | null;
|
|
138
|
+
stringToContentType(contentType: string): ContentType | null;
|
|
139
|
+
stringToEditorLanguage(editorLanguage: string): EditorLanguage | null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A service class responsible for detecting and identifying various content formats and types.
|
|
144
|
+
*
|
|
145
|
+
* The FormatDetector analyzes input strings to determine their format (JSON, XML, CSV, HL7, etc.)
|
|
146
|
+
* and provides corresponding content types and editor language mappings. It uses a series of
|
|
147
|
+
* validation functions to identify the most likely format of the input data.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const detector = new FormatDetector();
|
|
152
|
+
* const format = detector.detectFormat('{"key": "value"}');
|
|
153
|
+
* // Returns: ContentFormat.JSON
|
|
154
|
+
*
|
|
155
|
+
* const contentType = detector.detectContentType('<root></root>');
|
|
156
|
+
* // Returns: ContentType corresponding to XML format
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare class FormatDetector implements IFormatDetector {
|
|
160
|
+
private static readonly typeConverter;
|
|
161
|
+
detectContentType(input: string): ContentType | null;
|
|
162
|
+
detectFormat(input: string): ContentFormat;
|
|
163
|
+
detectEditorLanguage(input: string): EditorLanguage;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { ContentFormat, ContentType, EditorLanguage, FormatDetector, type IFormatDetector, type ITypeConverter, TypeConverter };
|
package/dist/browser.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var FormatUtils=(function(exports){'use strict';var
|
|
1
|
+
var FormatUtils=(function(exports){'use strict';var r={JSON:"application/json",CSV:"text/csv",XML:"application/xml",HL7V2:"x-application/hl7-v2+er7"};var e={JSON:"json",CSV:"csv",XML:"xml",HL7:"hl7",UNKNOWN:"unknown"};var a={JSON:"json",XML:"xml",PLAINTEXT:"plaintext"};var s=class s{contentTypeToContentFormat(t){return s.contentTypeToContentFormatMap[t]}contentTypeToEditorLanguage(t){let o=this.contentTypeToContentFormat(t);return this.contentFormatToEditorLanguage(o)}contentFormatToContentType(t){return s.contentFormatToContentTypeMap[t]||null}contentFormatToEditorLanguage(t){return s.contentFormatToEditorLanguageMap[t]}stringToContentFormat(t){let o=t.toLowerCase();return s.contentFormats.find(c=>c===o)||null}stringToContentType(t){let o=t.toLowerCase();return s.contentTypes.find(c=>o.startsWith(c))||null}stringToEditorLanguage(t){let o=t.toLowerCase();return s.editorLanguages.find(c=>c===o)||null}};s.contentTypeToContentFormatMap={[r.JSON]:e.JSON,[r.CSV]:e.CSV,[r.XML]:e.XML,[r.HL7V2]:e.HL7},s.contentFormatToContentTypeMap={[e.JSON]:r.JSON,[e.CSV]:r.CSV,[e.XML]:r.XML,[e.HL7]:r.HL7V2,[e.UNKNOWN]:null},s.contentFormatToEditorLanguageMap={[e.JSON]:a.JSON,[e.XML]:a.XML,[e.CSV]:a.PLAINTEXT,[e.HL7]:a.PLAINTEXT,[e.UNKNOWN]:a.PLAINTEXT},s.contentFormats=[e.JSON,e.CSV,e.XML,e.HL7,e.UNKNOWN],s.contentTypes=[r.JSON,r.CSV,r.XML,r.HL7V2],s.editorLanguages=[a.JSON,a.XML,a.PLAINTEXT];var i=s;var y=n=>typeof n=="string"&&n.trimStart().startsWith("MSH|"),C=n=>{try{return JSON.parse(n),!0}catch(t){return false}},L=n=>{let t=n,o={curlyBraces:(t.match(/[{}]/g)||[]).length,colons:(t.match(/:/g)||[]).length,keyValueStructure:/{[^}]*:[^}]*}/.test(n)},c=/{[^}]*"[^"]*"\s*:\s*/.test(n);return (o.curlyBraces>=2||o.curlyBraces>=1&&c)&&o.colons>=1&&(o.keyValueStructure||/{.*:.*}/.test(n)||c)},u=n=>{let t={openingTags:(n.match(/<[^/!?][^>]*?>/g)||[]).length,closingTags:(n.match(/<\/[^>]+>/g)||[]).length,selfClosingTags:(n.match(/<[^>]+\/>/g)||[]).length,xmlNamespaces:(n.match(/xmlns(:[a-zA-Z0-9]+)?=/g)||[]).length};return (/^<\?xml.*?\?>/.test(n)||t.xmlNamespaces>=1||t.openingTags>=1)&&(t.openingTags===t.closingTags||t.selfClosingTags>=1)},T=n=>{let t=n.split(/\r?\n/),o=t[0],c={rowCount:t.length,commaCounts:t.map(l=>(l.match(/,/g)||[]).length)},m={curlyBraces:(o.match(/[{}]/g)||[]).length,squareBrackets:(o.match(/[\[\]]/g)||[]).length,angularBrackets:(o.match(/[<>]/g)||[]).length,colons:(o.match(/:/g)||[]).length};return (c.rowCount>1||c.commaCounts.some(l=>l>0))&&m.curlyBraces===0&&m.squareBrackets===0&&m.angularBrackets===0&&m.colons===0},g=class g{detectContentType(t){let o=this.detectFormat(t);return g.typeConverter.contentFormatToContentType(o)}detectFormat(t){try{return (t==null?void 0:t.trim())?C(t)?e.JSON:y(t)?e.HL7:L(t)?e.JSON:u(t)?e.XML:T(t)?e.CSV:e.UNKNOWN:e.UNKNOWN}catch(o){return e.UNKNOWN}}detectEditorLanguage(t){switch(this.detectFormat(t)){case e.JSON:return a.JSON;case e.XML:return a.XML;default:return a.PLAINTEXT}}};g.typeConverter=new i;var p=g;exports.ContentFormat=e;exports.ContentType=r;exports.EditorLanguage=a;exports.FormatDetector=p;exports.TypeConverter=i;return exports;})({});//# sourceMappingURL=browser.js.map
|
|
2
2
|
//# sourceMappingURL=browser.js.map
|
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r={JSON:"application/json",CSV:"text/csv",XML:"application/xml",HL7V2:"x-application/hl7-v2+er7"};var e={JSON:"json",CSV:"csv",XML:"xml",HL7:"hl7",UNKNOWN:"unknown"};var a={JSON:"json",XML:"xml",PLAINTEXT:"plaintext"};var s=class s{contentTypeToContentFormat(t){return s.contentTypeToContentFormatMap[t]}contentTypeToEditorLanguage(t){let o=this.contentTypeToContentFormat(t);return this.contentFormatToEditorLanguage(o)}contentFormatToContentType(t){return s.contentFormatToContentTypeMap[t]||null}contentFormatToEditorLanguage(t){return s.contentFormatToEditorLanguageMap[t]}stringToContentFormat(t){let o=t.toLowerCase();return s.contentFormats.find(c=>c===o)||null}stringToContentType(t){let o=t.toLowerCase();return s.contentTypes.find(c=>o.startsWith(c))||null}stringToEditorLanguage(t){let o=t.toLowerCase();return s.editorLanguages.find(c=>c===o)||null}};s.contentTypeToContentFormatMap={[r.JSON]:e.JSON,[r.CSV]:e.CSV,[r.XML]:e.XML,[r.HL7V2]:e.HL7},s.contentFormatToContentTypeMap={[e.JSON]:r.JSON,[e.CSV]:r.CSV,[e.XML]:r.XML,[e.HL7]:r.HL7V2,[e.UNKNOWN]:null},s.contentFormatToEditorLanguageMap={[e.JSON]:a.JSON,[e.XML]:a.XML,[e.CSV]:a.PLAINTEXT,[e.HL7]:a.PLAINTEXT,[e.UNKNOWN]:a.PLAINTEXT},s.contentFormats=[e.JSON,e.CSV,e.XML,e.HL7,e.UNKNOWN],s.contentTypes=[r.JSON,r.CSV,r.XML,r.HL7V2],s.editorLanguages=[a.JSON,a.XML,a.PLAINTEXT];var i=s;var y=n=>typeof n=="string"&&n.trimStart().startsWith("MSH|"),C=n=>{try{return JSON.parse(n),!0}catch(t){return false}},L=n=>{let t=n,o={curlyBraces:(t.match(/[{}]/g)||[]).length,colons:(t.match(/:/g)||[]).length,keyValueStructure:/{[^}]*:[^}]*}/.test(n)},c=/{[^}]*"[^"]*"\s*:\s*/.test(n);return (o.curlyBraces>=2||o.curlyBraces>=1&&c)&&o.colons>=1&&(o.keyValueStructure||/{.*:.*}/.test(n)||c)},u=n=>{let t={openingTags:(n.match(/<[^/!?][^>]*?>/g)||[]).length,closingTags:(n.match(/<\/[^>]+>/g)||[]).length,selfClosingTags:(n.match(/<[^>]+\/>/g)||[]).length,xmlNamespaces:(n.match(/xmlns(:[a-zA-Z0-9]+)?=/g)||[]).length};return (/^<\?xml.*?\?>/.test(n)||t.xmlNamespaces>=1||t.openingTags>=1)&&(t.openingTags===t.closingTags||t.selfClosingTags>=1)},T=n=>{let t=n.split(/\r?\n/),o=t[0],c={rowCount:t.length,commaCounts:t.map(l=>(l.match(/,/g)||[]).length)},m={curlyBraces:(o.match(/[{}]/g)||[]).length,squareBrackets:(o.match(/[\[\]]/g)||[]).length,angularBrackets:(o.match(/[<>]/g)||[]).length,colons:(o.match(/:/g)||[]).length};return (c.rowCount>1||c.commaCounts.some(l=>l>0))&&m.curlyBraces===0&&m.squareBrackets===0&&m.angularBrackets===0&&m.colons===0},g=class g{detectContentType(t){let o=this.detectFormat(t);return g.typeConverter.contentFormatToContentType(o)}detectFormat(t){try{return (t==null?void 0:t.trim())?C(t)?e.JSON:y(t)?e.HL7:L(t)?e.JSON:u(t)?e.XML:T(t)?e.CSV:e.UNKNOWN:e.UNKNOWN}catch(o){return e.UNKNOWN}}detectEditorLanguage(t){switch(this.detectFormat(t)){case e.JSON:return a.JSON;case e.XML:return a.XML;default:return a.PLAINTEXT}}};g.typeConverter=new i;var p=g;export{e as ContentFormat,r as ContentType,a as EditorLanguage,p as FormatDetector,i as TypeConverter};//# sourceMappingURL=browser.mjs.map
|
|
2
|
+
//# sourceMappingURL=browser.mjs.map
|
package/dist/index.cjs
CHANGED
|
@@ -13,56 +13,92 @@ var HL7Dictionary__default = /*#__PURE__*/_interopDefault(HL7Dictionary);
|
|
|
13
13
|
var hl7js__default = /*#__PURE__*/_interopDefault(hl7js);
|
|
14
14
|
var jsonata__default = /*#__PURE__*/_interopDefault(jsonata);
|
|
15
15
|
|
|
16
|
+
// src/types/ContentType.ts
|
|
17
|
+
var ContentType = {
|
|
18
|
+
/** Standard MIME type for JSON data */
|
|
19
|
+
JSON: "application/json",
|
|
20
|
+
/** Standard MIME type for CSV data */
|
|
21
|
+
CSV: "text/csv",
|
|
22
|
+
/** Standard MIME type for XML data */
|
|
23
|
+
XML: "application/xml",
|
|
24
|
+
/** Custom MIME type for HL7 Version 2.x messages in ER7 encoding */
|
|
25
|
+
HL7V2: "x-application/hl7-v2+er7"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/types/ContentFormat.ts
|
|
29
|
+
var ContentFormat = {
|
|
30
|
+
/** JavaScript Object Notation format */
|
|
31
|
+
JSON: "json",
|
|
32
|
+
/** Comma-Separated Values format */
|
|
33
|
+
CSV: "csv",
|
|
34
|
+
/** eXtensible Markup Language format */
|
|
35
|
+
XML: "xml",
|
|
36
|
+
/** Health Level 7 Version 2.x message format */
|
|
37
|
+
HL7: "hl7",
|
|
38
|
+
/** Unknown or unsupported format */
|
|
39
|
+
UNKNOWN: "unknown"
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/types/EditorLanguage.ts
|
|
43
|
+
var EditorLanguage = {
|
|
44
|
+
/** JSON language mode for syntax highlighting */
|
|
45
|
+
JSON: "json",
|
|
46
|
+
/** XML language mode for syntax highlighting */
|
|
47
|
+
XML: "xml",
|
|
48
|
+
/** Plain text mode with no syntax highlighting */
|
|
49
|
+
PLAINTEXT: "plaintext"
|
|
50
|
+
};
|
|
51
|
+
|
|
16
52
|
// src/TypeConverter.ts
|
|
17
53
|
var TypeConverter = class _TypeConverter {
|
|
18
54
|
static {
|
|
19
55
|
this.contentTypeToContentFormatMap = {
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
56
|
+
[ContentType.JSON]: ContentFormat.JSON,
|
|
57
|
+
[ContentType.CSV]: ContentFormat.CSV,
|
|
58
|
+
[ContentType.XML]: ContentFormat.XML,
|
|
59
|
+
[ContentType.HL7V2]: ContentFormat.HL7
|
|
24
60
|
};
|
|
25
61
|
}
|
|
26
62
|
static {
|
|
27
63
|
this.contentFormatToContentTypeMap = {
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
64
|
+
[ContentFormat.JSON]: ContentType.JSON,
|
|
65
|
+
[ContentFormat.CSV]: ContentType.CSV,
|
|
66
|
+
[ContentFormat.XML]: ContentType.XML,
|
|
67
|
+
[ContentFormat.HL7]: ContentType.HL7V2,
|
|
68
|
+
[ContentFormat.UNKNOWN]: null
|
|
33
69
|
};
|
|
34
70
|
}
|
|
35
71
|
static {
|
|
36
72
|
this.contentFormatToEditorLanguageMap = {
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
73
|
+
[ContentFormat.JSON]: EditorLanguage.JSON,
|
|
74
|
+
[ContentFormat.XML]: EditorLanguage.XML,
|
|
75
|
+
[ContentFormat.CSV]: EditorLanguage.PLAINTEXT,
|
|
76
|
+
[ContentFormat.HL7]: EditorLanguage.PLAINTEXT,
|
|
77
|
+
[ContentFormat.UNKNOWN]: EditorLanguage.PLAINTEXT
|
|
42
78
|
};
|
|
43
79
|
}
|
|
44
80
|
static {
|
|
45
81
|
this.contentFormats = [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
82
|
+
ContentFormat.JSON,
|
|
83
|
+
ContentFormat.CSV,
|
|
84
|
+
ContentFormat.XML,
|
|
85
|
+
ContentFormat.HL7,
|
|
86
|
+
ContentFormat.UNKNOWN
|
|
51
87
|
];
|
|
52
88
|
}
|
|
53
89
|
static {
|
|
54
90
|
this.contentTypes = [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
91
|
+
ContentType.JSON,
|
|
92
|
+
ContentType.CSV,
|
|
93
|
+
ContentType.XML,
|
|
94
|
+
ContentType.HL7V2
|
|
59
95
|
];
|
|
60
96
|
}
|
|
61
97
|
static {
|
|
62
98
|
this.editorLanguages = [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
99
|
+
EditorLanguage.JSON,
|
|
100
|
+
EditorLanguage.XML,
|
|
101
|
+
EditorLanguage.PLAINTEXT
|
|
66
102
|
];
|
|
67
103
|
}
|
|
68
104
|
contentTypeToContentFormat(contentType) {
|
|
@@ -547,29 +583,29 @@ var FormatConverter = class _FormatConverter {
|
|
|
547
583
|
async toJson(input, contentType) {
|
|
548
584
|
if (!contentType || contentType === "") {
|
|
549
585
|
this.logger.info("No content type provided, defaulting to 'application/json'");
|
|
550
|
-
contentType =
|
|
586
|
+
contentType = ContentType.JSON;
|
|
551
587
|
}
|
|
552
588
|
const suggestedContentType = typeof contentType === "string" ? _FormatConverter.typeConverter.stringToContentType(contentType) : contentType;
|
|
553
589
|
if (!suggestedContentType) {
|
|
554
|
-
throw new Error(`Unsupported Content-Type: ${
|
|
590
|
+
throw new Error(`Unsupported Content-Type: ${contentType}`);
|
|
555
591
|
}
|
|
556
592
|
let parsedJson;
|
|
557
|
-
if (suggestedContentType ===
|
|
593
|
+
if (suggestedContentType === ContentType.HL7V2) {
|
|
558
594
|
this.logger.info("Content-Type suggests HL7 V2.x message");
|
|
559
595
|
this.logger.info("Trying to parse HL7 V2.x message as JSON...");
|
|
560
596
|
parsedJson = await this.hl7v2ToJson(input);
|
|
561
597
|
this.logger.info("Parsed HL7 V2.x message to JSON successfully.");
|
|
562
|
-
} else if (suggestedContentType ===
|
|
598
|
+
} else if (suggestedContentType === ContentType.CSV) {
|
|
563
599
|
this.logger.info("Content-Type suggests CSV input");
|
|
564
600
|
this.logger.info("Trying to parse CSV as JSON...");
|
|
565
601
|
parsedJson = await this.csvToJson(input);
|
|
566
602
|
this.logger.info("Parsed CSV to JSON successfully.");
|
|
567
|
-
} else if (suggestedContentType ===
|
|
603
|
+
} else if (suggestedContentType === ContentType.XML) {
|
|
568
604
|
this.logger.info("Content-Type suggests XML input");
|
|
569
605
|
this.logger.info("Trying to parse XML as JSON...");
|
|
570
606
|
parsedJson = await this.xmlToJson(input);
|
|
571
607
|
this.logger.info("Parsed XML to JSON successfully.");
|
|
572
|
-
} else if (suggestedContentType ===
|
|
608
|
+
} else if (suggestedContentType === ContentType.JSON) {
|
|
573
609
|
this.logger.info("Content-Type suggests JSON input");
|
|
574
610
|
parsedJson = input;
|
|
575
611
|
this.logger.info("Parsed input to JSON successfully.");
|
|
@@ -643,26 +679,26 @@ var FormatDetector = class _FormatDetector {
|
|
|
643
679
|
detectFormat(input) {
|
|
644
680
|
try {
|
|
645
681
|
const trimmedInput = input?.trim();
|
|
646
|
-
if (!trimmedInput) return
|
|
647
|
-
if (isValidJson(input)) return
|
|
648
|
-
if (isPossiblyHL7(input)) return
|
|
649
|
-
if (isJsonLikely(input)) return
|
|
650
|
-
if (isXmlLikely(input)) return
|
|
651
|
-
if (isCsvLikely(input)) return
|
|
652
|
-
return
|
|
682
|
+
if (!trimmedInput) return ContentFormat.UNKNOWN;
|
|
683
|
+
if (isValidJson(input)) return ContentFormat.JSON;
|
|
684
|
+
if (isPossiblyHL7(input)) return ContentFormat.HL7;
|
|
685
|
+
if (isJsonLikely(input)) return ContentFormat.JSON;
|
|
686
|
+
if (isXmlLikely(input)) return ContentFormat.XML;
|
|
687
|
+
if (isCsvLikely(input)) return ContentFormat.CSV;
|
|
688
|
+
return ContentFormat.UNKNOWN;
|
|
653
689
|
} catch (e) {
|
|
654
|
-
return
|
|
690
|
+
return ContentFormat.UNKNOWN;
|
|
655
691
|
}
|
|
656
692
|
}
|
|
657
693
|
detectEditorLanguage(input) {
|
|
658
694
|
const format = this.detectFormat(input);
|
|
659
695
|
switch (format) {
|
|
660
|
-
case
|
|
661
|
-
return
|
|
662
|
-
case
|
|
663
|
-
return
|
|
696
|
+
case ContentFormat.JSON:
|
|
697
|
+
return EditorLanguage.JSON;
|
|
698
|
+
case ContentFormat.XML:
|
|
699
|
+
return EditorLanguage.XML;
|
|
664
700
|
default:
|
|
665
|
-
return
|
|
701
|
+
return EditorLanguage.PLAINTEXT;
|
|
666
702
|
}
|
|
667
703
|
}
|
|
668
704
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -9,48 +9,51 @@ interface ILogger {
|
|
|
9
9
|
* Used by format detection algorithms to categorize input data and determine
|
|
10
10
|
* appropriate conversion strategies.
|
|
11
11
|
*/
|
|
12
|
-
declare const
|
|
12
|
+
declare const ContentFormat: {
|
|
13
13
|
/** JavaScript Object Notation format */
|
|
14
|
-
JSON
|
|
14
|
+
readonly JSON: "json";
|
|
15
15
|
/** Comma-Separated Values format */
|
|
16
|
-
CSV
|
|
16
|
+
readonly CSV: "csv";
|
|
17
17
|
/** eXtensible Markup Language format */
|
|
18
|
-
XML
|
|
18
|
+
readonly XML: "xml";
|
|
19
19
|
/** Health Level 7 Version 2.x message format */
|
|
20
|
-
HL7
|
|
20
|
+
readonly HL7: "hl7";
|
|
21
21
|
/** Unknown or unsupported format */
|
|
22
|
-
UNKNOWN
|
|
23
|
-
}
|
|
22
|
+
readonly UNKNOWN: "unknown";
|
|
23
|
+
};
|
|
24
|
+
type ContentFormat = typeof ContentFormat[keyof typeof ContentFormat];
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Enumeration of supported MIME types/content types for data format identification.
|
|
27
28
|
* These values correspond to standard HTTP Content-Type header values and are used
|
|
28
29
|
* for format detection and conversion operations.
|
|
29
30
|
*/
|
|
30
|
-
declare const
|
|
31
|
+
declare const ContentType: {
|
|
31
32
|
/** Standard MIME type for JSON data */
|
|
32
|
-
JSON
|
|
33
|
+
readonly JSON: "application/json";
|
|
33
34
|
/** Standard MIME type for CSV data */
|
|
34
|
-
CSV
|
|
35
|
+
readonly CSV: "text/csv";
|
|
35
36
|
/** Standard MIME type for XML data */
|
|
36
|
-
XML
|
|
37
|
+
readonly XML: "application/xml";
|
|
37
38
|
/** Custom MIME type for HL7 Version 2.x messages in ER7 encoding */
|
|
38
|
-
HL7V2
|
|
39
|
-
}
|
|
39
|
+
readonly HL7V2: "x-application/hl7-v2+er7";
|
|
40
|
+
};
|
|
41
|
+
type ContentType = typeof ContentType[keyof typeof ContentType];
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
44
|
* Enumeration of supported editor language identifiers for syntax highlighting and editor configuration.
|
|
43
45
|
* These values are used to determine the appropriate language mode for displaying content
|
|
44
46
|
* in code editors or other text editing interfaces.
|
|
45
47
|
*/
|
|
46
|
-
declare const
|
|
48
|
+
declare const EditorLanguage: {
|
|
47
49
|
/** JSON language mode for syntax highlighting */
|
|
48
|
-
JSON
|
|
50
|
+
readonly JSON: "json";
|
|
49
51
|
/** XML language mode for syntax highlighting */
|
|
50
|
-
XML
|
|
52
|
+
readonly XML: "xml";
|
|
51
53
|
/** Plain text mode with no syntax highlighting */
|
|
52
|
-
PLAINTEXT
|
|
53
|
-
}
|
|
54
|
+
readonly PLAINTEXT: "plaintext";
|
|
55
|
+
};
|
|
56
|
+
type EditorLanguage = typeof EditorLanguage[keyof typeof EditorLanguage];
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Interface for format detection operations, providing methods to analyze and identify
|
|
@@ -177,6 +180,18 @@ declare class TypeConverter implements ITypeConverter {
|
|
|
177
180
|
stringToEditorLanguage(editorLanguage: string): EditorLanguage | null;
|
|
178
181
|
}
|
|
179
182
|
|
|
183
|
+
/**
|
|
184
|
+
* A format converter that transforms various input formats to JSON.
|
|
185
|
+
*
|
|
186
|
+
* Supports conversion from multiple content types including HL7 V2.x messages,
|
|
187
|
+
* CSV data, XML documents, and JSON strings to standardized JSON format.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const converter = new FormatConverter(logger);
|
|
192
|
+
* const jsonData = await converter.toJson(csvInput, ContentType.CSV);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
180
195
|
declare class FormatConverter implements IFormatConverter {
|
|
181
196
|
private static readonly typeConverter;
|
|
182
197
|
private logger;
|
|
@@ -187,6 +202,23 @@ declare class FormatConverter implements IFormatConverter {
|
|
|
187
202
|
hl7v2ToJson: (message: string) => Promise<any>;
|
|
188
203
|
}
|
|
189
204
|
|
|
205
|
+
/**
|
|
206
|
+
* A service class responsible for detecting and identifying various content formats and types.
|
|
207
|
+
*
|
|
208
|
+
* The FormatDetector analyzes input strings to determine their format (JSON, XML, CSV, HL7, etc.)
|
|
209
|
+
* and provides corresponding content types and editor language mappings. It uses a series of
|
|
210
|
+
* validation functions to identify the most likely format of the input data.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const detector = new FormatDetector();
|
|
215
|
+
* const format = detector.detectFormat('{"key": "value"}');
|
|
216
|
+
* // Returns: ContentFormat.JSON
|
|
217
|
+
*
|
|
218
|
+
* const contentType = detector.detectContentType('<root></root>');
|
|
219
|
+
* // Returns: ContentType corresponding to XML format
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
190
222
|
declare class FormatDetector implements IFormatDetector {
|
|
191
223
|
private static readonly typeConverter;
|
|
192
224
|
detectContentType(input: string): ContentType | null;
|
package/dist/index.mjs
CHANGED
|
@@ -4,56 +4,92 @@ import HL7Dictionary from 'hl7-dictionary';
|
|
|
4
4
|
import hl7js from 'hl7js';
|
|
5
5
|
import jsonata from 'jsonata';
|
|
6
6
|
|
|
7
|
+
// src/types/ContentType.ts
|
|
8
|
+
var ContentType = {
|
|
9
|
+
/** Standard MIME type for JSON data */
|
|
10
|
+
JSON: "application/json",
|
|
11
|
+
/** Standard MIME type for CSV data */
|
|
12
|
+
CSV: "text/csv",
|
|
13
|
+
/** Standard MIME type for XML data */
|
|
14
|
+
XML: "application/xml",
|
|
15
|
+
/** Custom MIME type for HL7 Version 2.x messages in ER7 encoding */
|
|
16
|
+
HL7V2: "x-application/hl7-v2+er7"
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// src/types/ContentFormat.ts
|
|
20
|
+
var ContentFormat = {
|
|
21
|
+
/** JavaScript Object Notation format */
|
|
22
|
+
JSON: "json",
|
|
23
|
+
/** Comma-Separated Values format */
|
|
24
|
+
CSV: "csv",
|
|
25
|
+
/** eXtensible Markup Language format */
|
|
26
|
+
XML: "xml",
|
|
27
|
+
/** Health Level 7 Version 2.x message format */
|
|
28
|
+
HL7: "hl7",
|
|
29
|
+
/** Unknown or unsupported format */
|
|
30
|
+
UNKNOWN: "unknown"
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/types/EditorLanguage.ts
|
|
34
|
+
var EditorLanguage = {
|
|
35
|
+
/** JSON language mode for syntax highlighting */
|
|
36
|
+
JSON: "json",
|
|
37
|
+
/** XML language mode for syntax highlighting */
|
|
38
|
+
XML: "xml",
|
|
39
|
+
/** Plain text mode with no syntax highlighting */
|
|
40
|
+
PLAINTEXT: "plaintext"
|
|
41
|
+
};
|
|
42
|
+
|
|
7
43
|
// src/TypeConverter.ts
|
|
8
44
|
var TypeConverter = class _TypeConverter {
|
|
9
45
|
static {
|
|
10
46
|
this.contentTypeToContentFormatMap = {
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
47
|
+
[ContentType.JSON]: ContentFormat.JSON,
|
|
48
|
+
[ContentType.CSV]: ContentFormat.CSV,
|
|
49
|
+
[ContentType.XML]: ContentFormat.XML,
|
|
50
|
+
[ContentType.HL7V2]: ContentFormat.HL7
|
|
15
51
|
};
|
|
16
52
|
}
|
|
17
53
|
static {
|
|
18
54
|
this.contentFormatToContentTypeMap = {
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
55
|
+
[ContentFormat.JSON]: ContentType.JSON,
|
|
56
|
+
[ContentFormat.CSV]: ContentType.CSV,
|
|
57
|
+
[ContentFormat.XML]: ContentType.XML,
|
|
58
|
+
[ContentFormat.HL7]: ContentType.HL7V2,
|
|
59
|
+
[ContentFormat.UNKNOWN]: null
|
|
24
60
|
};
|
|
25
61
|
}
|
|
26
62
|
static {
|
|
27
63
|
this.contentFormatToEditorLanguageMap = {
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
64
|
+
[ContentFormat.JSON]: EditorLanguage.JSON,
|
|
65
|
+
[ContentFormat.XML]: EditorLanguage.XML,
|
|
66
|
+
[ContentFormat.CSV]: EditorLanguage.PLAINTEXT,
|
|
67
|
+
[ContentFormat.HL7]: EditorLanguage.PLAINTEXT,
|
|
68
|
+
[ContentFormat.UNKNOWN]: EditorLanguage.PLAINTEXT
|
|
33
69
|
};
|
|
34
70
|
}
|
|
35
71
|
static {
|
|
36
72
|
this.contentFormats = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
73
|
+
ContentFormat.JSON,
|
|
74
|
+
ContentFormat.CSV,
|
|
75
|
+
ContentFormat.XML,
|
|
76
|
+
ContentFormat.HL7,
|
|
77
|
+
ContentFormat.UNKNOWN
|
|
42
78
|
];
|
|
43
79
|
}
|
|
44
80
|
static {
|
|
45
81
|
this.contentTypes = [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
82
|
+
ContentType.JSON,
|
|
83
|
+
ContentType.CSV,
|
|
84
|
+
ContentType.XML,
|
|
85
|
+
ContentType.HL7V2
|
|
50
86
|
];
|
|
51
87
|
}
|
|
52
88
|
static {
|
|
53
89
|
this.editorLanguages = [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
90
|
+
EditorLanguage.JSON,
|
|
91
|
+
EditorLanguage.XML,
|
|
92
|
+
EditorLanguage.PLAINTEXT
|
|
57
93
|
];
|
|
58
94
|
}
|
|
59
95
|
contentTypeToContentFormat(contentType) {
|
|
@@ -538,29 +574,29 @@ var FormatConverter = class _FormatConverter {
|
|
|
538
574
|
async toJson(input, contentType) {
|
|
539
575
|
if (!contentType || contentType === "") {
|
|
540
576
|
this.logger.info("No content type provided, defaulting to 'application/json'");
|
|
541
|
-
contentType =
|
|
577
|
+
contentType = ContentType.JSON;
|
|
542
578
|
}
|
|
543
579
|
const suggestedContentType = typeof contentType === "string" ? _FormatConverter.typeConverter.stringToContentType(contentType) : contentType;
|
|
544
580
|
if (!suggestedContentType) {
|
|
545
|
-
throw new Error(`Unsupported Content-Type: ${
|
|
581
|
+
throw new Error(`Unsupported Content-Type: ${contentType}`);
|
|
546
582
|
}
|
|
547
583
|
let parsedJson;
|
|
548
|
-
if (suggestedContentType ===
|
|
584
|
+
if (suggestedContentType === ContentType.HL7V2) {
|
|
549
585
|
this.logger.info("Content-Type suggests HL7 V2.x message");
|
|
550
586
|
this.logger.info("Trying to parse HL7 V2.x message as JSON...");
|
|
551
587
|
parsedJson = await this.hl7v2ToJson(input);
|
|
552
588
|
this.logger.info("Parsed HL7 V2.x message to JSON successfully.");
|
|
553
|
-
} else if (suggestedContentType ===
|
|
589
|
+
} else if (suggestedContentType === ContentType.CSV) {
|
|
554
590
|
this.logger.info("Content-Type suggests CSV input");
|
|
555
591
|
this.logger.info("Trying to parse CSV as JSON...");
|
|
556
592
|
parsedJson = await this.csvToJson(input);
|
|
557
593
|
this.logger.info("Parsed CSV to JSON successfully.");
|
|
558
|
-
} else if (suggestedContentType ===
|
|
594
|
+
} else if (suggestedContentType === ContentType.XML) {
|
|
559
595
|
this.logger.info("Content-Type suggests XML input");
|
|
560
596
|
this.logger.info("Trying to parse XML as JSON...");
|
|
561
597
|
parsedJson = await this.xmlToJson(input);
|
|
562
598
|
this.logger.info("Parsed XML to JSON successfully.");
|
|
563
|
-
} else if (suggestedContentType ===
|
|
599
|
+
} else if (suggestedContentType === ContentType.JSON) {
|
|
564
600
|
this.logger.info("Content-Type suggests JSON input");
|
|
565
601
|
parsedJson = input;
|
|
566
602
|
this.logger.info("Parsed input to JSON successfully.");
|
|
@@ -634,26 +670,26 @@ var FormatDetector = class _FormatDetector {
|
|
|
634
670
|
detectFormat(input) {
|
|
635
671
|
try {
|
|
636
672
|
const trimmedInput = input?.trim();
|
|
637
|
-
if (!trimmedInput) return
|
|
638
|
-
if (isValidJson(input)) return
|
|
639
|
-
if (isPossiblyHL7(input)) return
|
|
640
|
-
if (isJsonLikely(input)) return
|
|
641
|
-
if (isXmlLikely(input)) return
|
|
642
|
-
if (isCsvLikely(input)) return
|
|
643
|
-
return
|
|
673
|
+
if (!trimmedInput) return ContentFormat.UNKNOWN;
|
|
674
|
+
if (isValidJson(input)) return ContentFormat.JSON;
|
|
675
|
+
if (isPossiblyHL7(input)) return ContentFormat.HL7;
|
|
676
|
+
if (isJsonLikely(input)) return ContentFormat.JSON;
|
|
677
|
+
if (isXmlLikely(input)) return ContentFormat.XML;
|
|
678
|
+
if (isCsvLikely(input)) return ContentFormat.CSV;
|
|
679
|
+
return ContentFormat.UNKNOWN;
|
|
644
680
|
} catch (e) {
|
|
645
|
-
return
|
|
681
|
+
return ContentFormat.UNKNOWN;
|
|
646
682
|
}
|
|
647
683
|
}
|
|
648
684
|
detectEditorLanguage(input) {
|
|
649
685
|
const format = this.detectFormat(input);
|
|
650
686
|
switch (format) {
|
|
651
|
-
case
|
|
652
|
-
return
|
|
653
|
-
case
|
|
654
|
-
return
|
|
687
|
+
case ContentFormat.JSON:
|
|
688
|
+
return EditorLanguage.JSON;
|
|
689
|
+
case ContentFormat.XML:
|
|
690
|
+
return EditorLanguage.XML;
|
|
655
691
|
default:
|
|
656
|
-
return
|
|
692
|
+
return EditorLanguage.PLAINTEXT;
|
|
657
693
|
}
|
|
658
694
|
}
|
|
659
695
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outburn/format-converter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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.
|
|
7
|
+
"browser": "./dist/browser.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
"import": "./dist/index.mjs",
|
|
14
14
|
"require": "./dist/index.cjs"
|
|
15
15
|
},
|
|
16
|
-
"./browser":
|
|
16
|
+
"./browser": {
|
|
17
|
+
"types": "./dist/browser.d.ts",
|
|
18
|
+
"import": "./dist/browser.mjs",
|
|
19
|
+
"default": "./dist/browser.mjs"
|
|
20
|
+
}
|
|
17
21
|
},
|
|
18
22
|
"scripts": {
|
|
19
23
|
"clean": "rimraf dist",
|
|
@@ -54,20 +58,20 @@
|
|
|
54
58
|
"license": "MIT",
|
|
55
59
|
"dependencies": {
|
|
56
60
|
"csvtojson": "^2.0.14",
|
|
57
|
-
"fast-xml-parser": "^
|
|
61
|
+
"fast-xml-parser": "^5.3.4",
|
|
58
62
|
"hl7-dictionary": "^1.0.1",
|
|
59
63
|
"hl7js": "^0.0.6",
|
|
60
64
|
"jsonata": "^2.1.0"
|
|
61
65
|
},
|
|
62
66
|
"devDependencies": {
|
|
63
|
-
"@types/node": "^
|
|
64
|
-
"eslint": "^9.39.
|
|
67
|
+
"@types/node": "^25.2.0",
|
|
68
|
+
"eslint": "^9.39.2",
|
|
65
69
|
"rimraf": "^6.1.2",
|
|
66
70
|
"tsup": "^8.5.1",
|
|
67
71
|
"tsx": "^4.21.0",
|
|
68
72
|
"typescript": "^5.9.3",
|
|
69
|
-
"typescript-eslint": "^8.
|
|
70
|
-
"vitest": "^4.0.
|
|
73
|
+
"typescript-eslint": "^8.54.0",
|
|
74
|
+
"vitest": "^4.0.18"
|
|
71
75
|
},
|
|
72
76
|
"repository": {
|
|
73
77
|
"type": "git",
|