@glion/decode-escapes 0.15.1 → 0.15.2
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 +29 -59
- package/package.json +11 -7
package/README.md
CHANGED
|
@@ -1,57 +1,33 @@
|
|
|
1
1
|
# @glion/decode-escapes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Unified plugin to decode HL7v2 escape sequences in literal values.
|
|
4
4
|
|
|
5
|
-
## What
|
|
5
|
+
## What it does
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
It preserves the original raw value and replaces the `value` property with the decoded text, handling:
|
|
10
|
-
|
|
11
|
-
- HL7 delimiter escapes (`\F\`, `\S\`, `\R\`, `\T\`, `\E\`)
|
|
12
|
-
- Hexadecimal escapes (`\Xdddd\`)
|
|
13
|
-
- Line break directives (`\.br\`)
|
|
14
|
-
- Strips highlighting markers (`\H\`, `\N\`)
|
|
15
|
-
|
|
16
|
-
## When should I use this?
|
|
17
|
-
|
|
18
|
-
Use this plugin when you need:
|
|
19
|
-
|
|
20
|
-
- Human-readable HL7v2 values with escape sequences decoded.
|
|
21
|
-
- To process or display HL7v2 message content where `\F\` and similar escapes should be expanded.
|
|
22
|
-
|
|
23
|
-
If you need to parse HL7v2 messages first, use [`@glion/ast`](https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-parser) before applying this plugin.
|
|
7
|
+
Walks an HL7v2 AST and decodes escape sequences found in `subcomponent` nodes, replacing `node.value` with the decoded text. It handles the HL7 delimiter escapes (`\F\`, `\S\`, `\R\`, `\T\`, `\E\`), hexadecimal escapes (`\Xdddd\`), line-break directives (`\.br\`), and strips the highlighting markers (`\H\`, `\N\`). The original raw text is preserved on `node.data.raw` so the transformation is non-destructive.
|
|
24
8
|
|
|
25
9
|
## Install
|
|
26
10
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
In Node.js (version 16+), install with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):
|
|
30
|
-
|
|
31
|
-
```sh
|
|
11
|
+
```bash
|
|
32
12
|
npm install @glion/decode-escapes
|
|
33
13
|
```
|
|
34
14
|
|
|
35
15
|
## Use
|
|
36
16
|
|
|
37
|
-
Say we have an HL7v2 message with escapes:
|
|
38
|
-
|
|
39
17
|
```js
|
|
18
|
+
import { hl7v2DecodeEscapes } from "@glion/decode-escapes";
|
|
19
|
+
import { hl7v2Parser } from "@glion/parser";
|
|
40
20
|
import { unified } from "unified";
|
|
41
|
-
import { hl7v2Parse } from "@glion/ast";
|
|
42
|
-
import { hl7v2DecodeLiterals } from "@glion/decode-escapes";
|
|
43
21
|
|
|
44
22
|
const msg = `OBX|1|TX|ID123||Patient allergic to \\F\\Peanuts\\F\\ and \\.br\\Severe reaction`;
|
|
45
23
|
|
|
46
24
|
const file = await unified()
|
|
47
|
-
.use(
|
|
48
|
-
.use(
|
|
25
|
+
.use(hl7v2Parser)
|
|
26
|
+
.use(hl7v2DecodeEscapes)
|
|
49
27
|
.process(msg);
|
|
50
|
-
|
|
51
|
-
console.log(String(file));
|
|
52
28
|
```
|
|
53
29
|
|
|
54
|
-
Before decoding,
|
|
30
|
+
Before decoding, `subcomponent.value` contains the raw HL7 text:
|
|
55
31
|
|
|
56
32
|
```json
|
|
57
33
|
{
|
|
@@ -73,7 +49,7 @@ After this plugin runs:
|
|
|
73
49
|
|
|
74
50
|
## API
|
|
75
51
|
|
|
76
|
-
### `unified().use(
|
|
52
|
+
### `unified().use(hl7v2DecodeEscapes[, options])`
|
|
77
53
|
|
|
78
54
|
Decode HL7v2 escape sequences in literal nodes.
|
|
79
55
|
|
|
@@ -87,35 +63,29 @@ Nothing (`undefined`). Mutates the AST in-place.
|
|
|
87
63
|
|
|
88
64
|
## Behavior
|
|
89
65
|
|
|
90
|
-
|
|
91
|
-
- Decodes into `node.value`.
|
|
92
|
-
- Uses `Root.data.delimiters` (preferred) or `options.delimiters`.
|
|
93
|
-
- Falls back to defaults if neither is present.
|
|
94
|
-
|
|
95
|
-
## Security
|
|
96
|
-
|
|
97
|
-
This plugin only transforms AST nodes and does not execute code. Ensure you trust the source of HL7v2 messages before processing.
|
|
98
|
-
|
|
99
|
-
## Contributing
|
|
100
|
-
|
|
101
|
-
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
66
|
+
The plugin visits every `subcomponent` node and rewrites `node.value`. The original text is preserved on `node.data.raw` so downstream plugins can recover it.
|
|
102
67
|
|
|
103
|
-
|
|
104
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
105
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
106
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
107
|
-
5. Open a Pull Request
|
|
68
|
+
Each escape sequence is decoded as follows:
|
|
108
69
|
|
|
109
|
-
|
|
70
|
+
| Input | Output |
|
|
71
|
+
| --------- | ---------------------------------------------- |
|
|
72
|
+
| `\F\` | field separator (default `\|`) |
|
|
73
|
+
| `\S\` | component separator (default `^`) |
|
|
74
|
+
| `\R\` | repetition separator (default `~`) |
|
|
75
|
+
| `\T\` | subcomponent separator (default `&`) |
|
|
76
|
+
| `\E\` | escape character (default `\`) |
|
|
77
|
+
| `\Xdddd\` | character(s) for the given hexadecimal code(s) |
|
|
78
|
+
| `\.br\` | carriage return (`\r`) |
|
|
79
|
+
| `\H\` | stripped (highlight-on marker, no output) |
|
|
80
|
+
| `\N\` | stripped (normal-text marker, no output) |
|
|
110
81
|
|
|
111
|
-
|
|
82
|
+
Delimiter resolution order: `Root.data.delimiters` (preferred, set by the parser) → `options.delimiters` → HL7 defaults.
|
|
112
83
|
|
|
113
|
-
|
|
84
|
+
The plugin only transforms AST nodes and does not execute code. The inverse operation is provided by [`@glion/encode-escapes`](https://github.com/rethinkhealth/glion/tree/main/packages/encode-escapes).
|
|
114
85
|
|
|
115
|
-
|
|
86
|
+
## Part of Glion
|
|
116
87
|
|
|
117
|
-
|
|
88
|
+
`@glion/decode-escapes` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
|
|
118
89
|
|
|
119
|
-
[
|
|
120
|
-
[
|
|
121
|
-
[github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
|
|
90
|
+
[Glion]: https://github.com/rethinkhealth/glion#readme
|
|
91
|
+
[Glion README]: https://github.com/rethinkhealth/glion#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/decode-escapes",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "hl7v2 plugin to decode hl7v2 escape sequences",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -36,20 +36,22 @@
|
|
|
36
36
|
"unified": "11.0.5",
|
|
37
37
|
"unist-util-visit": "5.1.0",
|
|
38
38
|
"unist-util-visit-parents": "6.0.2",
|
|
39
|
-
"@glion/utils": "0.15.
|
|
39
|
+
"@glion/utils": "0.15.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^25.5.0",
|
|
43
43
|
"@types/unist": "^3.0.3",
|
|
44
44
|
"@vitest/coverage-v8": "4.1.2",
|
|
45
|
+
"publint": "0.3.18",
|
|
45
46
|
"tsdown": "0.21.7",
|
|
46
47
|
"typescript": "^5.9.3",
|
|
47
48
|
"vfile": "^6.0.3",
|
|
48
49
|
"vitest": "4.1.2",
|
|
49
|
-
"@glion/
|
|
50
|
-
"@glion/
|
|
51
|
-
"@glion/
|
|
52
|
-
"@glion/builder": "0.15.
|
|
50
|
+
"@glion/ast": "0.15.2",
|
|
51
|
+
"@glion/check-readme": "0.15.2",
|
|
52
|
+
"@glion/testing": "0.15.2",
|
|
53
|
+
"@glion/builder": "0.15.2",
|
|
54
|
+
"@glion/tsconfig": "0.15.2"
|
|
53
55
|
},
|
|
54
56
|
"engines": {
|
|
55
57
|
"node": ">=18"
|
|
@@ -59,8 +61,10 @@
|
|
|
59
61
|
"bench": "vitest bench --run",
|
|
60
62
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
61
63
|
"check-types": "tsc --noEmit",
|
|
64
|
+
"check:readme": "glion-check-readme",
|
|
62
65
|
"test": "vitest run",
|
|
63
66
|
"test:coverage": "vitest run --coverage",
|
|
64
|
-
"test:watch": "vitest"
|
|
67
|
+
"test:watch": "vitest",
|
|
68
|
+
"publint": "publint --strict"
|
|
65
69
|
}
|
|
66
70
|
}
|