@glion/encode-escapes 0.15.1 → 0.15.3
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 +25 -48
- package/package.json +12 -8
package/README.md
CHANGED
|
@@ -1,40 +1,23 @@
|
|
|
1
1
|
# @glion/encode-escapes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Unified plugin to encode special characters as HL7v2 escape sequences in literal values.
|
|
4
4
|
|
|
5
|
-
## What
|
|
5
|
+
## What it does
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
This is the inverse of [`@glion/decode-escapes`](https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-decode-escapes), handling:
|
|
10
|
-
|
|
11
|
-
- Delimiter encoding (`|` → `\F\`, `^` → `\S\`, `~` → `\R\`, `&` → `\T\`)
|
|
12
|
-
- Escape character encoding (`\` → `\E\`)
|
|
13
|
-
- Line break encoding (`\r` → `\.br\`)
|
|
14
|
-
|
|
15
|
-
## When should I use this?
|
|
16
|
-
|
|
17
|
-
Use this plugin when you need to:
|
|
18
|
-
|
|
19
|
-
- Prepare an HL7v2 AST for serialization after modifying subcomponent values that may contain delimiter characters.
|
|
20
|
-
- Ensure values with special characters are safely encoded before converting the AST back to HL7v2 text with [`@glion/to-hl7v2`](https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-to-hl7v2).
|
|
7
|
+
Walks an HL7v2 AST and encodes delimiter characters found in `subcomponent` node values as HL7v2 escape sequences, so a tree that has been modified in memory can be safely serialized back to HL7v2 text without breaking the delimiter structure. It is the inverse of [`@glion/decode-escapes`](https://github.com/rethinkhealth/glion/tree/main/packages/decode-escapes): encode then decode round-trips to the original values.
|
|
21
8
|
|
|
22
9
|
## Install
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
In Node.js (version 18+), install with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):
|
|
27
|
-
|
|
28
|
-
```sh
|
|
11
|
+
```bash
|
|
29
12
|
npm install @glion/encode-escapes
|
|
30
13
|
```
|
|
31
14
|
|
|
32
15
|
## Use
|
|
33
16
|
|
|
34
17
|
```js
|
|
35
|
-
import { unified } from "unified";
|
|
36
18
|
import { hl7v2EncodeEscapes } from "@glion/encode-escapes";
|
|
37
19
|
import { hl7v2ToHl7v2 } from "@glion/to-hl7v2";
|
|
20
|
+
import { unified } from "unified";
|
|
38
21
|
|
|
39
22
|
// After modifying AST values that may contain delimiters:
|
|
40
23
|
const file = await unified()
|
|
@@ -75,9 +58,22 @@ Encode special characters as HL7v2 escape sequences in literal nodes.
|
|
|
75
58
|
|
|
76
59
|
Nothing (`undefined`). Mutates the AST in-place.
|
|
77
60
|
|
|
78
|
-
##
|
|
61
|
+
## Behavior
|
|
62
|
+
|
|
63
|
+
The plugin visits every `subcomponent` node and rewrites `node.value`, substituting delimiter and control characters with their HL7v2 escape sequences:
|
|
79
64
|
|
|
80
|
-
|
|
65
|
+
| Input | Output |
|
|
66
|
+
| ----- | ------------------------------ |
|
|
67
|
+
| `\|` | `\F\` (field separator) |
|
|
68
|
+
| `^` | `\S\` (component separator) |
|
|
69
|
+
| `~` | `\R\` (repetition separator) |
|
|
70
|
+
| `&` | `\T\` (subcomponent separator) |
|
|
71
|
+
| `\` | `\E\` (escape character) |
|
|
72
|
+
| `\r` | `\.br\` (line break directive) |
|
|
73
|
+
|
|
74
|
+
Delimiter resolution order: `Root.data.delimiters` (preferred, set by the parser) → `options.delimiters` → HL7 defaults.
|
|
75
|
+
|
|
76
|
+
This is the inverse of [`@glion/decode-escapes`](https://github.com/rethinkhealth/glion/tree/main/packages/decode-escapes):
|
|
81
77
|
|
|
82
78
|
```js
|
|
83
79
|
import { hl7v2DecodeEscapes } from "@glion/decode-escapes";
|
|
@@ -89,30 +85,11 @@ const decoded = await unified().use(hl7v2DecodeEscapes).run(encoded);
|
|
|
89
85
|
// decoded values === original values
|
|
90
86
|
```
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
This plugin only transforms AST nodes and does not execute code. Ensure you trust the source of HL7v2 messages before processing.
|
|
95
|
-
|
|
96
|
-
## Contributing
|
|
97
|
-
|
|
98
|
-
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
99
|
-
|
|
100
|
-
1. Fork the repository
|
|
101
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
102
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
103
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
104
|
-
5. Open a Pull Request
|
|
105
|
-
|
|
106
|
-
## Code of Conduct
|
|
107
|
-
|
|
108
|
-
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.
|
|
109
|
-
|
|
110
|
-
## License
|
|
88
|
+
The plugin only transforms AST nodes and does not execute code.
|
|
111
89
|
|
|
112
|
-
|
|
90
|
+
## Part of Glion
|
|
113
91
|
|
|
114
|
-
|
|
92
|
+
`@glion/encode-escapes` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
|
|
115
93
|
|
|
116
|
-
[
|
|
117
|
-
[
|
|
118
|
-
[github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
|
|
94
|
+
[Glion]: https://github.com/rethinkhealth/glion#readme
|
|
95
|
+
[Glion README]: https://github.com/rethinkhealth/glion#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/encode-escapes",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "hl7v2 plugin to encode special characters as hl7v2 escape sequences",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -35,21 +35,23 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"unified": "11.0.5",
|
|
37
37
|
"unist-util-visit": "5.1.0",
|
|
38
|
-
"@glion/utils": "0.15.
|
|
38
|
+
"@glion/utils": "0.15.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^25.5.0",
|
|
42
42
|
"@types/unist": "^3.0.3",
|
|
43
43
|
"@vitest/coverage-v8": "4.1.2",
|
|
44
|
+
"publint": "0.3.18",
|
|
44
45
|
"tsdown": "0.21.7",
|
|
45
46
|
"typescript": "^5.9.3",
|
|
46
47
|
"vfile": "^6.0.3",
|
|
47
48
|
"vitest": "4.1.2",
|
|
48
|
-
"@glion/
|
|
49
|
-
"@glion/
|
|
50
|
-
"@glion/decode-escapes": "0.15.
|
|
51
|
-
"@glion/
|
|
52
|
-
"@glion/
|
|
49
|
+
"@glion/builder": "0.15.3",
|
|
50
|
+
"@glion/ast": "0.15.3",
|
|
51
|
+
"@glion/decode-escapes": "0.15.3",
|
|
52
|
+
"@glion/check-readme": "0.15.3",
|
|
53
|
+
"@glion/tsconfig": "0.15.3",
|
|
54
|
+
"@glion/testing": "0.15.3"
|
|
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
|
}
|