@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.
@@ -0,0 +1,76 @@
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 };
@@ -0,0 +1,76 @@
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 };