@outburn/format-converter 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Outburn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # Format Converter
2
+
3
+ A TypeScript library for converting between various data formats including CSV, XML, HL7 v2, and JSON.
4
+
5
+ ## Features
6
+
7
+ - ๐Ÿ”„ **Multi-format support**: Convert between CSV, XML, HL7 v2, and JSON
8
+ - ๐Ÿฅ **Healthcare focused**: Specialized HL7 v2 message parsing and conversion
9
+ - ๐Ÿ” **Format detection**: Automatic content type detection
10
+ - ๐Ÿ›ก๏ธ **Type-safe**: Written in TypeScript with full type definitions
11
+ - ๐Ÿงช **Well-tested**: Comprehensive test suite
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @outburn/format-converter
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Basic Usage
22
+
23
+ ```typescript
24
+ import { FormatConverter } from '@outburn/format-converter';
25
+
26
+ const converter = new FormatConverter();
27
+
28
+ // Convert CSV to JSON
29
+ const csvData = `name,age,city
30
+ John,25,New York
31
+ Jane,30,Los Angeles`;
32
+
33
+ const jsonResult = await converter.toJson(csvData, 'text/csv');
34
+ console.log(jsonResult);
35
+
36
+ // Convert XML to JSON
37
+ const xmlData = `<?xml version="1.0"?>
38
+ <root>
39
+ <person>
40
+ <name>John</name>
41
+ <age>25</age>
42
+ </person>
43
+ </root>`;
44
+
45
+ const xmlToJson = await converter.toJson(xmlData, 'application/xml');
46
+ console.log(xmlToJson);
47
+ ```
48
+
49
+ ### HL7 v2 Message Conversion
50
+
51
+ ```typescript
52
+ import { FormatConverter } from '@outburn/format-converter';
53
+
54
+ const converter = new FormatConverter();
55
+
56
+ // Convert HL7 v2 message to JSON
57
+ const hl7Message = `MSH|^~\\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4
58
+ PID|||PATID1234^5^M11^ADT1^MR^UNIVERSITY HOSPITAL~123456789^^^USSSA^SS||EVERYMAN^ADAM^A^III||19610615|M||C|1200 N ELM STREET^^GREENSBORO^NC^27401-1020|GL|(919)379-1212|(919)271-3434||S||PATID12345001^2^M10^ADT1^AN^A|123456789|9-87654^NC`;
59
+
60
+ const hl7ToJson = await converter.toJson(hl7Message, 'x-application/hl7-v2+er7');
61
+ console.log(hl7ToJson);
62
+ ```
63
+
64
+ ### With Logging
65
+
66
+ ```typescript
67
+ import { FormatConverter } from '@outburn/format-converter';
68
+
69
+ // Custom logger implementation
70
+ const logger = {
71
+ info: (message: string) => console.log(`[INFO] ${message}`),
72
+ warn: (message: string) => console.warn(`[WARN] ${message}`),
73
+ error: (message: string) => console.error(`[ERROR] ${message}`)
74
+ };
75
+
76
+ const converter = new FormatConverter(logger);
77
+ ```
78
+
79
+ ### Type Conversion Utilities
80
+
81
+ ```typescript
82
+ import { TypeConverter } from '@outburn/format-converter';
83
+
84
+ const typeConverter = new TypeConverter();
85
+
86
+ // Convert MIME type strings to ContentType enum
87
+ const contentType = typeConverter.stringToContentType('text/csv');
88
+
89
+ // Detect format from content
90
+ const detectedFormat = typeConverter.detectFormat(csvData);
91
+ ```
92
+
93
+ ## Supported Formats
94
+
95
+ | Input Format | Content Type | Output |
96
+ |--------------|--------------|--------|
97
+ | CSV | `text/csv` | JSON |
98
+ | XML | `application/xml` | JSON |
99
+ | HL7 v2 | `x-application/hl7-v2+er7` | JSON |
100
+ | JSON | `application/json` | JSON (passthrough) |
101
+
102
+ ## API Reference
103
+
104
+ ### FormatConverter
105
+
106
+ #### Constructor
107
+ ```typescript
108
+ new FormatConverter(logger?: ILogger)
109
+ ```
110
+
111
+ - `logger` (optional): Custom logger implementing the `ILogger` interface
112
+
113
+ #### Methods
114
+
115
+ ##### `toJson(input: any, contentType?: ContentType | string): Promise<any>`
116
+
117
+ Converts input data to JSON format.
118
+
119
+ **Parameters:**
120
+ - `input`: The data to convert
121
+ - `contentType`: The MIME type or ContentType enum value of the input data
122
+
123
+ **Returns:** Promise resolving to the converted JSON data
124
+
125
+ ### TypeConverter
126
+
127
+ #### Methods
128
+
129
+ ##### `stringToContentType(mimeType: string): ContentType | undefined`
130
+
131
+ Converts a MIME type string to a ContentType enum value.
132
+
133
+ ##### `detectFormat(content: string): ContentType | undefined`
134
+
135
+ Attempts to automatically detect the format of the provided content.
136
+
137
+ ## Development
138
+
139
+ ### Building
140
+
141
+ ```bash
142
+ npm run build
143
+ ```
144
+
145
+ ### Testing
146
+
147
+ ```bash
148
+ npm test
149
+ ```
150
+
151
+ ### Linting
152
+
153
+ ```bash
154
+ npm run lint
155
+ ```
156
+
157
+ ## Dependencies
158
+
159
+ - **csvtojson**: CSV parsing functionality
160
+ - **fast-xml-parser**: XML parsing and conversion
161
+ - **hl7-dictionary**: HL7 v2 message definitions
162
+ - **hl7js**: HL7 message parsing utilities
163
+ - **jsonata**: JSON transformation and querying
164
+
165
+ ## License
166
+
167
+ MIT ยฉ Outburn Ltd.
168
+
169
+ ## Support
170
+
171
+ For issues and questions, please use the [GitHub Issues](https://github.com/Outburn-IL/format-converter/issues) page.