string-remove-widows 3.0.5 → 3.0.11
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/LICENSE +1 -1
- package/README.md +4 -5
- package/dist/string-remove-widows.esm.js +7 -351
- package/dist/string-remove-widows.umd.js +53 -35
- package/examples/_quickTake.js +1 -0
- package/examples/widow-word-removal-from-html.js +2 -1
- package/package.json +28 -80
- package/types/index.d.ts +26 -25
- package/types/util.d.ts +32 -12
- package/examples/api.json +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -26,18 +26,17 @@
|
|
|
26
26
|
|
|
27
27
|
## Install
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `2.1.0`.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
npm i string-remove-widows
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
If you need a legacy version which works with `require`, use version 2.1.0
|
|
36
|
-
|
|
37
35
|
## Quick Take
|
|
38
36
|
|
|
39
37
|
```js
|
|
40
38
|
import { strict as assert } from "assert";
|
|
39
|
+
|
|
41
40
|
import { removeWidows } from "string-remove-widows";
|
|
42
41
|
|
|
43
42
|
const { ranges, res } = removeWidows("Some text with many words on one line.");
|
|
@@ -50,7 +49,7 @@ assert.equal(res, "Some text with many words on one line.");
|
|
|
50
49
|
|
|
51
50
|
## Documentation
|
|
52
51
|
|
|
53
|
-
Please [visit codsen.com](https://codsen.com/os/string-remove-widows/) for a full description of the API
|
|
52
|
+
Please [visit codsen.com](https://codsen.com/os/string-remove-widows/) for a full description of the API and even a test <a href="https://codsen.com/os/string-remove-widows/play">playground</a>.
|
|
54
53
|
|
|
55
54
|
## Contributing
|
|
56
55
|
|
|
@@ -60,6 +59,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
60
59
|
|
|
61
60
|
MIT License
|
|
62
61
|
|
|
63
|
-
Copyright (c) 2010-
|
|
62
|
+
Copyright (c) 2010-2022 Roy Revelt and other contributors
|
|
64
63
|
|
|
65
64
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
|
@@ -1,359 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-remove-widows
|
|
3
3
|
* @fileoverview Helps to prevent widow words in a text
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-remove-widows/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const rawnbsp = "\u00A0";
|
|
18
|
-
const encodedNbspHtml = " ";
|
|
19
|
-
const encodedNbspCss = "\\00A0";
|
|
20
|
-
const encodedNbspJs = "\\u00A0";
|
|
21
|
-
const rawNdash = "\u2013";
|
|
22
|
-
const encodedNdashHtml = "–";
|
|
23
|
-
const encodedNdashCss = "\\2013";
|
|
24
|
-
const encodedNdashJs = "\\u2013";
|
|
25
|
-
const rawMdash = "\u2014";
|
|
26
|
-
const encodedMdashHtml = "—";
|
|
27
|
-
const encodedMdashCss = "\\2014";
|
|
28
|
-
const encodedMdashJs = "\\u2014";
|
|
29
|
-
const headsAndTailsJinja = [{
|
|
30
|
-
heads: "{{",
|
|
31
|
-
tails: "}}"
|
|
32
|
-
}, {
|
|
33
|
-
heads: ["{% if", "{%- if"],
|
|
34
|
-
tails: ["{% endif", "{%- endif"]
|
|
35
|
-
}, {
|
|
36
|
-
heads: ["{% for", "{%- for"],
|
|
37
|
-
tails: ["{% endfor", "{%- endfor"]
|
|
38
|
-
}, {
|
|
39
|
-
heads: ["{%", "{%-"],
|
|
40
|
-
tails: ["%}", "-%}"]
|
|
41
|
-
}, {
|
|
42
|
-
heads: "{#",
|
|
43
|
-
tails: "#}"
|
|
44
|
-
}];
|
|
45
|
-
const headsAndTailsHugo = [{
|
|
46
|
-
heads: "{{",
|
|
47
|
-
tails: "}}"
|
|
48
|
-
}];
|
|
49
|
-
const headsAndTailsHexo = [{
|
|
50
|
-
heads: ["<%", "<%=", "<%-"],
|
|
51
|
-
tails: ["%>", "=%>", "-%>"]
|
|
52
|
-
}];
|
|
53
|
-
const knownHTMLTags = ["abbr", "address", "area", "article", "aside", "audio", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "doctype", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "iframe", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "main", "map", "mark", "math", "menu", "menuitem", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "param", "picture", "pre", "progress", "rb", "rp", "rt", "rtc", "ruby", "samp", "script", "section", "select", "slot", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "ul", "var", "video", "wbr", "xml"];
|
|
54
|
-
|
|
55
|
-
const version = version$1;
|
|
56
|
-
const defaults = {
|
|
57
|
-
removeWidowPreventionMeasures: false,
|
|
58
|
-
convertEntities: true,
|
|
59
|
-
targetLanguage: "html",
|
|
60
|
-
UKPostcodes: false,
|
|
61
|
-
hyphens: true,
|
|
62
|
-
minWordCount: 4,
|
|
63
|
-
minCharCount: 5,
|
|
64
|
-
ignore: [],
|
|
65
|
-
reportProgressFunc: null,
|
|
66
|
-
reportProgressFuncFrom: 0,
|
|
67
|
-
reportProgressFuncTo: 100,
|
|
68
|
-
tagRanges: []
|
|
69
|
-
};
|
|
70
|
-
function removeWidows(str, originalOpts) {
|
|
71
|
-
const start = Date.now();
|
|
72
|
-
if (typeof str !== "string") {
|
|
73
|
-
if (str === undefined) {
|
|
74
|
-
throw new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string.");
|
|
75
|
-
} else {
|
|
76
|
-
throw new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof str}", equal to:\n${JSON.stringify(str, null, 4)}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (originalOpts && typeof originalOpts !== "object") {
|
|
80
|
-
throw new Error(`string-remove-widows: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof originalOpts}, equal to ${JSON.stringify(originalOpts, null, 4)}`);
|
|
81
|
-
}
|
|
82
|
-
const isArr = Array.isArray;
|
|
83
|
-
const len = str.length;
|
|
84
|
-
const rangesArr = new Ranges({
|
|
85
|
-
mergeType: 2
|
|
86
|
-
});
|
|
87
|
-
const punctuationCharsToConsiderWidowIssue = ["."];
|
|
88
|
-
const postcodeRegexFront = /[A-Z]{1,2}[0-9][0-9A-Z]?$/;
|
|
89
|
-
const postcodeRegexEnd = /^[0-9][A-Z]{2}/;
|
|
90
|
-
const leavePercForLastStage = 0.06;
|
|
91
|
-
let currentPercentageDone;
|
|
92
|
-
let lastPercentage = 0;
|
|
93
|
-
let wordCount = 0;
|
|
94
|
-
let charCount = 0;
|
|
95
|
-
let secondToLastWhitespaceStartedAt;
|
|
96
|
-
let secondToLastWhitespaceEndedAt;
|
|
97
|
-
let lastWhitespaceStartedAt;
|
|
98
|
-
let lastWhitespaceEndedAt;
|
|
99
|
-
let lastEncodedNbspStartedAt;
|
|
100
|
-
let lastEncodedNbspEndedAt;
|
|
101
|
-
let doNothingUntil;
|
|
102
|
-
let bumpWordCountAt;
|
|
103
|
-
const opts = { ...defaults,
|
|
104
|
-
...originalOpts
|
|
105
|
-
};
|
|
106
|
-
const whatWasDone = {
|
|
107
|
-
removeWidows: false,
|
|
108
|
-
convertEntities: false
|
|
109
|
-
};
|
|
110
|
-
if (!opts.ignore || !isArr(opts.ignore) && typeof opts.ignore !== "string") {
|
|
111
|
-
opts.ignore = [];
|
|
112
|
-
} else {
|
|
113
|
-
if (typeof opts.ignore === "string") {
|
|
114
|
-
opts.ignore = [opts.ignore];
|
|
115
|
-
}
|
|
116
|
-
if (opts.ignore.includes("all")) {
|
|
117
|
-
opts.ignore = opts.ignore.concat(headsAndTailsJinja.concat(headsAndTailsHexo));
|
|
118
|
-
} else if (opts.ignore.some(val => typeof val === "string")) {
|
|
119
|
-
let temp = [];
|
|
120
|
-
opts.ignore = opts.ignore.filter(val => {
|
|
121
|
-
if (typeof val === "string" && val.length) {
|
|
122
|
-
if (["nunjucks", "jinja", "liquid"].includes(val.trim().toLowerCase())) {
|
|
123
|
-
temp = temp.concat(headsAndTailsJinja);
|
|
124
|
-
} else if (["hugo"].includes(val.trim().toLowerCase())) {
|
|
125
|
-
temp = temp.concat(headsAndTailsHugo);
|
|
126
|
-
} else if (["hexo"].includes(val.trim().toLowerCase())) {
|
|
127
|
-
temp = temp.concat(headsAndTailsHexo);
|
|
128
|
-
}
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
if (typeof val === "object") {
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
if (temp.length) {
|
|
136
|
-
opts.ignore = opts.ignore.concat(temp);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
let ceil;
|
|
141
|
-
if (opts.reportProgressFunc) {
|
|
142
|
-
ceil = Math.floor(opts.reportProgressFuncTo - (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * leavePercForLastStage - opts.reportProgressFuncFrom);
|
|
143
|
-
}
|
|
144
|
-
function push(finalStart, finalEnd) {
|
|
145
|
-
let finalWhatToInsert = rawnbsp;
|
|
146
|
-
if (opts.removeWidowPreventionMeasures) {
|
|
147
|
-
finalWhatToInsert = " ";
|
|
148
|
-
} else if (opts.convertEntities) {
|
|
149
|
-
finalWhatToInsert = encodedNbspHtml;
|
|
150
|
-
if (typeof opts.targetLanguage === "string") {
|
|
151
|
-
if (opts.targetLanguage.trim().toLowerCase() === "css") {
|
|
152
|
-
finalWhatToInsert = encodedNbspCss;
|
|
153
|
-
} else if (opts.targetLanguage.trim().toLowerCase() === "js") {
|
|
154
|
-
finalWhatToInsert = encodedNbspJs;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (str.slice(finalStart, finalEnd) !== finalWhatToInsert) {
|
|
159
|
-
rangesArr.push(finalStart, finalEnd, finalWhatToInsert);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function resetAll() {
|
|
163
|
-
wordCount = 0;
|
|
164
|
-
charCount = 0;
|
|
165
|
-
secondToLastWhitespaceStartedAt = undefined;
|
|
166
|
-
secondToLastWhitespaceEndedAt = undefined;
|
|
167
|
-
lastWhitespaceStartedAt = undefined;
|
|
168
|
-
lastWhitespaceEndedAt = undefined;
|
|
169
|
-
lastEncodedNbspStartedAt = undefined;
|
|
170
|
-
lastEncodedNbspEndedAt = undefined;
|
|
171
|
-
}
|
|
172
|
-
resetAll();
|
|
173
|
-
for (let i = 0; i <= len; i++) {
|
|
174
|
-
if (!doNothingUntil && isArr(opts.ignore) && opts.ignore.length) {
|
|
175
|
-
opts.ignore.some((valObj, y) => {
|
|
176
|
-
if (isArr(valObj.heads) && valObj.heads.some(oneOfHeads => str.startsWith(oneOfHeads, i)) || typeof valObj.heads === "string" && str.startsWith(valObj.heads, i)) {
|
|
177
|
-
wordCount += 1;
|
|
178
|
-
doNothingUntil = opts.ignore[y].tails;
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (!doNothingUntil && bumpWordCountAt && bumpWordCountAt === i) {
|
|
184
|
-
wordCount += 1;
|
|
185
|
-
bumpWordCountAt = undefined;
|
|
186
|
-
}
|
|
187
|
-
if (typeof opts.reportProgressFunc === "function") {
|
|
188
|
-
currentPercentageDone = opts.reportProgressFuncFrom + Math.floor(i / len * (ceil || 1));
|
|
189
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
190
|
-
lastPercentage = currentPercentageDone;
|
|
191
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (!doNothingUntil && i && str[i] && str[i].trim() && (!str[i - 1] || str[i - 1] && !str[i - 1].trim())) {
|
|
195
|
-
lastWhitespaceEndedAt = i;
|
|
196
|
-
}
|
|
197
|
-
if (!doNothingUntil && str[i] && str[i].trim()) {
|
|
198
|
-
charCount += 1;
|
|
199
|
-
}
|
|
200
|
-
if (!doNothingUntil && opts.hyphens && (`-${rawMdash}${rawNdash}`.includes(str[i]) || str.startsWith(encodedNdashHtml, i) || str.startsWith(encodedNdashCss, i) || str.startsWith(encodedNdashJs, i) || str.startsWith(encodedMdashHtml, i) || str.startsWith(encodedMdashCss, i) || str.startsWith(encodedMdashJs, i)) && str[i + 1] && (!str[i + 1].trim() || str[i] === "&")) {
|
|
201
|
-
if (str[i - 1] && !str[i - 1].trim() && str[left(str, i)]) {
|
|
202
|
-
push(left(str, i) + 1, i);
|
|
203
|
-
whatWasDone.removeWidows = true;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (!doNothingUntil && (str.startsWith(" ", i) || str.startsWith(" ", i))) {
|
|
207
|
-
lastEncodedNbspStartedAt = i;
|
|
208
|
-
lastEncodedNbspEndedAt = i + 6;
|
|
209
|
-
if (str[i + 6] && str[i + 6].trim()) {
|
|
210
|
-
bumpWordCountAt = i + 6;
|
|
211
|
-
}
|
|
212
|
-
if (!opts.convertEntities) {
|
|
213
|
-
rangesArr.push(i, i + 6, rawnbsp);
|
|
214
|
-
whatWasDone.convertEntities = true;
|
|
215
|
-
} else if (opts.targetLanguage === "css" || opts.targetLanguage === "js") {
|
|
216
|
-
rangesArr.push(i, i + 6, opts.targetLanguage === "css" ? encodedNbspCss : encodedNbspJs);
|
|
217
|
-
whatWasDone.convertEntities = true;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (!doNothingUntil && str[i + 4] && str[i] === "\\" && str[i + 1] === "0" && str[i + 2] === "0" && str[i + 3].toUpperCase() === "A" && str[i + 4] === "0") {
|
|
221
|
-
lastEncodedNbspStartedAt = i;
|
|
222
|
-
lastEncodedNbspEndedAt = i + 5;
|
|
223
|
-
if (str[i + 5] && str[i + 5].trim()) {
|
|
224
|
-
bumpWordCountAt = i + 5;
|
|
225
|
-
}
|
|
226
|
-
if (!opts.convertEntities) {
|
|
227
|
-
rangesArr.push(i, i + 5, rawnbsp);
|
|
228
|
-
whatWasDone.convertEntities = true;
|
|
229
|
-
} else if (opts.targetLanguage === "html" || opts.targetLanguage === "js") {
|
|
230
|
-
rangesArr.push(i, i + 5, opts.targetLanguage === "html" ? encodedNbspHtml : encodedNbspJs);
|
|
231
|
-
whatWasDone.convertEntities = true;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
if (!doNothingUntil && str[i] === "\\" && str[i + 1] && str[i + 1].toLowerCase() === "u" && str[i + 2] === "0" && str[i + 3] === "0" && str[i + 4] && str[i + 4].toUpperCase() === "A" && str[i + 5] === "0") {
|
|
235
|
-
lastEncodedNbspStartedAt = i;
|
|
236
|
-
lastEncodedNbspEndedAt = i + 6;
|
|
237
|
-
if (str[i + 6] && str[i + 6].trim()) {
|
|
238
|
-
bumpWordCountAt = i + 6;
|
|
239
|
-
}
|
|
240
|
-
if (!opts.convertEntities) {
|
|
241
|
-
rangesArr.push(i, i + 6, rawnbsp);
|
|
242
|
-
} else if (opts.targetLanguage === "html" || opts.targetLanguage === "css") {
|
|
243
|
-
rangesArr.push(i, i + 6, opts.targetLanguage === "html" ? encodedNbspHtml : encodedNbspCss);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (!doNothingUntil && str[i] === rawnbsp) {
|
|
247
|
-
lastEncodedNbspStartedAt = i;
|
|
248
|
-
lastEncodedNbspEndedAt = i + 1;
|
|
249
|
-
if (opts.convertEntities) {
|
|
250
|
-
rangesArr.push(i, i + 1, opts.targetLanguage === "css" ? encodedNbspCss : opts.targetLanguage === "js" ? encodedNbspJs : encodedNbspHtml);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
if (!doNothingUntil && str[i] && str[i].trim() && (!str[i - 1] || !str[i - 1].trim())) {
|
|
254
|
-
wordCount += 1;
|
|
255
|
-
}
|
|
256
|
-
if (!doNothingUntil && (!str[i] || `\r\n`.includes(str[i]) || (str[i] === "\n" || str[i] === "\r" || str[i] === "\r" && str[i + 1] === "\n") && left(str, i) && punctuationCharsToConsiderWidowIssue.includes(str[left(str, i)]))) {
|
|
257
|
-
if ((!opts.minWordCount || wordCount >= opts.minWordCount) && (!opts.minCharCount || charCount >= opts.minCharCount)) {
|
|
258
|
-
let finalStart;
|
|
259
|
-
let finalEnd;
|
|
260
|
-
if (lastWhitespaceStartedAt !== undefined && lastWhitespaceEndedAt !== undefined && lastEncodedNbspStartedAt !== undefined && lastEncodedNbspEndedAt !== undefined) {
|
|
261
|
-
if (lastWhitespaceStartedAt > lastEncodedNbspStartedAt) {
|
|
262
|
-
finalStart = lastWhitespaceStartedAt;
|
|
263
|
-
finalEnd = lastWhitespaceEndedAt;
|
|
264
|
-
} else {
|
|
265
|
-
finalStart = lastEncodedNbspStartedAt;
|
|
266
|
-
finalEnd = lastEncodedNbspEndedAt;
|
|
267
|
-
}
|
|
268
|
-
} else if (lastWhitespaceStartedAt !== undefined && lastWhitespaceEndedAt !== undefined) {
|
|
269
|
-
finalStart = lastWhitespaceStartedAt;
|
|
270
|
-
finalEnd = lastWhitespaceEndedAt;
|
|
271
|
-
} else if (lastEncodedNbspStartedAt !== undefined && lastEncodedNbspEndedAt !== undefined) {
|
|
272
|
-
finalStart = lastEncodedNbspStartedAt;
|
|
273
|
-
finalEnd = lastEncodedNbspEndedAt;
|
|
274
|
-
}
|
|
275
|
-
if (!(finalStart && finalEnd) && secondToLastWhitespaceStartedAt && secondToLastWhitespaceEndedAt) {
|
|
276
|
-
finalStart = secondToLastWhitespaceStartedAt;
|
|
277
|
-
finalEnd = secondToLastWhitespaceEndedAt;
|
|
278
|
-
}
|
|
279
|
-
if (finalStart && finalEnd) {
|
|
280
|
-
push(finalStart, finalEnd);
|
|
281
|
-
whatWasDone.removeWidows = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
resetAll();
|
|
285
|
-
}
|
|
286
|
-
if (opts.UKPostcodes && str[i] && !str[i].trim() && str[i - 1] && str[i - 1].trim() && postcodeRegexFront.test(str.slice(0, i)) && str[right(str, i)] && postcodeRegexEnd.test(str.slice(right(str, i)))) {
|
|
287
|
-
push(i, right(str, i));
|
|
288
|
-
whatWasDone.removeWidows = true;
|
|
289
|
-
}
|
|
290
|
-
if (!doNothingUntil && str[i] && !str[i].trim() && str[i - 1] && str[i - 1].trim() && (lastWhitespaceStartedAt === undefined || str[lastWhitespaceStartedAt - 1] && str[lastWhitespaceStartedAt - 1].trim()) && !"/>".includes(str[right(str, i)]) && !str.slice(0, i).trim().endsWith("br") && !str.slice(0, i).trim().endsWith("hr") && !(str.slice(0, i).endsWith("<") && knownHTMLTags.some(tag => str.startsWith(tag, right(str, i))))) {
|
|
291
|
-
secondToLastWhitespaceStartedAt = lastWhitespaceStartedAt;
|
|
292
|
-
secondToLastWhitespaceEndedAt = lastWhitespaceEndedAt;
|
|
293
|
-
lastWhitespaceStartedAt = i;
|
|
294
|
-
lastWhitespaceEndedAt = undefined;
|
|
295
|
-
if (lastEncodedNbspStartedAt !== undefined || lastEncodedNbspEndedAt !== undefined) {
|
|
296
|
-
lastEncodedNbspStartedAt = undefined;
|
|
297
|
-
lastEncodedNbspEndedAt = undefined;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
let tempTailFinding;
|
|
301
|
-
if (doNothingUntil) {
|
|
302
|
-
if (typeof doNothingUntil === "string" && (!doNothingUntil.length || str.startsWith(doNothingUntil, i))) {
|
|
303
|
-
doNothingUntil = undefined;
|
|
304
|
-
} else if (isArr(doNothingUntil) && (!doNothingUntil.length || doNothingUntil.some(val => {
|
|
305
|
-
if (str.startsWith(val, i)) {
|
|
306
|
-
tempTailFinding = val;
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
}))) {
|
|
310
|
-
doNothingUntil = undefined;
|
|
311
|
-
i += tempTailFinding.length;
|
|
312
|
-
if (isArr(opts.ignore) && opts.ignore.length && str[i + 1]) {
|
|
313
|
-
opts.ignore.some(oneOfHeadsTailsObjs => {
|
|
314
|
-
return matchRightIncl(str, i, oneOfHeadsTailsObjs.tails, {
|
|
315
|
-
trimBeforeMatching: true,
|
|
316
|
-
cb: (_char, _theRemainderOfTheString, index) => {
|
|
317
|
-
if (index) {
|
|
318
|
-
i = index - 1;
|
|
319
|
-
if (str[i + 1] && str[i + 1].trim()) {
|
|
320
|
-
wordCount += 1;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (str[i] && `\r\n`.includes(str[i])) {
|
|
331
|
-
wordCount = 0;
|
|
332
|
-
charCount = 0;
|
|
333
|
-
}
|
|
334
|
-
if (isArr(opts.tagRanges) && opts.tagRanges.length && opts.tagRanges.some(rangeArr => {
|
|
335
|
-
if (i >= rangeArr[0] && i <= rangeArr[1] && rangeArr[1] - 1 > i) {
|
|
336
|
-
i = rangeArr[1] - 1;
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
})) ;
|
|
340
|
-
}
|
|
341
|
-
rApply(str, rangesArr.current()).split("").forEach((key, i) => {
|
|
342
|
-
});
|
|
343
|
-
return {
|
|
344
|
-
res: rApply(str, rangesArr.current(), opts.reportProgressFunc ? incomingPerc => {
|
|
345
|
-
currentPercentageDone = Math.floor((opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * (1 - leavePercForLastStage) + incomingPerc / 100 * (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * leavePercForLastStage);
|
|
346
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
347
|
-
lastPercentage = currentPercentageDone;
|
|
348
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
349
|
-
}
|
|
350
|
-
} : undefined),
|
|
351
|
-
ranges: rangesArr.current(),
|
|
352
|
-
log: {
|
|
353
|
-
timeTakenInMilliseconds: Date.now() - start
|
|
354
|
-
},
|
|
355
|
-
whatWasDone
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
export { defaults, removeWidows, version };
|
|
10
|
+
import{matchRightIncl as ee}from"string-match-left-right";import{left as N,right as D}from"string-left-right";import{Ranges as te}from"ranges-push";import{rApply as K}from"ranges-apply";var M="3.0.11";var h="\xA0",E=" ",S="\\00A0",w="\\u00A0",O="\u2013",J="–",U="\\2013",x="\\u2013",k="\u2014",I="—",B="\\2014",_="\\u2014",v=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],q=[{heads:"{{",tails:"}}"}],P=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],G=["abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"];var $e=M,ne={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function ce(t,f){let Z=Date.now();if(typeof t!="string")throw t===void 0?new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof t}", equal to:
|
|
11
|
+
${JSON.stringify(t,null,4)}`);if(f&&typeof f!="object")throw new Error(`string-remove-widows: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof f}, equal to ${JSON.stringify(f,null,4)}`);let b=Array.isArray,L=t.length,a=new te({mergeType:2}),Y=["."],z=/[A-Z]{1,2}[0-9][0-9A-Z]?$/,Q=/^[0-9][A-Z]{2}/,V=.06,$,A=0,g=0,W=0,y,T,d,c,r,u,s,p,n={...ne,...f},m={removeWidows:!1,convertEntities:!1};if(!n.ignore||!b(n.ignore)&&typeof n.ignore!="string")n.ignore=[];else if(typeof n.ignore=="string"&&(n.ignore=[n.ignore]),n.ignore.includes("all"))n.ignore=n.ignore.concat(v.concat(P));else if(n.ignore.some(e=>typeof e=="string")){let e=[];n.ignore=n.ignore.filter(i=>typeof i=="string"&&i.length?(["nunjucks","jinja","liquid"].includes(i.trim().toLowerCase())?e=e.concat(v):["hugo"].includes(i.trim().toLowerCase())?e=e.concat(q):["hexo"].includes(i.trim().toLowerCase())&&(e=e.concat(P)),!1):typeof i=="object"),e.length&&(n.ignore=n.ignore.concat(e))}let H;n.reportProgressFunc&&(H=Math.floor(n.reportProgressFuncTo-(n.reportProgressFuncTo-n.reportProgressFuncFrom)*V-n.reportProgressFuncFrom));function C(e,i){let o=h;n.removeWidowPreventionMeasures?o=" ":n.convertEntities&&(o=E,typeof n.targetLanguage=="string"&&(n.targetLanguage.trim().toLowerCase()==="css"?o=S:n.targetLanguage.trim().toLowerCase()==="js"&&(o=w))),t.slice(e,i)!==o&&a.push(e,i,o)}function F(){g=0,W=0,y=void 0,T=void 0,d=void 0,c=void 0,r=void 0,u=void 0}F();for(let e=0;e<=L;e++){if(!s&&b(n.ignore)&&n.ignore.length&&n.ignore.some((o,l)=>{if(b(o.heads)&&o.heads.some(R=>t.startsWith(R,e))||typeof o.heads=="string"&&t.startsWith(o.heads,e))return g+=1,s=n.ignore[l].tails,!0}),!s&&p&&p===e&&(g+=1,p=void 0),typeof n.reportProgressFunc=="function"&&($=n.reportProgressFuncFrom+Math.floor(e/L*(H||1)),$!==A&&(A=$,n.reportProgressFunc($))),!s&&e&&t[e]&&t[e].trim()&&(!t[e-1]||t[e-1]&&!t[e-1].trim())&&(c=e),!s&&t[e]&&t[e].trim()&&(W+=1),!s&&n.hyphens&&(`-${k}${O}`.includes(t[e])||t.startsWith(J,e)||t.startsWith(U,e)||t.startsWith(x,e)||t.startsWith(I,e)||t.startsWith(B,e)||t.startsWith(_,e))&&t[e+1]&&(!t[e+1].trim()||t[e]==="&")&&t[e-1]&&!t[e-1].trim()&&t[N(t,e)]&&(C(N(t,e)+1,e),m.removeWidows=!0),!s&&(t.startsWith(" ",e)||t.startsWith(" ",e))&&(r=e,u=e+6,t[e+6]&&t[e+6].trim()&&(p=e+6),n.convertEntities?(n.targetLanguage==="css"||n.targetLanguage==="js")&&(a.push(e,e+6,n.targetLanguage==="css"?S:w),m.convertEntities=!0):(a.push(e,e+6,h),m.convertEntities=!0)),!s&&t[e+4]&&t[e]==="\\"&&t[e+1]==="0"&&t[e+2]==="0"&&t[e+3].toUpperCase()==="A"&&t[e+4]==="0"&&(r=e,u=e+5,t[e+5]&&t[e+5].trim()&&(p=e+5),n.convertEntities?(n.targetLanguage==="html"||n.targetLanguage==="js")&&(a.push(e,e+5,n.targetLanguage==="html"?E:w),m.convertEntities=!0):(a.push(e,e+5,h),m.convertEntities=!0)),!s&&t[e]==="\\"&&t[e+1]&&t[e+1].toLowerCase()==="u"&&t[e+2]==="0"&&t[e+3]==="0"&&t[e+4]&&t[e+4].toUpperCase()==="A"&&t[e+5]==="0"&&(r=e,u=e+6,t[e+6]&&t[e+6].trim()&&(p=e+6),n.convertEntities?(n.targetLanguage==="html"||n.targetLanguage==="css")&&a.push(e,e+6,n.targetLanguage==="html"?E:S):a.push(e,e+6,h)),!s&&t[e]===h&&(r=e,u=e+1,n.convertEntities&&a.push(e,e+1,n.targetLanguage==="css"?S:n.targetLanguage==="js"?w:E)),!s&&t[e]&&t[e].trim()&&(!t[e-1]||!t[e-1].trim())&&(g+=1),!s&&(!t[e]||`\r
|
|
12
|
+
`.includes(t[e])||(t[e]===`
|
|
13
|
+
`||t[e]==="\r"||t[e]==="\r"&&t[e+1]===`
|
|
14
|
+
`)&&N(t,e)&&Y.includes(t[N(t,e)]))){if((!n.minWordCount||g>=n.minWordCount)&&(!n.minCharCount||W>=n.minCharCount)){let o,l;d!==void 0&&c!==void 0&&r!==void 0&&u!==void 0?d>r?(o=d,l=c):(o=r,l=u):d!==void 0&&c!==void 0?(o=d,l=c):r!==void 0&&u!==void 0&&(o=r,l=u),!(o&&l)&&y&&T&&(o=y,l=T),o&&l&&(C(o,l),m.removeWidows=!0)}F()}n.UKPostcodes&&t[e]&&!t[e].trim()&&t[e-1]&&t[e-1].trim()&&z.test(t.slice(0,e))&&t[D(t,e)]&&Q.test(t.slice(D(t,e)))&&(C(e,D(t,e)),m.removeWidows=!0),!s&&t[e]&&!t[e].trim()&&t[e-1]&&t[e-1].trim()&&(d===void 0||t[d-1]&&t[d-1].trim())&&!"/>".includes(t[D(t,e)])&&!t.slice(0,e).trim().endsWith("br")&&!t.slice(0,e).trim().endsWith("hr")&&!(t.slice(0,e).endsWith("<")&&G.some(o=>t.startsWith(o,D(t,e))))&&(y=d,T=c,d=e,c=void 0,(r!==void 0||u!==void 0)&&(r=void 0,u=void 0));let i;s&&(typeof s=="string"&&(!s.length||t.startsWith(s,e))?s=void 0:b(s)&&(!s.length||s.some(o=>{if(t.startsWith(o,e))return i=o,!0}))&&(s=void 0,e+=i.length,b(n.ignore)&&n.ignore.length&&t[e+1]&&n.ignore.some(o=>ee(t,e,o.tails,{trimBeforeMatching:!0,cb:(l,R,j)=>(j&&(e=j-1,t[e+1]&&t[e+1].trim()&&(g+=1)),!0)})))),t[e]&&`\r
|
|
15
|
+
`.includes(t[e])&&(g=0,W=0),b(n.tagRanges)&&n.tagRanges.length&&n.tagRanges.some(o=>{if(e>=o[0]&&e<=o[1]&&o[1]-1>e)return e=o[1]-1,!0})}return K(t,a.current()).split("").forEach((e,i)=>{}),{res:K(t,a.current(),n.reportProgressFunc?e=>{$=Math.floor((n.reportProgressFuncTo-n.reportProgressFuncFrom)*(1-V)+e/100*(n.reportProgressFuncTo-n.reportProgressFuncFrom)*V),$!==A&&(A=$,n.reportProgressFunc($))}:void 0),ranges:a.current(),log:{timeTakenInMilliseconds:Date.now()-Z},whatWasDone:m}}export{ne as defaults,ce as removeWidows,$e as version};
|
|
@@ -1,76 +1,94 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-remove-widows
|
|
3
3
|
* @fileoverview Helps to prevent widow words in a text
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-remove-widows/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).stringRemoveWidows={})}(this,(function(t){"use strict";
|
|
10
|
+
var stringRemoveWidows=(()=>{var rr=Object.create;var k=Object.defineProperty;var nr=Object.getOwnPropertyDescriptor;var or=Object.getOwnPropertyNames,xe=Object.getOwnPropertySymbols,sr=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty,ir=Object.prototype.propertyIsEnumerable;var ge=(e,t,r)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,T=(e,t)=>{for(var r in t||(t={}))Le.call(t,r)&&ge(e,r,t[r]);if(xe)for(var r of xe(t))ir.call(t,r)&&ge(e,r,t[r]);return e};var He=e=>k(e,"__esModule",{value:!0});var Ve=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ar=(e,t)=>{for(var r in t)k(e,r,{get:t[r],enumerable:!0})},Fe=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of or(t))!Le.call(e,u)&&(r||u!=="default")&&k(e,u,{get:()=>t[u],enumerable:!(o=nr(t,u))||o.enumerable});return e},Pe=(e,t)=>Fe(He(k(e!=null?rr(sr(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),ur=(e=>(t,r)=>e&&e.get(t)||(r=Fe(He({}),t,1),e&&e.set(t,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var fe=(e,t,r)=>(ge(e,typeof t!="symbol"?t+"":t,r),r);var Ze=Ve((mo,Ke)=>{var fr="[object Object]";function hr(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(r){}return t}function dr(e,t){return function(r){return e(t(r))}}var mr=Function.prototype,qe=Object.prototype,Ge=mr.toString,pr=qe.hasOwnProperty,$r=Ge.call(Object),br=qe.toString,yr=dr(Object.getPrototypeOf,Object);function wr(e){return!!e&&typeof e=="object"}function Er(e){if(!wr(e)||br.call(e)!=fr||hr(e))return!1;var t=yr(e);if(t===null)return!0;var r=pr.call(t,"constructor")&&t.constructor;return typeof r=="function"&&r instanceof r&&Ge.call(r)==$r}Ke.exports=Er});var Lt=Ve((K,P)=>{var Tr=200,Ye="__lodash_hash_undefined__",Xe=9007199254740991,he="[object Arguments]",Ar="[object Array]",ze="[object Boolean]",Qe="[object Date]",vr="[object Error]",de="[object Function]",et="[object GeneratorFunction]",te="[object Map]",tt="[object Number]",me="[object Object]",rt="[object Promise]",nt="[object RegExp]",re="[object Set]",ot="[object String]",st="[object Symbol]",pe="[object WeakMap]",it="[object ArrayBuffer]",ne="[object DataView]",at="[object Float32Array]",ut="[object Float64Array]",lt="[object Int8Array]",ct="[object Int16Array]",gt="[object Int32Array]",ft="[object Uint8Array]",ht="[object Uint8ClampedArray]",dt="[object Uint16Array]",mt="[object Uint32Array]",Sr=/[\\^$.*+?()[\]{}|]/g,_r=/\w*$/,Nr=/^\[object .+?Constructor\]$/,Cr=/^(?:0|[1-9]\d*)$/,w={};w[he]=w[Ar]=w[it]=w[ne]=w[ze]=w[Qe]=w[at]=w[ut]=w[lt]=w[ct]=w[gt]=w[te]=w[tt]=w[me]=w[nt]=w[re]=w[ot]=w[st]=w[ft]=w[ht]=w[dt]=w[mt]=!0;w[vr]=w[de]=w[pe]=!1;var Or=typeof global=="object"&&global&&global.Object===Object&&global,Wr=typeof self=="object"&&self&&self.Object===Object&&self,W=Or||Wr||Function("return this")(),pt=typeof K=="object"&&K&&!K.nodeType&&K,$t=pt&&typeof P=="object"&&P&&!P.nodeType&&P,Dr=$t&&$t.exports===pt;function Rr(e,t){return e.set(t[0],t[1]),e}function Ir(e,t){return e.add(t),e}function Mr(e,t){for(var r=-1,o=e?e.length:0;++r<o&&t(e[r],r,e)!==!1;);return e}function jr(e,t){for(var r=-1,o=t.length,u=e.length;++r<o;)e[u+r]=t[r];return e}function bt(e,t,r,o){var u=-1,n=e?e.length:0;for(o&&n&&(r=e[++u]);++u<n;)r=t(r,e[u],u,e);return r}function xr(e,t){for(var r=-1,o=Array(e);++r<e;)o[r]=t(r);return o}function Lr(e,t){return e==null?void 0:e[t]}function yt(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(r){}return t}function wt(e){var t=-1,r=Array(e.size);return e.forEach(function(o,u){r[++t]=[u,o]}),r}function $e(e,t){return function(r){return e(t(r))}}function Et(e){var t=-1,r=Array(e.size);return e.forEach(function(o){r[++t]=o}),r}var Hr=Array.prototype,Vr=Function.prototype,oe=Object.prototype,be=W["__core-js_shared__"],Tt=function(){var e=/[^.]+$/.exec(be&&be.keys&&be.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),At=Vr.toString,R=oe.hasOwnProperty,se=oe.toString,Fr=RegExp("^"+At.call(R).replace(Sr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),vt=Dr?W.Buffer:void 0,St=W.Symbol,_t=W.Uint8Array,Pr=$e(Object.getPrototypeOf,Object),Jr=Object.create,Br=oe.propertyIsEnumerable,Ur=Hr.splice,Nt=Object.getOwnPropertySymbols,kr=vt?vt.isBuffer:void 0,qr=$e(Object.keys,Object),ye=F(W,"DataView"),q=F(W,"Map"),we=F(W,"Promise"),Ee=F(W,"Set"),Te=F(W,"WeakMap"),G=F(Object,"create"),Gr=L(ye),Kr=L(q),Zr=L(we),Yr=L(Ee),Xr=L(Te),Ct=St?St.prototype:void 0,Ot=Ct?Ct.valueOf:void 0;function j(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1])}}function zr(){this.__data__=G?G(null):{}}function Qr(e){return this.has(e)&&delete this.__data__[e]}function en(e){var t=this.__data__;if(G){var r=t[e];return r===Ye?void 0:r}return R.call(t,e)?t[e]:void 0}function tn(e){var t=this.__data__;return G?t[e]!==void 0:R.call(t,e)}function rn(e,t){var r=this.__data__;return r[e]=G&&t===void 0?Ye:t,this}j.prototype.clear=zr;j.prototype.delete=Qr;j.prototype.get=en;j.prototype.has=tn;j.prototype.set=rn;function D(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1])}}function nn(){this.__data__=[]}function on(e){var t=this.__data__,r=ie(t,e);if(r<0)return!1;var o=t.length-1;return r==o?t.pop():Ur.call(t,r,1),!0}function sn(e){var t=this.__data__,r=ie(t,e);return r<0?void 0:t[r][1]}function an(e){return ie(this.__data__,e)>-1}function un(e,t){var r=this.__data__,o=ie(r,e);return o<0?r.push([e,t]):r[o][1]=t,this}D.prototype.clear=nn;D.prototype.delete=on;D.prototype.get=sn;D.prototype.has=an;D.prototype.set=un;function H(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1])}}function ln(){this.__data__={hash:new j,map:new(q||D),string:new j}}function cn(e){return ae(this,e).delete(e)}function gn(e){return ae(this,e).get(e)}function fn(e){return ae(this,e).has(e)}function hn(e,t){return ae(this,e).set(e,t),this}H.prototype.clear=ln;H.prototype.delete=cn;H.prototype.get=gn;H.prototype.has=fn;H.prototype.set=hn;function V(e){this.__data__=new D(e)}function dn(){this.__data__=new D}function mn(e){return this.__data__.delete(e)}function pn(e){return this.__data__.get(e)}function $n(e){return this.__data__.has(e)}function bn(e,t){var r=this.__data__;if(r instanceof D){var o=r.__data__;if(!q||o.length<Tr-1)return o.push([e,t]),this;r=this.__data__=new H(o)}return r.set(e,t),this}V.prototype.clear=dn;V.prototype.delete=mn;V.prototype.get=pn;V.prototype.has=$n;V.prototype.set=bn;function yn(e,t){var r=Se(e)||Bn(e)?xr(e.length,String):[],o=r.length,u=!!o;for(var n in e)(t||R.call(e,n))&&!(u&&(n=="length"||Vn(n,o)))&&r.push(n);return r}function Wt(e,t,r){var o=e[t];(!(R.call(e,t)&&Mt(o,r))||r===void 0&&!(t in e))&&(e[t]=r)}function ie(e,t){for(var r=e.length;r--;)if(Mt(e[r][0],t))return r;return-1}function wn(e,t){return e&&Dt(t,_e(t),e)}function Ae(e,t,r,o,u,n,g){var a;if(o&&(a=n?o(e,u,n,g):o(e)),a!==void 0)return a;if(!ue(e))return e;var c=Se(e);if(c){if(a=xn(e),!t)return In(e,a)}else{var i=x(e),f=i==de||i==et;if(kn(e))return _n(e,t);if(i==me||i==he||f&&!n){if(yt(e))return n?e:{};if(a=Ln(f?{}:e),!t)return Mn(e,wn(a,e))}else{if(!w[i])return n?e:{};a=Hn(e,i,Ae,t)}}g||(g=new V);var m=g.get(e);if(m)return m;if(g.set(e,a),!c)var p=r?jn(e):_e(e);return Mr(p||e,function(d,h){p&&(h=d,d=e[h]),Wt(a,h,Ae(d,t,r,o,h,e,g))}),a}function En(e){return ue(e)?Jr(e):{}}function Tn(e,t,r){var o=t(e);return Se(e)?o:jr(o,r(e))}function An(e){return se.call(e)}function vn(e){if(!ue(e)||Pn(e))return!1;var t=xt(e)||yt(e)?Fr:Nr;return t.test(L(e))}function Sn(e){if(!It(e))return qr(e);var t=[];for(var r in Object(e))R.call(e,r)&&r!="constructor"&&t.push(r);return t}function _n(e,t){if(t)return e.slice();var r=new e.constructor(e.length);return e.copy(r),r}function ve(e){var t=new e.constructor(e.byteLength);return new _t(t).set(new _t(e)),t}function Nn(e,t){var r=t?ve(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)}function Cn(e,t,r){var o=t?r(wt(e),!0):wt(e);return bt(o,Rr,new e.constructor)}function On(e){var t=new e.constructor(e.source,_r.exec(e));return t.lastIndex=e.lastIndex,t}function Wn(e,t,r){var o=t?r(Et(e),!0):Et(e);return bt(o,Ir,new e.constructor)}function Dn(e){return Ot?Object(Ot.call(e)):{}}function Rn(e,t){var r=t?ve(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}function In(e,t){var r=-1,o=e.length;for(t||(t=Array(o));++r<o;)t[r]=e[r];return t}function Dt(e,t,r,o){r||(r={});for(var u=-1,n=t.length;++u<n;){var g=t[u],a=o?o(r[g],e[g],g,r,e):void 0;Wt(r,g,a===void 0?e[g]:a)}return r}function Mn(e,t){return Dt(e,Rt(e),t)}function jn(e){return Tn(e,_e,Rt)}function ae(e,t){var r=e.__data__;return Fn(t)?r[typeof t=="string"?"string":"hash"]:r.map}function F(e,t){var r=Lr(e,t);return vn(r)?r:void 0}var Rt=Nt?$e(Nt,Object):Kn,x=An;(ye&&x(new ye(new ArrayBuffer(1)))!=ne||q&&x(new q)!=te||we&&x(we.resolve())!=rt||Ee&&x(new Ee)!=re||Te&&x(new Te)!=pe)&&(x=function(e){var t=se.call(e),r=t==me?e.constructor:void 0,o=r?L(r):void 0;if(o)switch(o){case Gr:return ne;case Kr:return te;case Zr:return rt;case Yr:return re;case Xr:return pe}return t});function xn(e){var t=e.length,r=e.constructor(t);return t&&typeof e[0]=="string"&&R.call(e,"index")&&(r.index=e.index,r.input=e.input),r}function Ln(e){return typeof e.constructor=="function"&&!It(e)?En(Pr(e)):{}}function Hn(e,t,r,o){var u=e.constructor;switch(t){case it:return ve(e);case ze:case Qe:return new u(+e);case ne:return Nn(e,o);case at:case ut:case lt:case ct:case gt:case ft:case ht:case dt:case mt:return Rn(e,o);case te:return Cn(e,o,r);case tt:case ot:return new u(e);case nt:return On(e);case re:return Wn(e,o,r);case st:return Dn(e)}}function Vn(e,t){return t=t==null?Xe:t,!!t&&(typeof e=="number"||Cr.test(e))&&e>-1&&e%1==0&&e<t}function Fn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Pn(e){return!!Tt&&Tt in e}function It(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||oe;return e===r}function L(e){if(e!=null){try{return At.call(e)}catch(t){}try{return e+""}catch(t){}}return""}function Jn(e){return Ae(e,!0,!0)}function Mt(e,t){return e===t||e!==e&&t!==t}function Bn(e){return Un(e)&&R.call(e,"callee")&&(!Br.call(e,"callee")||se.call(e)==he)}var Se=Array.isArray;function jt(e){return e!=null&&qn(e.length)&&!xt(e)}function Un(e){return Gn(e)&&jt(e)}var kn=kr||Zn;function xt(e){var t=ue(e)?se.call(e):"";return t==de||t==et}function qn(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Xe}function ue(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Gn(e){return!!e&&typeof e=="object"}function _e(e){return jt(e)?yn(e):Sn(e)}function Kn(){return[]}function Zn(){return!1}P.exports=Jn});var uo={};ar(uo,{defaults:()=>tr,removeWidows:()=>ao,version:()=>io});function Je(e){return typeof e=="string"?e.length?[e]:[]:e}function Be(e){return e&&typeof e=="object"&&!Array.isArray(e)}function ee(e){return typeof e=="string"}var Ue={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},lr=e=>e+1;function cr(e,t,r,o,u=!1,n=lr){let g=typeof r=="function"?r():r;if(+t<0&&u&&g==="EOL")return g;let a=T(T({},Ue),o);if(t>=e.length&&!u)return!1;let c=u?1:r.length,i=0,f=!1,m=!1,p=!1,d=a.maxMismatches,h=t,A=!1,b=!1,y=!1;function v(){return i===1&&d<a.maxMismatches-1}for(;e[h];){let S=n(h);if(a.trimBeforeMatching&&e[h].trim()===""){if(!e[S]&&u&&r==="EOL")return!0;h=n(h);continue}if(a&&!a.i&&a.trimCharsBeforeMatching&&a.trimCharsBeforeMatching.includes(e[h])||(a==null?void 0:a.i)&&a.trimCharsBeforeMatching&&a.trimCharsBeforeMatching.map(_=>_.toLowerCase()).includes(e[h].toLowerCase())){if(u&&r==="EOL"&&!e[S])return!0;h=n(h);continue}let E=S>h?r[r.length-c]:r[c-1];if(!a.i&&e[h]===E||a.i&&e[h].toLowerCase()===E.toLowerCase()){if(A||(A=!0),p||(p=!0),c===r.length){if(b=!0,d!==a.maxMismatches)return!1}else c===1&&(y=!0);if(c-=1,i++,v())return!1;if(!c)return i!==r.length||d===a.maxMismatches||!f?h:!1}else if(!f&&!i&&(f=!0),a.maxMismatches&&d&&h){d-=1;for(let _=0;_<=d;_++){let l=S>h?r[r.length-c+1+_]:r[c-2-_],C=e[n(h)];if(l&&(!a.i&&e[h]===l||a.i&&e[h].toLowerCase()===l.toLowerCase())&&(!a.firstMustMatch||c!==r.length)){if(i++,v())return!1;c-=2,A=!0;break}else if(C&&l&&(!a.i&&C===l||a.i&&C.toLowerCase()===l.toLowerCase())&&(!a.firstMustMatch||c!==r.length)){if(!i&&!a.hungry)return!1;c-=1,A=!0;break}else if(l===void 0&&d>=0&&A&&(!a.firstMustMatch||b)&&(!a.lastMustMatch||y))return h}A||(m=h)}else return h===0&&c===1&&!a.lastMustMatch&&p?0:!1;if(m!==!1&&m!==h&&(m=!1),c<1)return h;h=n(h)}if(c>0)return u&&g==="EOL"?!0:a&&a.maxMismatches>=c&&p?m||0:!1}function gr(e,t,r,o,u){if(Be(u)&&Object.prototype.hasOwnProperty.call(u,"trimBeforeMatching")&&typeof u.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${e}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(u.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let n=T(T({},Ue),u);if(typeof n.trimCharsBeforeMatching=="string"&&(n.trimCharsBeforeMatching=Je(n.trimCharsBeforeMatching)),n.trimCharsBeforeMatching=n.trimCharsBeforeMatching.map(f=>ee(f)?f:String(f)),!ee(t)||!t.length)return!1;if(!Number.isInteger(r)||r<0)throw new Error(`string-match-left-right/${e}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof r}, equal to:
|
|
11
|
+
${JSON.stringify(r,null,4)}`);let g,a;if(ee(o))g=[o];else if(Array.isArray(o))g=o;else if(!o)g=o;else if(typeof o=="function")g=[],g.push(o);else throw new Error(`string-match-left-right/${e}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof o}, equal to:
|
|
12
|
+
${JSON.stringify(o,null,4)}`);if(u&&!Be(u))throw new Error(`string-match-left-right/${e}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof u}", and equal to:
|
|
13
|
+
${JSON.stringify(u,null,4)}`);let c=0,i="";if((n==null?void 0:n.trimCharsBeforeMatching)&&n.trimCharsBeforeMatching.some((f,m)=>f.length>1?(c=m,i=f,!0):!1))throw new Error(`string-match-left-right/${e}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${c} is longer than 1 character, ${i.length} (equals to ${i}). Please split it into separate characters and put into array as separate elements.`);if(!g||!Array.isArray(g)||Array.isArray(g)&&!g.length||Array.isArray(g)&&g.length===1&&ee(g[0])&&!g[0].trim()){if(typeof n.cb=="function"){let m,p=r;if((e==="matchLeftIncl"||e==="matchRight")&&(p+=1),e[5]==="L")for(let b=p;b--;){let y=t[b];if((!n.trimBeforeMatching||n.trimBeforeMatching&&y!==void 0&&y.trim())&&(!n.trimCharsBeforeMatching||!n.trimCharsBeforeMatching.length||y!==void 0&&!n.trimCharsBeforeMatching.includes(y))){m=b;break}}else if(e.startsWith("matchRight"))for(let b=p;b<t.length;b++){let y=t[b];if((!n.trimBeforeMatching||n.trimBeforeMatching&&y.trim())&&(!n.trimCharsBeforeMatching||!n.trimCharsBeforeMatching.length||!n.trimCharsBeforeMatching.includes(y))){m=b;break}}if(m===void 0)return!1;let d=t[m],h=m+1,A="";return h&&h>0&&(A=t.slice(0,h)),e[5]==="L"||m&&m>0&&(A=t.slice(m)),n.cb(d,A,m)}let f="";throw u||(f=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${e}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${f}`)}for(let f=0,m=g.length;f<m;f++){a=typeof g[f]=="function";let p=g[f],d,h,A="",b=r;e==="matchRight"?b+=1:e==="matchLeft"&&(b-=1);let y=cr(t,b,p,n,a,v=>e[5]==="L"?v-1:v+1);if(y&&a&&typeof p=="function"&&p()==="EOL")return p()&&(n.cb?n.cb(d,A,h):!0)?p():!1;if(Number.isInteger(y)&&(h=e.startsWith("matchLeft")?y-1:y+1,e[5]==="L"?A=t.slice(0,y):A=t.slice(h)),h<0&&(h=void 0),t[h]&&(d=t[h]),Number.isInteger(y)&&(n.cb?n.cb(d,A,h):!0))return p}return!1}function ke(e,t,r,o){return gr("matchRightIncl",e,t,r,o)}var Yn=Pe(Ze(),1),Xn=Pe(Lt(),1);var J="\xA0";function zn({str:e,idx:t=0,stopAtNewlines:r=!1,stopAtRawNbsp:o=!1}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),!e[t+1]))return null;if(e[t+1]&&(e[t+1].trim()||r&&`
|
|
14
|
+
\r`.includes(e[t+1])||o&&e[t+1]===J))return t+1;if(e[t+2]&&(e[t+2].trim()||r&&`
|
|
15
|
+
\r`.includes(e[t+2])||o&&e[t+2]===J))return t+2;for(let u=t+1,n=e.length;u<n;u++)if(e[u].trim()||r&&`
|
|
16
|
+
\r`.includes(e[u])||o&&e[u]===J)return u;return null}function B(e,t=0){return zn({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function Qn({str:e,idx:t,stopAtNewlines:r,stopAtRawNbsp:o}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),t<1))return null;if(e[~-t]&&(e[~-t].trim()||r&&`
|
|
17
|
+
\r`.includes(e[~-t])||o&&e[~-t]===J))return~-t;if(e[t-2]&&(e[t-2].trim()||r&&`
|
|
18
|
+
\r`.includes(e[t-2])||o&&e[t-2]===J))return t-2;for(let u=t;u--;)if(e[u]&&(e[u].trim()||r&&`
|
|
19
|
+
\r`.includes(e[u])||o&&e[u]===J))return u;return null}function Z(e,t=0){return Qn({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function le(e,t=1){let r="\xA0";function o(n){return Array.from(n).reverse().join("")}function u(n,g,a){let c=a?`
|
|
20
|
+
`:"\r",i=a?"\r":`
|
|
21
|
+
`;if(!n)return n;let f=0,m=0,p="";for(let d=0,h=n.length;d<h;d++)(n[d]===c||n[d]===i&&n[d-1]!==c)&&m++,`\r
|
|
22
|
+
`.includes(n[d])||n[d]===r?(f=0,n[d]===r?p+=n[d]:n[d]===c?m<=g&&(p+=n[d],n[d+1]===i&&(p+=n[d+1],d++)):n[d]===i&&(!n[d-1]||n[d-1]!==c)&&m<=g&&(p+=n[d])):(f++,!n[d+1]&&!m&&(p+=" "));return p}if(typeof e=="string"&&e.length){let n=1;typeof+t=="number"&&Number.isInteger(+t)&&+t>=0&&(n=+t);let g="",a="";if(!e.trim())g=e;else if(!e[0].trim()){for(let c=0,i=e.length;c<i;c++)if(e[c].trim()){g=e.slice(0,c);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===r)){for(let c=e.length;c--;)if(e[c].trim()){a=e.slice(c+1);break}}return`${u(g,n,!1)}${e.trim()}${o(u(o(a),n,!0))}`}return e}var eo={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Ht(e,t){if(!Array.isArray(e)||!e.length)return e;let r=T(T({},eo),t),o,u;if(r.strictlyTwoElementsInRangeArrays&&!e.every((a,c)=>!Array.isArray(a)||a.length!==2?(o=c,u=a.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${o}th range (${JSON.stringify(e[o],null,4)}) has not two but ${u} elements!`);if(!e.every((a,c)=>!Array.isArray(a)||!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(o=c,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${o}th range (${JSON.stringify(e[o],null,4)}) does not consist of only natural numbers!`);let n=e.length**2,g=0;return Array.from(e).sort((a,c)=>(r.progressFn&&(g+=1,r.progressFn(Math.floor(g*100/n))),a[0]===c[0]?a[1]<c[1]?-1:a[1]>c[1]?1:0:a[0]<c[0]?-1:1))}var Vt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function to(e,t){function r(i){return i&&typeof i=="object"&&!Array.isArray(i)}if(!Array.isArray(e)||!e.length)return null;let o;if(t)if(r(t)){if(o=T(T({},Vt),t),o.progressFn&&r(o.progressFn)&&!Object.keys(o.progressFn).length)o.progressFn=null;else if(o.progressFn&&typeof o.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof o.progressFn}", equal to ${JSON.stringify(o.progressFn,null,4)}`);if(![1,2,"1","2"].includes(o.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof o.mergeType}", equal to ${JSON.stringify(o.mergeType,null,4)}`);if(typeof o.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof o.joinRangesThatTouchEdges}", equal to ${JSON.stringify(o.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
|
|
23
|
+
${JSON.stringify(t,null,4)} (type ${typeof t})`);else o=T({},Vt);let u=e.filter(i=>Array.isArray(i)).map(i=>[...i]).filter(i=>i[2]!==void 0||i[0]!==i[1]),n,g,a;o.progressFn?n=Ht(u,{progressFn:i=>{a=Math.floor(i/5),a!==g&&(g=a,o.progressFn(a))}}):n=Ht(u);let c=n.length-1;for(let i=c;i>0;i--)o.progressFn&&(a=Math.floor((1-i/c)*78)+21,a!==g&&a>g&&(g=a,o.progressFn(a))),(n[i][0]<=n[i-1][0]||!o.joinRangesThatTouchEdges&&n[i][0]<n[i-1][1]||o.joinRangesThatTouchEdges&&n[i][0]<=n[i-1][1])&&(n[i-1][0]=Math.min(n[i][0],n[i-1][0]),n[i-1][1]=Math.max(n[i][1],n[i-1][1]),n[i][2]!==void 0&&(n[i-1][0]>=n[i][0]||n[i-1][1]<=n[i][1])&&n[i-1][2]!==null&&(n[i][2]===null&&n[i-1][2]!==null?n[i-1][2]=null:n[i-1][2]!=null?+o.mergeType==2&&n[i-1][0]===n[i][0]?n[i-1][2]=n[i][2]:n[i-1][2]+=n[i][2]:n[i-1][2]=n[i][2]),n.splice(i,1),i=n.length);return n.length?n:null}function I(e){return e!=null}function M(e){return Number.isInteger(e)&&e>=0}function Y(e){return typeof e=="string"}var ro={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},Ft=class{constructor(e){fe(this,"ranges");fe(this,"opts");let t=T(T({},ro),e);if(t.mergeType&&t.mergeType!==1&&t.mergeType!==2)if(Y(t.mergeType)&&t.mergeType.trim()==="1")t.mergeType=1;else if(Y(t.mergeType)&&t.mergeType.trim()==="2")t.mergeType=2;else throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof t.mergeType}", equal to ${JSON.stringify(t.mergeType,null,4)}`);this.opts=t,this.ranges=[]}add(e,t,r){if(e==null&&t==null)return;if(I(e)&&!I(t)){if(Array.isArray(e)){if(e.length){if(e.some(n=>Array.isArray(n))){e.forEach(n=>{Array.isArray(n)&&this.add(...n)});return}e.length&&M(+e[0])&&M(+e[1])&&this.add(...e)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(e,null,0)}) but second-one, "to" is not (${JSON.stringify(t,null,0)})`)}else if(!I(e)&&I(t))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(t,null,0)}) but first-one, "from" is not (${JSON.stringify(e,null,0)})`);let o=+e,u=+t;if(M(r)&&(r=String(r)),M(o)&&M(u)){if(I(r)&&!Y(r)&&!M(r))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof r}, equal to:
|
|
24
|
+
${JSON.stringify(r,null,4)}`);if(I(this.ranges)&&Array.isArray(this.last())&&o===this.last()[1]){if(this.last()[1]=u,this.last()[2],this.last()[2]!==null&&I(r)){let n=this.last()[2]&&this.last()[2].length>0&&(!this.opts||!this.opts.mergeType||this.opts.mergeType===1)?`${this.last()[2]}${r}`:r;this.opts.limitToBeAddedWhitespace&&(n=le(n,this.opts.limitLinebreaksCount)),Y(n)&&!n.length||(this.last()[2]=n)}}else{this.ranges||(this.ranges=[]);let n=r!==void 0&&!(Y(r)&&!r.length)?[o,u,r&&this.opts.limitToBeAddedWhitespace?le(r,this.opts.limitLinebreaksCount):r]:[o,u];this.ranges.push(n)}}else throw M(o)&&o>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof u}" equal to: ${JSON.stringify(u,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof o}" equal to: ${JSON.stringify(o,null,4)}`)}push(e,t,r){this.add(e,t,r)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=to(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>I(e[2])?[e[0],e[1],le(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&M(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var no={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Ne(e,t){if(!Array.isArray(e)||!e.length)return e;let r=T(T({},no),t),o,u;if(r.strictlyTwoElementsInRangeArrays&&!e.every((a,c)=>!Array.isArray(a)||a.length!==2?(o=c,u=a.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${o}th range (${JSON.stringify(e[o],null,4)}) has not two but ${u} elements!`);if(!e.every((a,c)=>!Array.isArray(a)||!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(o=c,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${o}th range (${JSON.stringify(e[o],null,4)}) does not consist of only natural numbers!`);let n=e.length**2,g=0;return Array.from(e).sort((a,c)=>(r.progressFn&&(g+=1,r.progressFn(Math.floor(g*100/n))),a[0]===c[0]?a[1]<c[1]?-1:a[1]>c[1]?1:0:a[0]<c[0]?-1:1))}var Pt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function Jt(e,t){function r(i){return i&&typeof i=="object"&&!Array.isArray(i)}if(!Array.isArray(e)||!e.length)return null;let o;if(t)if(r(t)){if(o=T(T({},Pt),t),o.progressFn&&r(o.progressFn)&&!Object.keys(o.progressFn).length)o.progressFn=null;else if(o.progressFn&&typeof o.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof o.progressFn}", equal to ${JSON.stringify(o.progressFn,null,4)}`);if(![1,2,"1","2"].includes(o.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof o.mergeType}", equal to ${JSON.stringify(o.mergeType,null,4)}`);if(typeof o.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof o.joinRangesThatTouchEdges}", equal to ${JSON.stringify(o.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
|
|
25
|
+
${JSON.stringify(t,null,4)} (type ${typeof t})`);else o=T({},Pt);let u=e.filter(i=>Array.isArray(i)).map(i=>[...i]).filter(i=>i[2]!==void 0||i[0]!==i[1]),n,g,a;o.progressFn?n=Ne(u,{progressFn:i=>{a=Math.floor(i/5),a!==g&&(g=a,o.progressFn(a))}}):n=Ne(u);let c=n.length-1;for(let i=c;i>0;i--)o.progressFn&&(a=Math.floor((1-i/c)*78)+21,a!==g&&a>g&&(g=a,o.progressFn(a))),(n[i][0]<=n[i-1][0]||!o.joinRangesThatTouchEdges&&n[i][0]<n[i-1][1]||o.joinRangesThatTouchEdges&&n[i][0]<=n[i-1][1])&&(n[i-1][0]=Math.min(n[i][0],n[i-1][0]),n[i-1][1]=Math.max(n[i][1],n[i-1][1]),n[i][2]!==void 0&&(n[i-1][0]>=n[i][0]||n[i-1][1]<=n[i][1])&&n[i-1][2]!==null&&(n[i][2]===null&&n[i-1][2]!==null?n[i-1][2]=null:n[i-1][2]!=null?+o.mergeType==2&&n[i-1][0]===n[i][0]?n[i-1][2]=n[i][2]:n[i-1][2]+=n[i][2]:n[i-1][2]=n[i][2]),n.splice(i,1),i=n.length);return n.length?n:null}var oo=!0,Ce="Invariant failed";function Bt(e,t){if(!e){if(oo)throw new Error(Ce);var r=typeof t=="function"?t():t,o=r?Ce+": "+r:Ce;throw new Error(o)}}function Oe(e,t,r){let o=0,u=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${JSON.stringify(t,null,4)}`);if(r&&typeof r!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(!t||!t.filter(f=>f).length)return e;let n;Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?n=[Array.from(t)]:n=Array.from(t);let g=n.length,a=0;n.filter(f=>f).forEach((f,m)=>{if(r&&(o=Math.floor(a/g*10),o!==u&&(u=o,r(o))),!Array.isArray(f))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${m}th element not an array: ${JSON.stringify(f,null,4)}, which is ${typeof f}`);if(!Number.isInteger(f[0])){if(!Number.isInteger(+f[0])||+f[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${m}th element, array ${JSON.stringify(f,null,0)}. Its first element is not an integer, string index, but ${typeof f[0]}, equal to: ${JSON.stringify(f[0],null,4)}.`);n[m][0]=+n[m][0]}if(!Number.isInteger(f[1])){if(!Number.isInteger(+f[1])||+f[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${m}th element, array ${JSON.stringify(f,null,0)}. Its second element is not an integer, string index, but ${typeof f[1]}, equal to: ${JSON.stringify(f[1],null,4)}.`);n[m][1]=+n[m][1]}a+=1});let c=Jt(n,{progressFn:f=>{r&&(o=10+Math.floor(f/10),o!==u&&(u=o,r(o)))}});Bt(c);let i=c.length;if(i>0){let f=e.slice(c[i-1][1]);e=c.reduce((m,p,d,h)=>{r&&(o=20+Math.floor(d/i*80),o!==u&&(u=o,r(o)));let A=d===0?0:h[d-1][1],b=h[d][0];return`${m}${e.slice(A,b)}${h[d][2]||""}`},""),e+=f}return e}var Ut="3.0.11";var U="\xA0",X=" ",z="\\00A0",Q="\\u00A0",kt="\u2013",qt="–",Gt="\\2013",Kt="\\u2013",Zt="\u2014",Yt="—",Xt="\\2014",zt="\\u2014",We=[{heads:"{{",tails:"}}"},{heads:["{% if","{%- if"],tails:["{% endif","{%- endif"]},{heads:["{% for","{%- for"],tails:["{% endfor","{%- endfor"]},{heads:["{%","{%-"],tails:["%}","-%}"]},{heads:"{#",tails:"#}"}],Qt=[{heads:"{{",tails:"}}"}],De=[{heads:["<%","<%=","<%-"],tails:["%>","=%>","-%>"]}],er=["abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"];var io=Ut,tr={removeWidowPreventionMeasures:!1,convertEntities:!0,targetLanguage:"html",UKPostcodes:!1,hyphens:!0,minWordCount:4,minCharCount:5,ignore:[],reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,tagRanges:[]};function ao(e,t){var lo;let r=Date.now();if(typeof e!="string")throw e===void 0?new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as "${typeof e}", equal to:
|
|
26
|
+
${JSON.stringify(e,null,4)}`);if(t&&typeof t!="object")throw new Error(`string-remove-widows: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof t}, equal to ${JSON.stringify(t,null,4)}`);let o=Array.isArray,u=e.length,n=new Ft({mergeType:2}),g=["."],a=/[A-Z]{1,2}[0-9][0-9A-Z]?$/,c=/^[0-9][A-Z]{2}/,i=.06,f,m=0,p=0,d=0,h,A,b,y,v,S,E,_,l=T(T({},tr),t),C={removeWidows:!1,convertEntities:!1};if(!l.ignore||!o(l.ignore)&&typeof l.ignore!="string")l.ignore=[];else if(typeof l.ignore=="string"&&(l.ignore=[l.ignore]),l.ignore.includes("all"))l.ignore=l.ignore.concat(We.concat(De));else if(l.ignore.some(s=>typeof s=="string")){let s=[];l.ignore=l.ignore.filter(N=>typeof N=="string"&&N.length?(["nunjucks","jinja","liquid"].includes(N.trim().toLowerCase())?s=s.concat(We):["hugo"].includes(N.trim().toLowerCase())?s=s.concat(Qt):["hexo"].includes(N.trim().toLowerCase())&&(s=s.concat(De)),!1):typeof N=="object"),s.length&&(l.ignore=l.ignore.concat(s))}let Re;l.reportProgressFunc&&(Re=Math.floor(l.reportProgressFuncTo-(l.reportProgressFuncTo-l.reportProgressFuncFrom)*i-l.reportProgressFuncFrom));function ce(s,N){let $=U;l.removeWidowPreventionMeasures?$=" ":l.convertEntities&&($=X,typeof l.targetLanguage=="string"&&(l.targetLanguage.trim().toLowerCase()==="css"?$=z:l.targetLanguage.trim().toLowerCase()==="js"&&($=Q))),e.slice(s,N)!==$&&n.push(s,N,$)}function Ie(){p=0,d=0,h=void 0,A=void 0,b=void 0,y=void 0,v=void 0,S=void 0}Ie();for(let s=0;s<=u;s++){if(!E&&o(l.ignore)&&l.ignore.length&&l.ignore.some(($,O)=>{if(o($.heads)&&$.heads.some(Me=>e.startsWith(Me,s))||typeof $.heads=="string"&&e.startsWith($.heads,s))return p+=1,E=l.ignore[O].tails,!0}),!E&&_&&_===s&&(p+=1,_=void 0),typeof l.reportProgressFunc=="function"&&(f=l.reportProgressFuncFrom+Math.floor(s/u*(Re||1)),f!==m&&(m=f,l.reportProgressFunc(f))),!E&&s&&e[s]&&e[s].trim()&&(!e[s-1]||e[s-1]&&!e[s-1].trim())&&(y=s),!E&&e[s]&&e[s].trim()&&(d+=1),!E&&l.hyphens&&(`-${Zt}${kt}`.includes(e[s])||e.startsWith(qt,s)||e.startsWith(Gt,s)||e.startsWith(Kt,s)||e.startsWith(Yt,s)||e.startsWith(Xt,s)||e.startsWith(zt,s))&&e[s+1]&&(!e[s+1].trim()||e[s]==="&")&&e[s-1]&&!e[s-1].trim()&&e[Z(e,s)]&&(ce(Z(e,s)+1,s),C.removeWidows=!0),!E&&(e.startsWith(" ",s)||e.startsWith(" ",s))&&(v=s,S=s+6,e[s+6]&&e[s+6].trim()&&(_=s+6),l.convertEntities?(l.targetLanguage==="css"||l.targetLanguage==="js")&&(n.push(s,s+6,l.targetLanguage==="css"?z:Q),C.convertEntities=!0):(n.push(s,s+6,U),C.convertEntities=!0)),!E&&e[s+4]&&e[s]==="\\"&&e[s+1]==="0"&&e[s+2]==="0"&&e[s+3].toUpperCase()==="A"&&e[s+4]==="0"&&(v=s,S=s+5,e[s+5]&&e[s+5].trim()&&(_=s+5),l.convertEntities?(l.targetLanguage==="html"||l.targetLanguage==="js")&&(n.push(s,s+5,l.targetLanguage==="html"?X:Q),C.convertEntities=!0):(n.push(s,s+5,U),C.convertEntities=!0)),!E&&e[s]==="\\"&&e[s+1]&&e[s+1].toLowerCase()==="u"&&e[s+2]==="0"&&e[s+3]==="0"&&e[s+4]&&e[s+4].toUpperCase()==="A"&&e[s+5]==="0"&&(v=s,S=s+6,e[s+6]&&e[s+6].trim()&&(_=s+6),l.convertEntities?(l.targetLanguage==="html"||l.targetLanguage==="css")&&n.push(s,s+6,l.targetLanguage==="html"?X:z):n.push(s,s+6,U)),!E&&e[s]===U&&(v=s,S=s+1,l.convertEntities&&n.push(s,s+1,l.targetLanguage==="css"?z:l.targetLanguage==="js"?Q:X)),!E&&e[s]&&e[s].trim()&&(!e[s-1]||!e[s-1].trim())&&(p+=1),!E&&(!e[s]||`\r
|
|
27
|
+
`.includes(e[s])||(e[s]===`
|
|
28
|
+
`||e[s]==="\r"||e[s]==="\r"&&e[s+1]===`
|
|
29
|
+
`)&&Z(e,s)&&g.includes(e[Z(e,s)]))){if((!l.minWordCount||p>=l.minWordCount)&&(!l.minCharCount||d>=l.minCharCount)){let $,O;b!==void 0&&y!==void 0&&v!==void 0&&S!==void 0?b>v?($=b,O=y):($=v,O=S):b!==void 0&&y!==void 0?($=b,O=y):v!==void 0&&S!==void 0&&($=v,O=S),!($&&O)&&h&&A&&($=h,O=A),$&&O&&(ce($,O),C.removeWidows=!0)}Ie()}l.UKPostcodes&&e[s]&&!e[s].trim()&&e[s-1]&&e[s-1].trim()&&a.test(e.slice(0,s))&&e[B(e,s)]&&c.test(e.slice(B(e,s)))&&(ce(s,B(e,s)),C.removeWidows=!0),!E&&e[s]&&!e[s].trim()&&e[s-1]&&e[s-1].trim()&&(b===void 0||e[b-1]&&e[b-1].trim())&&!"/>".includes(e[B(e,s)])&&!e.slice(0,s).trim().endsWith("br")&&!e.slice(0,s).trim().endsWith("hr")&&!(e.slice(0,s).endsWith("<")&&er.some($=>e.startsWith($,B(e,s))))&&(h=b,A=y,b=s,y=void 0,(v!==void 0||S!==void 0)&&(v=void 0,S=void 0));let N;E&&(typeof E=="string"&&(!E.length||e.startsWith(E,s))?E=void 0:o(E)&&(!E.length||E.some($=>{if(e.startsWith($,s))return N=$,!0}))&&(E=void 0,s+=N.length,o(l.ignore)&&l.ignore.length&&e[s+1]&&l.ignore.some($=>ke(e,s,$.tails,{trimBeforeMatching:!0,cb:(O,Me,je)=>(je&&(s=je-1,e[s+1]&&e[s+1].trim()&&(p+=1)),!0)})))),e[s]&&`\r
|
|
30
|
+
`.includes(e[s])&&(p=0,d=0),o(l.tagRanges)&&l.tagRanges.length&&l.tagRanges.some($=>{if(s>=$[0]&&s<=$[1]&&$[1]-1>s)return s=$[1]-1,!0})}return Oe(e,n.current()).split("").forEach((s,N)=>{}),{res:Oe(e,n.current(),l.reportProgressFunc?s=>{f=Math.floor((l.reportProgressFuncTo-l.reportProgressFuncFrom)*(1-i)+s/100*(l.reportProgressFuncTo-l.reportProgressFuncFrom)*i),f!==m&&(m=f,l.reportProgressFunc(f))}:void 0),ranges:n.current(),log:{timeTakenInMilliseconds:Date.now()-r},whatWasDone:C}}return ur(uo);})();
|
|
11
31
|
/**
|
|
12
32
|
* @name arrayiffy-if-string
|
|
13
33
|
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
|
|
14
|
-
* @version 4.0.
|
|
34
|
+
* @version 4.0.11
|
|
15
35
|
* @author Roy Revelt, Codsen Ltd
|
|
16
36
|
* @license MIT
|
|
17
37
|
* {@link https://codsen.com/os/arrayiffy-if-string/}
|
|
18
38
|
*/
|
|
19
39
|
/**
|
|
20
|
-
* @name
|
|
21
|
-
* @fileoverview
|
|
22
|
-
* @version
|
|
40
|
+
* @name ranges-apply
|
|
41
|
+
* @fileoverview Take an array of string index ranges, delete/replace the string according to them
|
|
42
|
+
* @version 6.0.11
|
|
23
43
|
* @author Roy Revelt, Codsen Ltd
|
|
24
44
|
* @license MIT
|
|
25
|
-
* {@link https://codsen.com/os/
|
|
45
|
+
* {@link https://codsen.com/os/ranges-apply/}
|
|
26
46
|
*/
|
|
27
|
-
function e(t){return t&&"object"==typeof t&&!Array.isArray(t)}function r(t){return"string"==typeof t}const n={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},o=t=>t+1;function i(t,e,r,i,s=!1,a=o){const u="function"==typeof r?r():r;if(+e<0&&s&&"EOL"===u)return u;const l={...n,...i};if(e>=t.length&&!s)return!1;let c=s?1:r.length,g=0,f=!1,h=!1,p=!1,y=l.maxMismatches,m=e,d=!1,b=!1,w=!1;function v(){return 1===g&&y<l.maxMismatches-1}for(;t[m];){const e=a(m);if(l.trimBeforeMatching&&""===t[m].trim()){if(!t[e]&&s&&"EOL"===r)return!0;m=a(m);continue}if(l&&!l.i&&l.trimCharsBeforeMatching&&l.trimCharsBeforeMatching.includes(t[m])||l&&l.i&&l.trimCharsBeforeMatching&&l.trimCharsBeforeMatching.map((t=>t.toLowerCase())).includes(t[m].toLowerCase())){if(s&&"EOL"===r&&!t[e])return!0;m=a(m);continue}const n=e>m?r[r.length-c]:r[c-1];if(!l.i&&t[m]===n||l.i&&t[m].toLowerCase()===n.toLowerCase()){if(d||(d=!0),p||(p=!0),c===r.length){if(b=!0,y!==l.maxMismatches)return!1}else 1===c&&(w=!0);if(c-=1,g++,v())return!1;if(!c)return(g!==r.length||y===l.maxMismatches||!f)&&m}else{if(f||g||(f=!0),!(l.maxMismatches&&y&&m))return!(0!==m||1!==c||l.lastMustMatch||!p)&&0;y-=1;for(let n=0;n<=y;n++){const o=e>m?r[r.length-c+1+n]:r[c-2-n],i=t[a(m)];if(o&&(!l.i&&t[m]===o||l.i&&t[m].toLowerCase()===o.toLowerCase())&&(!l.firstMustMatch||c!==r.length)){if(g++,v())return!1;c-=2,d=!0;break}if(i&&o&&(!l.i&&i===o||l.i&&i.toLowerCase()===o.toLowerCase())&&(!l.firstMustMatch||c!==r.length)){if(!g&&!l.hungry)return!1;c-=1,d=!0;break}if(void 0===o&&y>=0&&d&&(!l.firstMustMatch||b)&&(!l.lastMustMatch||w))return m}d||(h=m)}if(!1!==h&&h!==m&&(h=!1),c<1)return m;m=a(m)}return c>0?!(!s||"EOL"!==u)||!!(l&&l.maxMismatches>=c&&p)&&(h||0):void 0}function s(t,o,s,a){return function(t,o,s,a,u){if(e(u)&&Object.prototype.hasOwnProperty.call(u,"trimBeforeMatching")&&"boolean"!=typeof u.trimBeforeMatching)throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(u.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);const l={...n,...u};var c;if("string"==typeof l.trimCharsBeforeMatching&&(l.trimCharsBeforeMatching="string"==typeof(c=l.trimCharsBeforeMatching)?c.length?[c]:[]:c),l.trimCharsBeforeMatching=l.trimCharsBeforeMatching.map((t=>r(t)?t:String(t))),!r(o))return!1;if(!o.length)return!1;if(!Number.isInteger(s)||s<0)throw new Error(`string-match-left-right/${t}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof s}, equal to:\n${JSON.stringify(s,null,4)}`);let g,f;if(r(a))g=[a];else if(Array.isArray(a))g=a;else if(a){if("function"!=typeof a)throw new Error(`string-match-left-right/${t}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof a}, equal to:\n${JSON.stringify(a,null,4)}`);g=[],g.push(a)}else g=a;if(u&&!e(u))throw new Error(`string-match-left-right/${t}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof u}", and equal to:\n${JSON.stringify(u,null,4)}`);let h=0,p="";if(l&&l.trimCharsBeforeMatching&&l.trimCharsBeforeMatching.some(((t,e)=>t.length>1&&(h=e,p=t,!0))))throw new Error(`string-match-left-right/${t}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${h} is longer than 1 character, ${p.length} (equals to ${p}). Please split it into separate characters and put into array as separate elements.`);if(!g||!Array.isArray(g)||Array.isArray(g)&&!g.length||Array.isArray(g)&&1===g.length&&r(g[0])&&!g[0].trim()){if("function"==typeof l.cb){let e,r=s;if("matchLeftIncl"!==t&&"matchRight"!==t||(r+=1),"L"===t[5])for(let t=r;t--;){const r=o[t];if((!l.trimBeforeMatching||l.trimBeforeMatching&&void 0!==r&&r.trim())&&(!l.trimCharsBeforeMatching||!l.trimCharsBeforeMatching.length||void 0!==r&&!l.trimCharsBeforeMatching.includes(r))){e=t;break}}else if(t.startsWith("matchRight"))for(let t=r;t<o.length;t++){const r=o[t];if((!l.trimBeforeMatching||l.trimBeforeMatching&&r.trim())&&(!l.trimCharsBeforeMatching||!l.trimCharsBeforeMatching.length||!l.trimCharsBeforeMatching.includes(r))){e=t;break}}if(void 0===e)return!1;const n=o[e],i=e+1;let a="";return i&&i>0&&(a=o.slice(0,i)),"L"===t[5]||e&&e>0&&(a=o.slice(e)),l.cb(n,a,e)}let e="";throw u||(e=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${t}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${e}`)}for(let e=0,r=g.length;e<r;e++){f="function"==typeof g[e];const r=g[e];let n,a,u="",c=s;"matchRight"===t?c+=1:"matchLeft"===t&&(c-=1);const h=i(o,c,r,l,f,(e=>"L"===t[5]?e-1:e+1));if(h&&f&&"function"==typeof r&&"EOL"===r())return!(!r()||l.cb&&!l.cb(n,u,a))&&r();if(Number.isInteger(h)&&(a=t.startsWith("matchLeft")?h-1:h+1,u="L"===t[5]?o.slice(0,h):o.slice(a)),a<0&&(a=void 0),o[a]&&(n=o[a]),Number.isInteger(h)&&(!l.cb||l.cb(n,u,a)))return r}return!1}("matchRightIncl",t,o,s,a)}var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};Function.prototype.toString.call(Object);var u={exports:{}};!function(t,e){var r="__lodash_hash_undefined__",n=9007199254740991,o="[object Arguments]",i="[object Boolean]",s="[object Date]",u="[object Function]",l="[object GeneratorFunction]",c="[object Map]",g="[object Number]",f="[object Object]",h="[object Promise]",p="[object RegExp]",y="[object Set]",m="[object String]",d="[object Symbol]",b="[object WeakMap]",w="[object ArrayBuffer]",v="[object DataView]",_="[object Float32Array]",T="[object Float64Array]",O="[object Int8Array]",A="[object Int16Array]",j="[object Int32Array]",$="[object Uint8Array]",E="[object Uint8ClampedArray]",I="[object Uint16Array]",M="[object Uint32Array]",R=/\w*$/,W=/^\[object .+?Constructor\]$/,F=/^(?:0|[1-9]\d*)$/,C={};C[o]=C["[object Array]"]=C[w]=C[v]=C[i]=C[s]=C[_]=C[T]=C[O]=C[A]=C[j]=C[c]=C[g]=C[f]=C[p]=C[y]=C[m]=C[d]=C[$]=C[E]=C[I]=C[M]=!0,C["[object Error]"]=C[u]=C[b]=!1;var N="object"==typeof self&&self&&self.Object===Object&&self,S="object"==typeof a&&a&&a.Object===Object&&a||N||Function("return this")(),L=e&&!e.nodeType&&e,x=L&&t&&!t.nodeType&&t,D=x&&x.exports===L;function B(t,e){return t.set(e[0],e[1]),t}function H(t,e){return t.add(e),t}function J(t,e,r,n){var o=-1,i=t?t.length:0;for(n&&i&&(r=t[++o]);++o<i;)r=e(r,t[o],o,t);return r}function P(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function k(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function q(t,e){return function(r){return t(e(r))}}function U(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}var z,Z=Array.prototype,K=Function.prototype,V=Object.prototype,G=S["__core-js_shared__"],Q=(z=/[^.]+$/.exec(G&&G.keys&&G.keys.IE_PROTO||""))?"Symbol(src)_1."+z:"",X=K.toString,Y=V.hasOwnProperty,tt=V.toString,et=RegExp("^"+X.call(Y).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rt=D?S.Buffer:void 0,nt=S.Symbol,ot=S.Uint8Array,it=q(Object.getPrototypeOf,Object),st=Object.create,at=V.propertyIsEnumerable,ut=Z.splice,lt=Object.getOwnPropertySymbols,ct=rt?rt.isBuffer:void 0,gt=q(Object.keys,Object),ft=xt(S,"DataView"),ht=xt(S,"Map"),pt=xt(S,"Promise"),yt=xt(S,"Set"),mt=xt(S,"WeakMap"),dt=xt(Object,"create"),bt=Pt(ft),wt=Pt(ht),vt=Pt(pt),_t=Pt(yt),Tt=Pt(mt),Ot=nt?nt.prototype:void 0,At=Ot?Ot.valueOf:void 0;function jt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function $t(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Et(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function It(t){this.__data__=new $t(t)}function Mt(t,e){var r=qt(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&Ut(t)}(t)&&Y.call(t,"callee")&&(!at.call(t,"callee")||tt.call(t)==o)}(t)?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],n=r.length,i=!!n;for(var s in t)!e&&!Y.call(t,s)||i&&("length"==s||Ht(s,n))||r.push(s);return r}function Rt(t,e,r){var n=t[e];Y.call(t,e)&&kt(n,r)&&(void 0!==r||e in t)||(t[e]=r)}function Wt(t,e){for(var r=t.length;r--;)if(kt(t[r][0],e))return r;return-1}function Ft(t,e,r,n,a,h,b){var W;if(n&&(W=h?n(t,a,h,b):n(t)),void 0!==W)return W;if(!Kt(t))return t;var F=qt(t);if(F){if(W=function(t){var e=t.length,r=t.constructor(e);e&&"string"==typeof t[0]&&Y.call(t,"index")&&(r.index=t.index,r.input=t.input);return r}(t),!e)return function(t,e){var r=-1,n=t.length;e||(e=Array(n));for(;++r<n;)e[r]=t[r];return e}(t,W)}else{var N=Bt(t),S=N==u||N==l;if(zt(t))return function(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}(t,e);if(N==f||N==o||S&&!h){if(P(t))return h?t:{};if(W=function(t){return"function"!=typeof t.constructor||Jt(t)?{}:(e=it(t),Kt(e)?st(e):{});var e}(S?{}:t),!e)return function(t,e){return St(t,Dt(t),e)}(t,function(t,e){return t&&St(e,Vt(e),t)}(W,t))}else{if(!C[N])return h?t:{};W=function(t,e,r,n){var o=t.constructor;switch(e){case w:return Nt(t);case i:case s:return new o(+t);case v:return function(t,e){var r=e?Nt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,n);case _:case T:case O:case A:case j:case $:case E:case I:case M:return function(t,e){var r=e?Nt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,n);case c:return function(t,e,r){return J(e?r(k(t),!0):k(t),B,new t.constructor)}(t,n,r);case g:case m:return new o(t);case p:return function(t){var e=new t.constructor(t.source,R.exec(t));return e.lastIndex=t.lastIndex,e}(t);case y:return function(t,e,r){return J(e?r(U(t),!0):U(t),H,new t.constructor)}(t,n,r);case d:return a=t,At?Object(At.call(a)):{}}var a}(t,N,Ft,e)}}b||(b=new It);var L=b.get(t);if(L)return L;if(b.set(t,W),!F)var x=r?function(t){return function(t,e,r){var n=e(t);return qt(t)?n:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(n,r(t))}(t,Vt,Dt)}(t):Vt(t);return function(t,e){for(var r=-1,n=t?t.length:0;++r<n&&!1!==e(t[r],r,t););}(x||t,(function(o,i){x&&(o=t[i=o]),Rt(W,i,Ft(o,e,r,n,i,t,b))})),W}function Ct(t){return!(!Kt(t)||(e=t,Q&&Q in e))&&(Zt(t)||P(t)?et:W).test(Pt(t));var e}function Nt(t){var e=new t.constructor(t.byteLength);return new ot(e).set(new ot(t)),e}function St(t,e,r,n){r||(r={});for(var o=-1,i=e.length;++o<i;){var s=e[o],a=n?n(r[s],t[s],s,r,t):void 0;Rt(r,s,void 0===a?t[s]:a)}return r}function Lt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function xt(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Ct(r)?r:void 0}jt.prototype.clear=function(){this.__data__=dt?dt(null):{}},jt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},jt.prototype.get=function(t){var e=this.__data__;if(dt){var n=e[t];return n===r?void 0:n}return Y.call(e,t)?e[t]:void 0},jt.prototype.has=function(t){var e=this.__data__;return dt?void 0!==e[t]:Y.call(e,t)},jt.prototype.set=function(t,e){return this.__data__[t]=dt&&void 0===e?r:e,this},$t.prototype.clear=function(){this.__data__=[]},$t.prototype.delete=function(t){var e=this.__data__,r=Wt(e,t);return!(r<0)&&(r==e.length-1?e.pop():ut.call(e,r,1),!0)},$t.prototype.get=function(t){var e=this.__data__,r=Wt(e,t);return r<0?void 0:e[r][1]},$t.prototype.has=function(t){return Wt(this.__data__,t)>-1},$t.prototype.set=function(t,e){var r=this.__data__,n=Wt(r,t);return n<0?r.push([t,e]):r[n][1]=e,this},Et.prototype.clear=function(){this.__data__={hash:new jt,map:new(ht||$t),string:new jt}},Et.prototype.delete=function(t){return Lt(this,t).delete(t)},Et.prototype.get=function(t){return Lt(this,t).get(t)},Et.prototype.has=function(t){return Lt(this,t).has(t)},Et.prototype.set=function(t,e){return Lt(this,t).set(t,e),this},It.prototype.clear=function(){this.__data__=new $t},It.prototype.delete=function(t){return this.__data__.delete(t)},It.prototype.get=function(t){return this.__data__.get(t)},It.prototype.has=function(t){return this.__data__.has(t)},It.prototype.set=function(t,e){var r=this.__data__;if(r instanceof $t){var n=r.__data__;if(!ht||n.length<199)return n.push([t,e]),this;r=this.__data__=new Et(n)}return r.set(t,e),this};var Dt=lt?q(lt,Object):function(){return[]},Bt=function(t){return tt.call(t)};function Ht(t,e){return!!(e=null==e?n:e)&&("number"==typeof t||F.test(t))&&t>-1&&t%1==0&&t<e}function Jt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||V)}function Pt(t){if(null!=t){try{return X.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function kt(t,e){return t===e||t!=t&&e!=e}(ft&&Bt(new ft(new ArrayBuffer(1)))!=v||ht&&Bt(new ht)!=c||pt&&Bt(pt.resolve())!=h||yt&&Bt(new yt)!=y||mt&&Bt(new mt)!=b)&&(Bt=function(t){var e=tt.call(t),r=e==f?t.constructor:void 0,n=r?Pt(r):void 0;if(n)switch(n){case bt:return v;case wt:return c;case vt:return h;case _t:return y;case Tt:return b}return e});var qt=Array.isArray;function Ut(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=n}(t.length)&&!Zt(t)}var zt=ct||function(){return!1};function Zt(t){var e=Kt(t)?tt.call(t):"";return e==u||e==l}function Kt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Vt(t){return Ut(t)?Mt(t):function(t){if(!Jt(t))return gt(t);var e=[];for(var r in Object(t))Y.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}t.exports=function(t){return Ft(t,!0,!0)}}(u,u.exports);
|
|
28
47
|
/**
|
|
29
|
-
* @name
|
|
30
|
-
* @fileoverview
|
|
31
|
-
* @version
|
|
48
|
+
* @name ranges-merge
|
|
49
|
+
* @fileoverview Merge and sort string index ranges
|
|
50
|
+
* @version 8.0.11
|
|
32
51
|
* @author Roy Revelt, Codsen Ltd
|
|
33
52
|
* @license MIT
|
|
34
|
-
* {@link https://codsen.com/os/
|
|
53
|
+
* {@link https://codsen.com/os/ranges-merge/}
|
|
35
54
|
*/
|
|
36
|
-
const l=" ";function c(t,e=0){return function({str:t,idx:e=0,stopAtNewlines:r=!1,stopAtRawNbsp:n=!1}){if("string"!=typeof t||!t.length)return null;if(e&&"number"==typeof e||(e=0),!t[e+1])return null;if(t[e+1]&&(t[e+1].trim()||r&&"\n\r".includes(t[e+1])||n&&t[e+1]===l))return e+1;if(t[e+2]&&(t[e+2].trim()||r&&"\n\r".includes(t[e+2])||n&&t[e+2]===l))return e+2;for(let o=e+1,i=t.length;o<i;o++)if(t[o].trim()||r&&"\n\r".includes(t[o])||n&&t[o]===l)return o;return null}({str:t,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}function g(t,e=0){return function({str:t,idx:e,stopAtNewlines:r,stopAtRawNbsp:n}){if("string"!=typeof t||!t.length)return null;if(e&&"number"==typeof e||(e=0),e<1)return null;if(t[~-e]&&(t[~-e].trim()||r&&"\n\r".includes(t[~-e])||n&&t[~-e]===l))return~-e;if(t[e-2]&&(t[e-2].trim()||r&&"\n\r".includes(t[e-2])||n&&t[e-2]===l))return e-2;for(let o=e;o--;)if(t[o]&&(t[o].trim()||r&&"\n\r".includes(t[o])||n&&t[o]===l))return o;return null}({str:t,idx:e,stopAtNewlines:!1,stopAtRawNbsp:!1})}
|
|
37
|
-
/**
|
|
38
|
-
* @name string-collapse-leading-whitespace
|
|
39
|
-
* @fileoverview Collapse the leading and trailing whitespace of a string
|
|
40
|
-
* @version 6.0.5
|
|
41
|
-
* @author Roy Revelt, Codsen Ltd
|
|
42
|
-
* @license MIT
|
|
43
|
-
* {@link https://codsen.com/os/string-collapse-leading-whitespace/}
|
|
44
|
-
*/function f(t,e=1){function r(t){return Array.from(t).reverse().join("")}function n(t,e,r){const n=r?"\n":"\r",o=r?"\r":"\n";if(!t)return t;let i=0,s="";for(let r=0,a=t.length;r<a;r++)(t[r]===n||t[r]===o&&t[r-1]!==n)&&i++,"\r\n".includes(t[r])||" "===t[r]?" "===t[r]?s+=t[r]:t[r]===n?i<=e&&(s+=t[r],t[r+1]===o&&(s+=t[r+1],r++)):t[r]===o&&(!t[r-1]||t[r-1]!==n)&&i<=e&&(s+=t[r]):t[r+1]||i||(s+=" ");return s}if("string"==typeof t&&t.length){let o=1;"number"==typeof+e&&Number.isInteger(+e)&&+e>=0&&(o=+e);let i="",s="";if(t.trim()){if(!t[0].trim())for(let e=0,r=t.length;e<r;e++)if(t[e].trim()){i=t.slice(0,e);break}}else i=t;if(t.trim()&&(""===t.slice(-1).trim()||" "===t.slice(-1)))for(let e=t.length;e--;)if(t[e].trim()){s=t.slice(e+1);break}return`${n(i,o,!1)}${t.trim()}${r(n(r(s),o,!0))}`}return t}
|
|
45
55
|
/**
|
|
46
56
|
* @name ranges-push
|
|
47
57
|
* @fileoverview Gather string index ranges
|
|
48
|
-
* @version 6.0.
|
|
58
|
+
* @version 6.0.11
|
|
49
59
|
* @author Roy Revelt, Codsen Ltd
|
|
50
60
|
* @license MIT
|
|
51
61
|
* {@link https://codsen.com/os/ranges-push/}
|
|
52
|
-
*/
|
|
62
|
+
*/
|
|
53
63
|
/**
|
|
54
64
|
* @name ranges-sort
|
|
55
65
|
* @fileoverview Sort string index ranges
|
|
56
|
-
* @version 5.0.
|
|
66
|
+
* @version 5.0.11
|
|
57
67
|
* @author Roy Revelt, Codsen Ltd
|
|
58
68
|
* @license MIT
|
|
59
69
|
* {@link https://codsen.com/os/ranges-sort/}
|
|
60
|
-
*/
|
|
70
|
+
*/
|
|
61
71
|
/**
|
|
62
|
-
* @name
|
|
63
|
-
* @fileoverview
|
|
64
|
-
* @version
|
|
72
|
+
* @name string-collapse-leading-whitespace
|
|
73
|
+
* @fileoverview Collapse the leading and trailing whitespace of a string
|
|
74
|
+
* @version 6.0.11
|
|
65
75
|
* @author Roy Revelt, Codsen Ltd
|
|
66
76
|
* @license MIT
|
|
67
|
-
* {@link https://codsen.com/os/
|
|
68
|
-
*/
|
|
77
|
+
* {@link https://codsen.com/os/string-collapse-leading-whitespace/}
|
|
78
|
+
*/
|
|
69
79
|
/**
|
|
70
|
-
* @name
|
|
71
|
-
* @fileoverview
|
|
72
|
-
* @version
|
|
80
|
+
* @name string-left-right
|
|
81
|
+
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
|
|
82
|
+
* @version 5.0.11
|
|
73
83
|
* @author Roy Revelt, Codsen Ltd
|
|
74
84
|
* @license MIT
|
|
75
|
-
* {@link https://codsen.com/os/
|
|
76
|
-
*/
|
|
85
|
+
* {@link https://codsen.com/os/string-left-right/}
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* @name string-match-left-right
|
|
89
|
+
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
|
|
90
|
+
* @version 8.0.11
|
|
91
|
+
* @author Roy Revelt, Codsen Ltd
|
|
92
|
+
* @license MIT
|
|
93
|
+
* {@link https://codsen.com/os/string-match-left-right/}
|
|
94
|
+
*/
|
package/examples/_quickTake.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Widow word removal from text within HTML
|
|
2
2
|
|
|
3
3
|
import { strict as assert } from "assert";
|
|
4
|
-
import { stripHtml } from "
|
|
4
|
+
import { stripHtml } from "string-strip-html";
|
|
5
|
+
|
|
5
6
|
import { removeWidows } from "../dist/string-remove-widows.esm.js";
|
|
6
7
|
|
|
7
8
|
const someHtml = `The quick brown fox jumps of the lazy dog.<div class="a">`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-remove-widows",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
4
4
|
"description": "Helps to prevent widow words in a text",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"against",
|
|
@@ -38,97 +38,45 @@
|
|
|
38
38
|
},
|
|
39
39
|
"types": "types/index.d.ts",
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"tap": "tap",
|
|
56
|
-
"pretest": "npm run build",
|
|
57
|
-
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
58
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
59
|
-
"tsc": "tsc",
|
|
60
|
-
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
|
|
41
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
42
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
43
|
+
"dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
|
|
44
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
45
|
+
"lect": "node '../../ops/lect/lect.js'",
|
|
46
|
+
"letspublish": "yarn publish || :",
|
|
47
|
+
"lint": "eslint . --fix",
|
|
48
|
+
"perf": "node perf/check.js",
|
|
49
|
+
"prepare": "echo 'ready'",
|
|
50
|
+
"prettier": "prettier",
|
|
51
|
+
"prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
|
|
52
|
+
"pretest": "yarn run lect && yarn run build",
|
|
53
|
+
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
54
|
+
"unit": "uvu test"
|
|
61
55
|
},
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"--no-warnings",
|
|
70
|
-
"--experimental-loader",
|
|
71
|
-
"@istanbuljs/esm-loader-hook"
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
58
|
+
},
|
|
59
|
+
"c8": {
|
|
60
|
+
"check-coverage": true,
|
|
61
|
+
"exclude": [
|
|
62
|
+
"**/test/**/*.*"
|
|
72
63
|
],
|
|
73
|
-
"
|
|
64
|
+
"lines": 100
|
|
74
65
|
},
|
|
75
66
|
"lect": {
|
|
76
67
|
"licence": {
|
|
77
68
|
"extras": [
|
|
78
69
|
""
|
|
79
70
|
]
|
|
80
|
-
},
|
|
81
|
-
"req": "{ removeWidows, defaults, version }",
|
|
82
|
-
"various": {
|
|
83
|
-
"devDependencies": []
|
|
84
71
|
}
|
|
85
72
|
},
|
|
86
73
|
"dependencies": {
|
|
87
|
-
"
|
|
88
|
-
"ranges-
|
|
89
|
-
"
|
|
90
|
-
"string-left-right": "^
|
|
91
|
-
"string-match-left-right": "^8.0.5"
|
|
74
|
+
"ranges-apply": "^6.0.11",
|
|
75
|
+
"ranges-push": "^6.0.11",
|
|
76
|
+
"string-left-right": "^5.0.11",
|
|
77
|
+
"string-match-left-right": "^8.0.11"
|
|
92
78
|
},
|
|
93
79
|
"devDependencies": {
|
|
94
|
-
"
|
|
95
|
-
"@babel/core": "^7.16.0",
|
|
96
|
-
"@babel/node": "^7.16.0",
|
|
97
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
98
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
99
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
100
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
101
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
102
|
-
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
103
|
-
"@babel/preset-env": "^7.16.0",
|
|
104
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
105
|
-
"@babel/register": "^7.16.0",
|
|
106
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
107
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
108
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
109
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
110
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
111
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
112
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
113
|
-
"@types/node": "^16.11.6",
|
|
114
|
-
"@types/tap": "^15.0.5",
|
|
115
|
-
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
116
|
-
"@typescript-eslint/parser": "^5.3.0",
|
|
117
|
-
"core-js": "^3.19.1",
|
|
118
|
-
"cross-env": "^7.0.3",
|
|
119
|
-
"eslint": "^8.2.0",
|
|
120
|
-
"lect": "^0.18.5",
|
|
121
|
-
"rollup": "^2.59.0",
|
|
122
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
123
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
124
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
125
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
126
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
127
|
-
"tap": "^15.0.10",
|
|
128
|
-
"tslib": "^2.3.1",
|
|
129
|
-
"typescript": "^4.4.4"
|
|
130
|
-
},
|
|
131
|
-
"engines": {
|
|
132
|
-
"node": ">=12"
|
|
80
|
+
"string-strip-html": "^9.1.5"
|
|
133
81
|
}
|
|
134
82
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
declare type Range =
|
|
1
|
+
declare type Range =
|
|
2
|
+
| [from: number, to: number]
|
|
3
|
+
| [from: number, to: number, whatToInsert: string | null | undefined];
|
|
2
4
|
declare type Ranges = Range[] | null;
|
|
3
5
|
|
|
4
6
|
declare const version: string;
|
|
5
|
-
|
|
6
7
|
interface HeadsAndTailsObj {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
heads: string | string[];
|
|
9
|
+
tails: string | string[];
|
|
9
10
|
}
|
|
10
11
|
interface Opts {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
removeWidowPreventionMeasures: boolean;
|
|
13
|
+
convertEntities: boolean;
|
|
14
|
+
targetLanguage: "html" | "css" | "js";
|
|
15
|
+
UKPostcodes: boolean;
|
|
16
|
+
hyphens: boolean;
|
|
17
|
+
minWordCount: number;
|
|
18
|
+
minCharCount: number;
|
|
19
|
+
ignore: HeadsAndTailsObj[] | string | string[];
|
|
20
|
+
reportProgressFunc: null | ((percDone: number) => void);
|
|
21
|
+
reportProgressFuncFrom: number;
|
|
22
|
+
reportProgressFuncTo: number;
|
|
23
|
+
tagRanges: Range[] | null;
|
|
23
24
|
}
|
|
24
25
|
declare const defaults: Opts;
|
|
25
26
|
interface Res {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
res: string;
|
|
28
|
+
ranges: Ranges;
|
|
29
|
+
log: {
|
|
30
|
+
timeTakenInMilliseconds: number;
|
|
31
|
+
};
|
|
32
|
+
whatWasDone: {
|
|
33
|
+
removeWidows: boolean;
|
|
34
|
+
convertEntities: boolean;
|
|
35
|
+
};
|
|
35
36
|
}
|
|
36
37
|
declare function removeWidows(str: string, originalOpts?: Partial<Opts>): Res;
|
|
37
38
|
|
package/types/util.d.ts
CHANGED
|
@@ -10,20 +10,40 @@ declare const rawMdash = "\u2014";
|
|
|
10
10
|
declare const encodedMdashHtml = "—";
|
|
11
11
|
declare const encodedMdashCss = "\\2014";
|
|
12
12
|
declare const encodedMdashJs = "\\u2014";
|
|
13
|
-
declare const headsAndTailsJinja: (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
declare const headsAndTailsJinja: (
|
|
14
|
+
| {
|
|
15
|
+
heads: string;
|
|
16
|
+
tails: string;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
heads: string[];
|
|
20
|
+
tails: string[];
|
|
21
|
+
}
|
|
22
|
+
)[];
|
|
20
23
|
declare const headsAndTailsHugo: {
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
heads: string;
|
|
25
|
+
tails: string;
|
|
23
26
|
}[];
|
|
24
27
|
declare const headsAndTailsHexo: {
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
heads: string[];
|
|
29
|
+
tails: string[];
|
|
27
30
|
}[];
|
|
28
31
|
declare const knownHTMLTags: string[];
|
|
29
|
-
export {
|
|
32
|
+
export {
|
|
33
|
+
rawnbsp,
|
|
34
|
+
encodedNbspHtml,
|
|
35
|
+
encodedNbspCss,
|
|
36
|
+
encodedNbspJs,
|
|
37
|
+
rawNdash,
|
|
38
|
+
encodedNdashHtml,
|
|
39
|
+
encodedNdashCss,
|
|
40
|
+
encodedNdashJs,
|
|
41
|
+
rawMdash,
|
|
42
|
+
encodedMdashHtml,
|
|
43
|
+
encodedMdashCss,
|
|
44
|
+
encodedMdashJs,
|
|
45
|
+
headsAndTailsJinja,
|
|
46
|
+
headsAndTailsHugo,
|
|
47
|
+
headsAndTailsHexo,
|
|
48
|
+
knownHTMLTags,
|
|
49
|
+
};
|
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { removeWidows } from \"string-remove-widows\";\n\nconst { ranges, res } = removeWidows(\"Some text with many words on one line.\");\n\n// see codsen.com/ranges/\nassert.deepEqual(ranges, [[32, 33, \" \"]]);\n\nassert.equal(res, \"Some text with many words on one line.\");"},"widow-word-removal-from-html.js":{"title":"Widow word removal from text within HTML","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\nimport { removeWidows } from \"string-remove-widows\";\n\nconst someHtml = `The quick brown fox jumps of the lazy dog.<div class=\"a\">`;\n\n// default widow word removal libs are not aware of HTML:\n// -----------------------------------------------------------------------------\n\nassert.equal(\n removeWidows(someHtml).res,\n `The quick brown fox jumps of the lazy dog.<div class=\"a\">` // 😱\n);\n\n// luckily, removeWidows() consumes optional HTML tag locations\nassert.equal(\n removeWidows(someHtml, {\n tagRanges: stripHtml(someHtml)\n // remove the third argument, what to insert (\" \" string in these cases)\n .ranges.map(([from, to]) => [from, to]),\n }).res,\n `The quick brown fox jumps of the lazy dog.<div class=\"a\">` // ✅\n);"}}
|