@rethinkhealth/hl7v2-utils 0.3.1 → 0.3.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/dist/index.d.ts +4 -7
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/dist/index.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -15,11 +15,10 @@ export declare function isEmptyNode(node: Nodes | null | undefined): boolean;
|
|
|
15
15
|
* Calculate the byte length of any HL7v2 AST node.
|
|
16
16
|
*
|
|
17
17
|
* For literal nodes (Subcomponent, SegmentHeader), returns the UTF-8 byte length of the value.
|
|
18
|
-
* For parent nodes, recursively calculates the length of all children
|
|
19
|
-
* per separator (assumed to be single-byte delimiters).
|
|
18
|
+
* For parent nodes, recursively calculates the length of all children. Delimiters are NOT included.
|
|
20
19
|
*
|
|
21
20
|
* @param node - The HL7v2 AST node to measure
|
|
22
|
-
* @returns The total byte length of the node
|
|
21
|
+
* @returns The total byte length of the node content
|
|
23
22
|
*
|
|
24
23
|
* @example
|
|
25
24
|
* ```ts
|
|
@@ -32,14 +31,13 @@ export declare function getByteLength(node: Nodes | null | undefined): number;
|
|
|
32
31
|
* Calculate the string length of any HL7v2 AST node.
|
|
33
32
|
*
|
|
34
33
|
* For literal nodes (Subcomponent, SegmentHeader), returns `value.length`.
|
|
35
|
-
* For parent nodes, recursively calculates the length of all children
|
|
36
|
-
* per separator (assumed to be single-character delimiters).
|
|
34
|
+
* For parent nodes, recursively calculates the length of all children. Delimiters are NOT included.
|
|
37
35
|
*
|
|
38
36
|
* Note: Returns JavaScript string length (UTF-16 code units). For UTF-8 byte
|
|
39
37
|
* length (e.g., for wire protocol), use `getByteLength` instead.
|
|
40
38
|
*
|
|
41
39
|
* @param node - The HL7v2 AST node to measure
|
|
42
|
-
* @returns The total string length of the node
|
|
40
|
+
* @returns The total string length of the node content
|
|
43
41
|
*
|
|
44
42
|
* @example
|
|
45
43
|
* ```ts
|
|
@@ -48,4 +46,3 @@ export declare function getByteLength(node: Nodes | null | undefined): number;
|
|
|
48
46
|
* ```
|
|
49
47
|
*/
|
|
50
48
|
export declare function getLength(node: Nodes | null | undefined): number;
|
|
51
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ function getByteLength(node) {
|
|
|
33
33
|
return Buffer.byteLength(node.value, "utf8");
|
|
34
34
|
}
|
|
35
35
|
return node.children.reduce(
|
|
36
|
-
(total, child
|
|
36
|
+
(total, child) => total + getByteLength(child),
|
|
37
37
|
0
|
|
38
38
|
);
|
|
39
39
|
}
|
|
@@ -44,10 +44,7 @@ function getLength(node) {
|
|
|
44
44
|
if ("value" in node) {
|
|
45
45
|
return node.value.length;
|
|
46
46
|
}
|
|
47
|
-
return node.children.reduce(
|
|
48
|
-
(total, child, i) => total + getLength(child) + (i < node.children.length - 1 ? 1 : 0),
|
|
49
|
-
0
|
|
50
|
-
);
|
|
47
|
+
return node.children.reduce((total, child) => total + getLength(child), 0);
|
|
51
48
|
}
|
|
52
49
|
export {
|
|
53
50
|
DEFAULT_DELIMITERS,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Nodes } from \"@rethinkhealth/hl7v2-ast\";\n\n// -------------\n// Delimiters\n// -------------\n\nexport const DEFAULT_DELIMITERS = {\n field: \"|\",\n component: \"^\",\n repetition: \"~\",\n subcomponent: \"&\",\n escape: \"\\\\\",\n segment: \"\\r\",\n};\n\n// -------------\n// General\n// -------------\n\n/**\n * Utility: check if a node is semantically empty\n */\nexport function isEmptyNode(node: Nodes | null | undefined): boolean {\n if (!node) {\n return true;\n }\n\n // If node has a \"value\" property (Subcomponent, maybe Component)\n if (\"value\" in node) {\n return !node.value || node.value.trim() === \"\";\n }\n\n // If node has children (Field, Component, Repetition, Segment, Root, etc.)\n if (\"children\" in node) {\n if (!node.children || node.children.length === 0) {\n return true;\n }\n\n // If node has more than one child, then it is considered non-empty\n if (node.children.length > 1) {\n return false;\n }\n\n // If node has only one child, then it is considered empty if the child is also empty\n return isEmptyNode(node.children[0]);\n }\n\n // Fallback: consider unknown node as non-empty\n return false;\n}\n\n// -------------\n// Byte Length\n// -------------\n\n/**\n * Calculate the byte length of any HL7v2 AST node.\n *\n * For literal nodes (Subcomponent, SegmentHeader), returns the UTF-8 byte length of the value.\n * For parent nodes, recursively calculates the length of all children
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Nodes } from \"@rethinkhealth/hl7v2-ast\";\n\n// -------------\n// Delimiters\n// -------------\n\nexport const DEFAULT_DELIMITERS = {\n field: \"|\",\n component: \"^\",\n repetition: \"~\",\n subcomponent: \"&\",\n escape: \"\\\\\",\n segment: \"\\r\",\n};\n\n// -------------\n// General\n// -------------\n\n/**\n * Utility: check if a node is semantically empty\n */\nexport function isEmptyNode(node: Nodes | null | undefined): boolean {\n if (!node) {\n return true;\n }\n\n // If node has a \"value\" property (Subcomponent, maybe Component)\n if (\"value\" in node) {\n return !node.value || node.value.trim() === \"\";\n }\n\n // If node has children (Field, Component, Repetition, Segment, Root, etc.)\n if (\"children\" in node) {\n if (!node.children || node.children.length === 0) {\n return true;\n }\n\n // If node has more than one child, then it is considered non-empty\n if (node.children.length > 1) {\n return false;\n }\n\n // If node has only one child, then it is considered empty if the child is also empty\n return isEmptyNode(node.children[0]);\n }\n\n // Fallback: consider unknown node as non-empty\n return false;\n}\n\n// -------------\n// Byte Length\n// -------------\n\n/**\n * Calculate the byte length of any HL7v2 AST node.\n *\n * For literal nodes (Subcomponent, SegmentHeader), returns the UTF-8 byte length of the value.\n * For parent nodes, recursively calculates the length of all children. Delimiters are NOT included.\n *\n * @param node - The HL7v2 AST node to measure\n * @returns The total byte length of the node content\n *\n * @example\n * ```ts\n * const field: Field = { type: \"field\", children: [...] };\n * const length = getByteLength(field); // e.g., 42\n * ```\n */\nexport function getByteLength(node: Nodes | null | undefined): number {\n if (!node) {\n return 0;\n }\n\n if (\"value\" in node) {\n return Buffer.byteLength(node.value, \"utf8\");\n }\n\n return node.children.reduce(\n (total, child) => total + getByteLength(child),\n 0\n );\n}\n\n// -------------\n// Length\n// -------------\n\n/**\n * Calculate the string length of any HL7v2 AST node.\n *\n * For literal nodes (Subcomponent, SegmentHeader), returns `value.length`.\n * For parent nodes, recursively calculates the length of all children. Delimiters are NOT included.\n *\n * Note: Returns JavaScript string length (UTF-16 code units). For UTF-8 byte\n * length (e.g., for wire protocol), use `getByteLength` instead.\n *\n * @param node - The HL7v2 AST node to measure\n * @returns The total string length of the node content\n *\n * @example\n * ```ts\n * const field: Field = { type: \"field\", children: [...] };\n * const length = getLength(field); // e.g., 42\n * ```\n */\nexport function getLength(node: Nodes | null | undefined): number {\n if (!node) {\n return 0;\n }\n\n if (\"value\" in node) {\n return node.value.length;\n }\n\n return node.children.reduce((total, child) => total + getLength(child), 0);\n}\n"],"mappings":";AAMO,IAAM,qBAAqB;AAAA,EAChC,OAAO;AAAA,EACP,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,SAAS;AACX;AASO,SAAS,YAAY,MAAyC;AACnE,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAGA,MAAI,WAAW,MAAM;AACnB,WAAO,CAAC,KAAK,SAAS,KAAK,MAAM,KAAK,MAAM;AAAA,EAC9C;AAGA,MAAI,cAAc,MAAM;AACtB,QAAI,CAAC,KAAK,YAAY,KAAK,SAAS,WAAW,GAAG;AAChD,aAAO;AAAA,IACT;AAGA,QAAI,KAAK,SAAS,SAAS,GAAG;AAC5B,aAAO;AAAA,IACT;AAGA,WAAO,YAAY,KAAK,SAAS,CAAC,CAAC;AAAA,EACrC;AAGA,SAAO;AACT;AAqBO,SAAS,cAAc,MAAwC;AACpE,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,MAAI,WAAW,MAAM;AACnB,WAAO,OAAO,WAAW,KAAK,OAAO,MAAM;AAAA,EAC7C;AAEA,SAAO,KAAK,SAAS;AAAA,IACnB,CAAC,OAAO,UAAU,QAAQ,cAAc,KAAK;AAAA,IAC7C;AAAA,EACF;AACF;AAwBO,SAAS,UAAU,MAAwC;AAChE,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,MAAI,WAAW,MAAM;AACnB,WAAO,KAAK,MAAM;AAAA,EACpB;AAEA,SAAO,KAAK,SAAS,OAAO,CAAC,OAAO,UAAU,QAAQ,UAAU,KAAK,GAAG,CAAC;AAC3E;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rethinkhealth/hl7v2-utils",
|
|
3
3
|
"description": "hl7v2 utilities",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Melek Somai",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"unist-builder": "^4.0.0",
|
|
25
25
|
"vfile": "^6.0.3",
|
|
26
26
|
"vitest": "^4.0.6",
|
|
27
|
-
"@rethinkhealth/hl7v2-ast": "0.3.
|
|
28
|
-
"@rethinkhealth/
|
|
29
|
-
"@rethinkhealth/
|
|
27
|
+
"@rethinkhealth/hl7v2-ast": "0.3.3",
|
|
28
|
+
"@rethinkhealth/testing": "0.0.2",
|
|
29
|
+
"@rethinkhealth/tsconfig": "0.0.1"
|
|
30
30
|
},
|
|
31
31
|
"repository": "rethinkhealth/hl7v2.git",
|
|
32
32
|
"homepage": "https://www.rethinkhealth.io/hl7v2/docs",
|
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
"nodejs",
|
|
39
39
|
"typescript"
|
|
40
40
|
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
41
44
|
"packageManager": "pnpm@10.14.0",
|
|
42
45
|
"publishConfig": {
|
|
43
46
|
"access": "public"
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAMtD,eAAO,MAAM,kBAAkB;;;;;;;CAO9B,CAAC;AAMF;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CA2BnE;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAcpE;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAchE"}
|