ezmedicationinput 0.1.43 → 0.1.45

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/segment.js DELETED
@@ -1,203 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitSigSegments = splitSigSegments;
4
- const COMMA_SEGMENT_STARTERS = new Set([
5
- "apply",
6
- "take",
7
- "instill",
8
- "inject",
9
- "spray",
10
- "use",
11
- "od",
12
- "os",
13
- "ou",
14
- "re",
15
- "le",
16
- "be",
17
- "right",
18
- "left",
19
- "both",
20
- "each"
21
- ]);
22
- const DIRECTIONAL_SEGMENT_STARTERS = new Set(["right", "left", "both", "each"]);
23
- const SEPARATOR_RULES = [
24
- {
25
- name: "double-slash",
26
- match: (input, index) => (input.startsWith("//", index) ? 2 : 0)
27
- },
28
- {
29
- name: "line-break",
30
- match: (input, index) => {
31
- const ch = input[index];
32
- if (ch === "\r" && input[index + 1] === "\n") {
33
- return 2;
34
- }
35
- return ch === "\n" || ch === "\r" ? 1 : 0;
36
- }
37
- },
38
- {
39
- name: "pipe",
40
- match: (input, index) => input[index] === "|" && hasNonWhitespaceAround(input, index) ? consumePipeRun(input, index) : 0
41
- },
42
- {
43
- name: "plus",
44
- match: (input, index) => input[index] === "+" && hasNonWhitespaceAround(input, index) ? 1 : 0
45
- },
46
- {
47
- name: "slash-divider",
48
- match: (input, index) => input[index] === "/" && isDividerSlash(input, index) ? 1 : 0
49
- },
50
- {
51
- name: "comma-clause",
52
- match: (input, index, currentStart) => input[index] === "," && shouldSplitComma(input, index, currentStart) ? 1 : 0
53
- }
54
- ];
55
- function splitSigSegments(input) {
56
- const segments = [];
57
- let currentStart = 0;
58
- let depth = 0;
59
- const pushSegment = (rawStart, rawEnd) => {
60
- let start = rawStart;
61
- let end = rawEnd;
62
- while (start < end && /\s/.test(input[start])) {
63
- start += 1;
64
- }
65
- while (end > start && /\s/.test(input[end - 1])) {
66
- end -= 1;
67
- }
68
- if (end <= start) {
69
- return;
70
- }
71
- segments.push({
72
- text: input.slice(start, end),
73
- start,
74
- end
75
- });
76
- };
77
- for (let index = 0; index < input.length; index += 1) {
78
- const ch = input[index];
79
- if (ch === "(" || ch === "[" || ch === "{") {
80
- depth += 1;
81
- continue;
82
- }
83
- if ((ch === ")" || ch === "]" || ch === "}") && depth > 0) {
84
- depth -= 1;
85
- continue;
86
- }
87
- if (depth > 0) {
88
- continue;
89
- }
90
- for (const rule of SEPARATOR_RULES) {
91
- const length = rule.match(input, index, currentStart);
92
- if (!length) {
93
- continue;
94
- }
95
- pushSegment(currentStart, index);
96
- currentStart = index + length;
97
- index = currentStart - 1;
98
- break;
99
- }
100
- }
101
- pushSegment(currentStart, input.length);
102
- if (segments.length > 0) {
103
- return segments;
104
- }
105
- const fallback = input.trim();
106
- if (!fallback) {
107
- return [];
108
- }
109
- const start = input.indexOf(fallback);
110
- return [{ text: fallback, start, end: start + fallback.length }];
111
- }
112
- function hasNonWhitespaceAround(input, index) {
113
- const left = previousNonWhitespace(input, index - 1);
114
- const right = nextNonWhitespace(input, index + 1);
115
- return left !== undefined && right !== undefined;
116
- }
117
- function isDividerSlash(input, index) {
118
- var _a, _b;
119
- if (input[index - 1] === "/" || input[index + 1] === "/") {
120
- return false;
121
- }
122
- const previous = previousNonWhitespace(input, index - 1);
123
- const next = nextNonWhitespace(input, index + 1);
124
- if (previous === undefined || next === undefined) {
125
- return false;
126
- }
127
- if (/\d/.test(previous) && /\d/.test(next)) {
128
- return false;
129
- }
130
- return /\s/.test((_a = input[index - 1]) !== null && _a !== void 0 ? _a : "") || /\s/.test((_b = input[index + 1]) !== null && _b !== void 0 ? _b : "");
131
- }
132
- function shouldSplitComma(input, index, currentStart) {
133
- var _a, _b;
134
- if (!hasNonWhitespaceAround(input, index)) {
135
- return false;
136
- }
137
- const left = input.slice(currentStart, index).trim();
138
- const right = input.slice(index + 1).trim();
139
- if (!left || !right) {
140
- return false;
141
- }
142
- if (startsWithTimeExpression(right)) {
143
- return false;
144
- }
145
- const rightToken = (_b = (_a = right.match(/^([a-z]+|\d+(?:\.\d+)?)/i)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.toLowerCase();
146
- if (!rightToken) {
147
- return false;
148
- }
149
- if (/^\d/.test(rightToken)) {
150
- return true;
151
- }
152
- if (COMMA_SEGMENT_STARTERS.has(rightToken)) {
153
- if (DIRECTIONAL_SEGMENT_STARTERS.has(rightToken)) {
154
- return looksLikeDirectionalClause(right);
155
- }
156
- return true;
157
- }
158
- return false;
159
- }
160
- function looksLikeDirectionalClause(text) {
161
- const normalized = text.trim().toLowerCase();
162
- if (!normalized) {
163
- return false;
164
- }
165
- if (/\b\d+(?:\.\d+)?\b/.test(normalized)) {
166
- return true;
167
- }
168
- return /\b(once|twice|thrice|daily|bid|tid|qid|q\d+[a-z0-9/-]*|every|prn|hs|morning|lunch|dinner|noon|night|weekly|monthly)\b/.test(normalized);
169
- }
170
- function startsWithTimeExpression(text) {
171
- const trimmed = text.replace(/^\s+/, "");
172
- if (!trimmed) {
173
- return false;
174
- }
175
- return (/^@\s*\d{1,2}([:.]\d{2})?\s*(am|pm)?\b/i.test(trimmed) ||
176
- /^\d{1,2}[:.]\d{2}\s*(am|pm)?\b/i.test(trimmed) ||
177
- /^\d{1,2}\s*(am|pm)\b/i.test(trimmed));
178
- }
179
- function previousNonWhitespace(input, index) {
180
- for (let cursor = index; cursor >= 0; cursor -= 1) {
181
- const ch = input[cursor];
182
- if (!/\s/.test(ch)) {
183
- return ch;
184
- }
185
- }
186
- return undefined;
187
- }
188
- function nextNonWhitespace(input, index) {
189
- for (let cursor = index; cursor < input.length; cursor += 1) {
190
- const ch = input[cursor];
191
- if (!/\s/.test(ch)) {
192
- return ch;
193
- }
194
- }
195
- return undefined;
196
- }
197
- function consumePipeRun(input, index) {
198
- let cursor = index;
199
- while (cursor < input.length && input[cursor] === "|") {
200
- cursor += 1;
201
- }
202
- return cursor - index;
203
- }