@oxyhq/core 10.1.3 → 10.1.4
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.
|
@@ -46,28 +46,6 @@
|
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
47
|
exports.normalizeInlineText = normalizeInlineText;
|
|
48
48
|
exports.normalizeMultilineText = normalizeMultilineText;
|
|
49
|
-
/**
|
|
50
|
-
* Characters that make a value ineligible for the zero-work fast path, and the
|
|
51
|
-
* whitespace shapes that a normalized INLINE value can never contain.
|
|
52
|
-
*
|
|
53
|
-
* A value that matches nothing here is, by construction, already normalized:
|
|
54
|
-
* it holds only printable ASCII (which is NFC-stable, so `normalize('NFC')`
|
|
55
|
-
* would be a no-op), its only whitespace is the plain space, it has no leading
|
|
56
|
-
* or trailing space, and no run of two spaces. Returning it untouched skips
|
|
57
|
-
* three string allocations — worth it because the common case in the feed
|
|
58
|
-
* hydration hot path is text that is already clean.
|
|
59
|
-
*
|
|
60
|
-
* Non-global (safe for repeated `.test()`; a global regex is stateful).
|
|
61
|
-
*/
|
|
62
|
-
const INLINE_NEEDS_NORMALIZATION = /[^\x20-\x7E]|^ | $| {2}/;
|
|
63
|
-
/**
|
|
64
|
-
* Same idea as {@link INLINE_NEEDS_NORMALIZATION}, for MULTILINE values: `\n`
|
|
65
|
-
* joins the printable-ASCII fast-path alphabet, and the additional shapes a
|
|
66
|
-
* normalized body can never contain are a space adjacent to a line break — on
|
|
67
|
-
* either side, since every line is trimmed — and a run of three line breaks
|
|
68
|
-
* (more than one blank line).
|
|
69
|
-
*/
|
|
70
|
-
const MULTILINE_NEEDS_NORMALIZATION = /[^\x20-\x7E\n]|^[ \n]|[ \n]$| {2}| \n|\n |\n{3}/;
|
|
71
49
|
/** Any run of whitespace, including tabs, line breaks and Unicode spaces. */
|
|
72
50
|
const ANY_WHITESPACE_RUN = /\s+/g;
|
|
73
51
|
/**
|
|
@@ -129,9 +107,6 @@ const EXCESS_BLANK_LINES = /\n{3,}/g;
|
|
|
129
107
|
* Idempotent: `f(f(x)) === f(x)`.
|
|
130
108
|
*/
|
|
131
109
|
function normalizeInlineText(value) {
|
|
132
|
-
if (!INLINE_NEEDS_NORMALIZATION.test(value)) {
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
110
|
return value.normalize('NFC').replace(ANY_WHITESPACE_RUN, ' ').trim();
|
|
136
111
|
}
|
|
137
112
|
/**
|
|
@@ -167,9 +142,6 @@ function normalizeInlineText(value) {
|
|
|
167
142
|
* Idempotent: `f(f(x)) === f(x)`.
|
|
168
143
|
*/
|
|
169
144
|
function normalizeMultilineText(value) {
|
|
170
|
-
if (!MULTILINE_NEEDS_NORMALIZATION.test(value)) {
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
145
|
return value
|
|
174
146
|
.normalize('NFC')
|
|
175
147
|
.replace(LINE_BREAK_FORMS, '\n')
|