@rethinkhealth/hl7v2-decode-escapes 0.2.10 → 0.2.12
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 +7 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ This plugin only transforms AST nodes and does not execute code. Ensure you trus
|
|
|
98
98
|
|
|
99
99
|
## Contributing
|
|
100
100
|
|
|
101
|
-
We welcome contributions! Please see our [Contributing Guide]
|
|
101
|
+
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
102
102
|
|
|
103
103
|
1. Fork the repository
|
|
104
104
|
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
@@ -108,10 +108,14 @@ We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING
|
|
|
108
108
|
|
|
109
109
|
## Code of Conduct
|
|
110
110
|
|
|
111
|
-
To ensure a welcoming and positive environment, we have a [Code of Conduct]
|
|
111
|
+
To ensure a welcoming and positive environment, we have a [Code of Conduct][github-code-of-conduct] that all contributors and participants are expected to adhere to.
|
|
112
112
|
|
|
113
113
|
## License
|
|
114
114
|
|
|
115
115
|
Copyright 2025 Rethink Health, SUARL. All rights reserved.
|
|
116
116
|
|
|
117
|
-
This program is licensed to you under the terms of the [MIT License](https://opensource.org/licenses/MIT). This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [LICENSE]
|
|
117
|
+
This program is licensed to you under the terms of the [MIT License](https://opensource.org/licenses/MIT). This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [LICENSE][github-license] file for details.
|
|
118
|
+
|
|
119
|
+
[github-code-of-conduct]: https://github.com/rethinkhealth/hl7v2/blob/main/CODE_OF_CONDUCT.md
|
|
120
|
+
[github-license]: https://github.com/rethinkhealth/hl7v2/blob/main/LICENSE
|
|
121
|
+
[github-contributing]: https://github.com/rethinkhealth/hl7v2/blob/main/CONTRIBUTING.md
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { Root } from '@rethinkhealth/hl7v2-ast';
|
|
2
|
-
import { type HL7v2Delimiters } from '@rethinkhealth/hl7v2-utils';
|
|
1
|
+
import type { Delimiters, Root } from '@rethinkhealth/hl7v2-ast';
|
|
3
2
|
import type { Plugin } from 'unified';
|
|
4
3
|
export type HL7v2DecodeOptions = {
|
|
5
|
-
delimiters?: Partial<
|
|
4
|
+
delimiters?: Partial<Delimiters>;
|
|
6
5
|
};
|
|
7
6
|
/**
|
|
8
7
|
* Unified plugin to decode HL7v2 escape sequences in subcomponent literals.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAgB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAgB,MAAM,0BAA0B,CAAC;AAE/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAkBxE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_DELIMITERS
|
|
4
|
-
} from "@rethinkhealth/hl7v2-utils";
|
|
2
|
+
import { DEFAULT_DELIMITERS } from "@rethinkhealth/hl7v2-utils";
|
|
5
3
|
import { visit } from "unist-util-visit";
|
|
6
4
|
var hl7v2DecodeEscapes = (options) => {
|
|
7
5
|
return (tree) => {
|
|
@@ -47,7 +45,7 @@ function decode(value, d) {
|
|
|
47
45
|
decoded += d.escape;
|
|
48
46
|
break;
|
|
49
47
|
case ".br":
|
|
50
|
-
decoded +=
|
|
48
|
+
decoded += d.segment;
|
|
51
49
|
break;
|
|
52
50
|
case "H":
|
|
53
51
|
case "N":
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Root, Subcomponent } from '@rethinkhealth/hl7v2-ast';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Delimiters, Root, Subcomponent } from '@rethinkhealth/hl7v2-ast';\nimport { DEFAULT_DELIMITERS } from '@rethinkhealth/hl7v2-utils';\nimport type { Plugin } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nexport type HL7v2DecodeOptions = {\n delimiters?: Partial<Delimiters>;\n};\n\n/**\n * Unified plugin to decode HL7v2 escape sequences in subcomponent literals.\n *\n * - Decodes \\F\\, \\S\\, \\T\\, \\R\\, \\E\\\n * - Decodes \\Xdddd\\ hex escapes\n * - Handles \\.br\\ line breaks\n * - Uses delimiters from Root.data.delimiters if available\n */\nexport const hl7v2DecodeEscapes: Plugin<[HL7v2DecodeOptions?], Root, Root> = (\n options\n) => {\n return (tree: Root) => {\n const delimiters =\n (tree.data as { delimiters?: Partial<Delimiters> })?.delimiters ||\n options?.delimiters;\n\n visit(tree, 'subcomponent', (node: Subcomponent) => {\n const raw = node.value;\n node.value = decode(raw, {\n ...DEFAULT_DELIMITERS,\n ...delimiters,\n });\n });\n\n return tree;\n };\n};\n\n/**\n * Decode HL7v2 escape sequences according to HL7 v2.8 spec.\n *\n * @param value - The value to decode.\n * @param d - The delimiters to use.\n * @returns The decoded value.\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: this function must handle multiple HL7v2 escape cases and is as simple as possible given the requirements\nfunction decode(value: string, d: typeof DEFAULT_DELIMITERS): string {\n if (!value?.includes(d.escape)) {\n return value;\n }\n\n let decoded = '';\n let i = 0;\n\n while (i < value.length) {\n if (value[i] === d.escape) {\n const end = value.indexOf(d.escape, i + 1);\n if (end === -1) {\n decoded += value.slice(i); // unterminated escape\n break;\n }\n\n const code = value.slice(i + 1, end);\n\n switch (code) {\n case 'F':\n decoded += d.field;\n break;\n case 'S':\n decoded += d.component;\n break;\n case 'R':\n decoded += d.repetition;\n break;\n case 'T':\n decoded += d.subcomponent;\n break;\n case 'E':\n decoded += d.escape;\n break;\n case '.br':\n decoded += d.segment;\n break;\n case 'H':\n case 'N':\n // Highlight start/end: ignored for now\n break;\n default:\n if (code.startsWith('X') && code.length > 1) {\n decoded += decodeHexSequence(code.slice(1));\n } else {\n // Unknown escape: preserve as-is\n decoded += d.escape + code + d.escape;\n }\n break;\n }\n\n i = end + 1;\n } else {\n decoded += value[i++];\n }\n }\n\n return decoded;\n}\n\n/**\n * Decode HL7 \\Xdddd\\ hexadecimal escape sequences into characters.\n */\nfunction decodeHexSequence(hex: string): string {\n let result = '';\n for (let i = 0; i < hex.length; i += 2) {\n const byte = hex.slice(i, i + 2);\n const codePoint = Number.parseInt(byte, 16);\n if (!Number.isNaN(codePoint)) {\n result += String.fromCharCode(codePoint);\n }\n }\n return result;\n}\n"],"mappings":";AACA,SAAS,0BAA0B;AAEnC,SAAS,aAAa;AAcf,IAAM,qBAAgE,CAC3E,YACG;AACH,SAAO,CAAC,SAAe;AACrB,UAAM,aACH,KAAK,MAA+C,cACrD,SAAS;AAEX,UAAM,MAAM,gBAAgB,CAAC,SAAuB;AAClD,YAAM,MAAM,KAAK;AACjB,WAAK,QAAQ,OAAO,KA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AAC/B,UAAM,YAAY,OAAO,SAAS,MAAM,EAAE;AAC1C,QAAI,CAAC,OAAO,MAAM,SAAS,GAAG;AAC5B,gBAAU,OAAO,aAAa,SAAS;AAAA,IACzC;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rethinkhealth/hl7v2-decode-escapes",
|
|
3
3
|
"description": "hl7v2 plugin to decode hl7v2 escape sequences",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.12",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Melek Somai",
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"unified": "11.0.1",
|
|
20
20
|
"unist-util-visit": "5.0.0",
|
|
21
21
|
"unist-util-visit-parents": "6.0.1",
|
|
22
|
-
"@rethinkhealth/hl7v2-utils": "0.2.
|
|
22
|
+
"@rethinkhealth/hl7v2-utils": "0.2.12"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/node": "
|
|
25
|
+
"@types/node": "24.3.0",
|
|
26
26
|
"@types/unist": "^3.0.3",
|
|
27
27
|
"@vitest/coverage-c8": "^0.33.0",
|
|
28
28
|
"@vitest/coverage-v8": "^3.2.4",
|
|
29
29
|
"tsup": "8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.4",
|
|
32
|
-
"@rethinkhealth/hl7v2-ast": "0.2.10",
|
|
33
32
|
"@rethinkhealth/testing": "0.0.1",
|
|
33
|
+
"@rethinkhealth/hl7v2-ast": "0.2.12",
|
|
34
34
|
"@rethinkhealth/tsconfig": "0.0.1"
|
|
35
35
|
},
|
|
36
36
|
"repository": "rethinkhealth/hl7v2.git",
|