string-remove-widows 2.0.16 → 3.0.2
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/CHANGELOG.md +22 -0
- package/README.md +4 -0
- package/dist/string-remove-widows.esm.js +2 -2
- package/dist/string-remove-widows.umd.js +22 -22
- package/package.json +49 -42
- package/dist/string-remove-widows.cjs.js +0 -385
- package/dist/string-remove-widows.dev.umd.js +0 -3422
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name string-remove-widows
|
|
3
|
-
* @fileoverview Helps to prevent widow words in a text
|
|
4
|
-
* @version 2.0.16
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/string-remove-widows/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
13
|
-
|
|
14
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
15
|
-
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
16
|
-
var stringMatchLeftRight = require('string-match-left-right');
|
|
17
|
-
var stringLeftRight = require('string-left-right');
|
|
18
|
-
var rangesPush = require('ranges-push');
|
|
19
|
-
var rangesApply = require('ranges-apply');
|
|
20
|
-
|
|
21
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
-
|
|
23
|
-
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
24
|
-
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
25
|
-
|
|
26
|
-
var version$1 = "2.0.16";
|
|
27
|
-
|
|
28
|
-
var rawnbsp = "\xA0";
|
|
29
|
-
var encodedNbspHtml = " ";
|
|
30
|
-
var encodedNbspCss = "\\00A0";
|
|
31
|
-
var encodedNbspJs = "\\u00A0";
|
|
32
|
-
var rawNdash = "\u2013";
|
|
33
|
-
var encodedNdashHtml = "–";
|
|
34
|
-
var encodedNdashCss = "\\2013";
|
|
35
|
-
var encodedNdashJs = "\\u2013";
|
|
36
|
-
var rawMdash = "\u2014";
|
|
37
|
-
var encodedMdashHtml = "—";
|
|
38
|
-
var encodedMdashCss = "\\2014";
|
|
39
|
-
var encodedMdashJs = "\\u2014";
|
|
40
|
-
var headsAndTailsJinja = [{
|
|
41
|
-
heads: "{{",
|
|
42
|
-
tails: "}}"
|
|
43
|
-
}, {
|
|
44
|
-
heads: ["{% if", "{%- if"],
|
|
45
|
-
tails: ["{% endif", "{%- endif"]
|
|
46
|
-
}, {
|
|
47
|
-
heads: ["{% for", "{%- for"],
|
|
48
|
-
tails: ["{% endfor", "{%- endfor"]
|
|
49
|
-
}, {
|
|
50
|
-
heads: ["{%", "{%-"],
|
|
51
|
-
tails: ["%}", "-%}"]
|
|
52
|
-
}, {
|
|
53
|
-
heads: "{#",
|
|
54
|
-
tails: "#}"
|
|
55
|
-
}];
|
|
56
|
-
var headsAndTailsHugo = [{
|
|
57
|
-
heads: "{{",
|
|
58
|
-
tails: "}}"
|
|
59
|
-
}];
|
|
60
|
-
var headsAndTailsHexo = [{
|
|
61
|
-
heads: ["<%", "<%=", "<%-"],
|
|
62
|
-
tails: ["%>", "=%>", "-%>"]
|
|
63
|
-
}];
|
|
64
|
-
var 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"];
|
|
65
|
-
|
|
66
|
-
var version = version$1;
|
|
67
|
-
var defaults = {
|
|
68
|
-
removeWidowPreventionMeasures: false,
|
|
69
|
-
convertEntities: true,
|
|
70
|
-
targetLanguage: "html",
|
|
71
|
-
UKPostcodes: false,
|
|
72
|
-
hyphens: true,
|
|
73
|
-
minWordCount: 4,
|
|
74
|
-
minCharCount: 5,
|
|
75
|
-
ignore: [],
|
|
76
|
-
reportProgressFunc: null,
|
|
77
|
-
reportProgressFuncFrom: 0,
|
|
78
|
-
reportProgressFuncTo: 100,
|
|
79
|
-
tagRanges: []
|
|
80
|
-
};
|
|
81
|
-
function removeWidows(str, originalOpts) {
|
|
82
|
-
var start = Date.now();
|
|
83
|
-
if (typeof str !== "string") {
|
|
84
|
-
if (str === undefined) {
|
|
85
|
-
throw new Error("string-remove-widows: [THROW_ID_01] the first input argument is completely missing! It should be given as string.");
|
|
86
|
-
} else {
|
|
87
|
-
throw new Error("string-remove-widows: [THROW_ID_02] the first input argument must be string! It was given as \"".concat(_typeof__default['default'](str), "\", equal to:\n").concat(JSON.stringify(str, null, 4)));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (originalOpts && _typeof__default['default'](originalOpts) !== "object") {
|
|
91
|
-
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 ".concat(_typeof__default['default'](originalOpts), ", equal to ").concat(JSON.stringify(originalOpts, null, 4)));
|
|
92
|
-
}
|
|
93
|
-
var isArr = Array.isArray;
|
|
94
|
-
var len = str.length;
|
|
95
|
-
var rangesArr = new rangesPush.Ranges({
|
|
96
|
-
mergeType: 2
|
|
97
|
-
});
|
|
98
|
-
var punctuationCharsToConsiderWidowIssue = ["."];
|
|
99
|
-
var postcodeRegexFront = /[A-Z]{1,2}[0-9][0-9A-Z]?$/;
|
|
100
|
-
var postcodeRegexEnd = /^[0-9][A-Z]{2}/;
|
|
101
|
-
var leavePercForLastStage = 0.06;
|
|
102
|
-
var currentPercentageDone;
|
|
103
|
-
var lastPercentage = 0;
|
|
104
|
-
var wordCount = 0;
|
|
105
|
-
var charCount = 0;
|
|
106
|
-
var secondToLastWhitespaceStartedAt;
|
|
107
|
-
var secondToLastWhitespaceEndedAt;
|
|
108
|
-
var lastWhitespaceStartedAt;
|
|
109
|
-
var lastWhitespaceEndedAt;
|
|
110
|
-
var lastEncodedNbspStartedAt;
|
|
111
|
-
var lastEncodedNbspEndedAt;
|
|
112
|
-
var doNothingUntil;
|
|
113
|
-
var bumpWordCountAt;
|
|
114
|
-
var opts = _objectSpread__default['default'](_objectSpread__default['default']({}, defaults), originalOpts);
|
|
115
|
-
var whatWasDone = {
|
|
116
|
-
removeWidows: false,
|
|
117
|
-
convertEntities: false
|
|
118
|
-
};
|
|
119
|
-
if (!opts.ignore || !isArr(opts.ignore) && typeof opts.ignore !== "string") {
|
|
120
|
-
opts.ignore = [];
|
|
121
|
-
} else {
|
|
122
|
-
if (typeof opts.ignore === "string") {
|
|
123
|
-
opts.ignore = [opts.ignore];
|
|
124
|
-
}
|
|
125
|
-
if (opts.ignore.includes("all")) {
|
|
126
|
-
opts.ignore = opts.ignore.concat(headsAndTailsJinja.concat(headsAndTailsHexo));
|
|
127
|
-
} else if (opts.ignore.some(function (val) {
|
|
128
|
-
return typeof val === "string";
|
|
129
|
-
})) {
|
|
130
|
-
var temp = [];
|
|
131
|
-
opts.ignore = opts.ignore.filter(function (val) {
|
|
132
|
-
if (typeof val === "string" && val.length) {
|
|
133
|
-
if (["nunjucks", "jinja", "liquid"].includes(val.trim().toLowerCase())) {
|
|
134
|
-
temp = temp.concat(headsAndTailsJinja);
|
|
135
|
-
} else if (["hugo"].includes(val.trim().toLowerCase())) {
|
|
136
|
-
temp = temp.concat(headsAndTailsHugo);
|
|
137
|
-
} else if (["hexo"].includes(val.trim().toLowerCase())) {
|
|
138
|
-
temp = temp.concat(headsAndTailsHexo);
|
|
139
|
-
}
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (_typeof__default['default'](val) === "object") {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
if (temp.length) {
|
|
147
|
-
opts.ignore = opts.ignore.concat(temp);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
var ceil;
|
|
152
|
-
if (opts.reportProgressFunc) {
|
|
153
|
-
ceil = Math.floor(opts.reportProgressFuncTo - (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * leavePercForLastStage - opts.reportProgressFuncFrom);
|
|
154
|
-
}
|
|
155
|
-
function push(finalStart, finalEnd) {
|
|
156
|
-
var finalWhatToInsert = rawnbsp;
|
|
157
|
-
if (opts.removeWidowPreventionMeasures) {
|
|
158
|
-
finalWhatToInsert = " ";
|
|
159
|
-
} else if (opts.convertEntities) {
|
|
160
|
-
finalWhatToInsert = encodedNbspHtml;
|
|
161
|
-
if (typeof opts.targetLanguage === "string") {
|
|
162
|
-
if (opts.targetLanguage.trim().toLowerCase() === "css") {
|
|
163
|
-
finalWhatToInsert = encodedNbspCss;
|
|
164
|
-
} else if (opts.targetLanguage.trim().toLowerCase() === "js") {
|
|
165
|
-
finalWhatToInsert = encodedNbspJs;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (str.slice(finalStart, finalEnd) !== finalWhatToInsert) {
|
|
170
|
-
rangesArr.push(finalStart, finalEnd, finalWhatToInsert);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function resetAll() {
|
|
174
|
-
wordCount = 0;
|
|
175
|
-
charCount = 0;
|
|
176
|
-
secondToLastWhitespaceStartedAt = undefined;
|
|
177
|
-
secondToLastWhitespaceEndedAt = undefined;
|
|
178
|
-
lastWhitespaceStartedAt = undefined;
|
|
179
|
-
lastWhitespaceEndedAt = undefined;
|
|
180
|
-
lastEncodedNbspStartedAt = undefined;
|
|
181
|
-
lastEncodedNbspEndedAt = undefined;
|
|
182
|
-
}
|
|
183
|
-
resetAll();
|
|
184
|
-
var _loop = function _loop(_i) {
|
|
185
|
-
if (!doNothingUntil && isArr(opts.ignore) && opts.ignore.length) {
|
|
186
|
-
opts.ignore.some(function (valObj, y) {
|
|
187
|
-
if (isArr(valObj.heads) && valObj.heads.some(function (oneOfHeads) {
|
|
188
|
-
return str.startsWith(oneOfHeads, _i);
|
|
189
|
-
}) || typeof valObj.heads === "string" && str.startsWith(valObj.heads, _i)) {
|
|
190
|
-
wordCount += 1;
|
|
191
|
-
doNothingUntil = opts.ignore[y].tails;
|
|
192
|
-
i = _i;
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
if (!doNothingUntil && bumpWordCountAt && bumpWordCountAt === _i) {
|
|
198
|
-
wordCount += 1;
|
|
199
|
-
bumpWordCountAt = undefined;
|
|
200
|
-
}
|
|
201
|
-
if (typeof opts.reportProgressFunc === "function") {
|
|
202
|
-
currentPercentageDone = opts.reportProgressFuncFrom + Math.floor(_i / len * (ceil || 1));
|
|
203
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
204
|
-
lastPercentage = currentPercentageDone;
|
|
205
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (!doNothingUntil && _i && str[_i] && str[_i].trim() && (!str[_i - 1] || str[_i - 1] && !str[_i - 1].trim())) {
|
|
209
|
-
lastWhitespaceEndedAt = _i;
|
|
210
|
-
}
|
|
211
|
-
if (!doNothingUntil && str[_i] && str[_i].trim()) {
|
|
212
|
-
charCount += 1;
|
|
213
|
-
}
|
|
214
|
-
if (!doNothingUntil && opts.hyphens && ("-".concat(rawMdash).concat(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] === "&")) {
|
|
215
|
-
if (str[_i - 1] && !str[_i - 1].trim() && str[stringLeftRight.left(str, _i)]) {
|
|
216
|
-
push(stringLeftRight.left(str, _i) + 1, _i);
|
|
217
|
-
whatWasDone.removeWidows = true;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (!doNothingUntil && (str.startsWith(" ", _i) || str.startsWith(" ", _i))) {
|
|
221
|
-
lastEncodedNbspStartedAt = _i;
|
|
222
|
-
lastEncodedNbspEndedAt = _i + 6;
|
|
223
|
-
if (str[_i + 6] && str[_i + 6].trim()) {
|
|
224
|
-
bumpWordCountAt = _i + 6;
|
|
225
|
-
}
|
|
226
|
-
if (!opts.convertEntities) {
|
|
227
|
-
rangesArr.push(_i, _i + 6, rawnbsp);
|
|
228
|
-
whatWasDone.convertEntities = true;
|
|
229
|
-
} else if (opts.targetLanguage === "css" || opts.targetLanguage === "js") {
|
|
230
|
-
rangesArr.push(_i, _i + 6, opts.targetLanguage === "css" ? encodedNbspCss : encodedNbspJs);
|
|
231
|
-
whatWasDone.convertEntities = true;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
if (!doNothingUntil && str[_i + 4] && str[_i] === "\\" && str[_i + 1] === "0" && str[_i + 2] === "0" && str[_i + 3].toUpperCase() === "A" && str[_i + 4] === "0") {
|
|
235
|
-
lastEncodedNbspStartedAt = _i;
|
|
236
|
-
lastEncodedNbspEndedAt = _i + 5;
|
|
237
|
-
if (str[_i + 5] && str[_i + 5].trim()) {
|
|
238
|
-
bumpWordCountAt = _i + 5;
|
|
239
|
-
}
|
|
240
|
-
if (!opts.convertEntities) {
|
|
241
|
-
rangesArr.push(_i, _i + 5, rawnbsp);
|
|
242
|
-
whatWasDone.convertEntities = true;
|
|
243
|
-
} else if (opts.targetLanguage === "html" || opts.targetLanguage === "js") {
|
|
244
|
-
rangesArr.push(_i, _i + 5, opts.targetLanguage === "html" ? encodedNbspHtml : encodedNbspJs);
|
|
245
|
-
whatWasDone.convertEntities = true;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
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") {
|
|
249
|
-
lastEncodedNbspStartedAt = _i;
|
|
250
|
-
lastEncodedNbspEndedAt = _i + 6;
|
|
251
|
-
if (str[_i + 6] && str[_i + 6].trim()) {
|
|
252
|
-
bumpWordCountAt = _i + 6;
|
|
253
|
-
}
|
|
254
|
-
if (!opts.convertEntities) {
|
|
255
|
-
rangesArr.push(_i, _i + 6, rawnbsp);
|
|
256
|
-
} else if (opts.targetLanguage === "html" || opts.targetLanguage === "css") {
|
|
257
|
-
rangesArr.push(_i, _i + 6, opts.targetLanguage === "html" ? encodedNbspHtml : encodedNbspCss);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
if (!doNothingUntil && str[_i] === rawnbsp) {
|
|
261
|
-
lastEncodedNbspStartedAt = _i;
|
|
262
|
-
lastEncodedNbspEndedAt = _i + 1;
|
|
263
|
-
if (opts.convertEntities) {
|
|
264
|
-
rangesArr.push(_i, _i + 1, opts.targetLanguage === "css" ? encodedNbspCss : opts.targetLanguage === "js" ? encodedNbspJs : encodedNbspHtml);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (!doNothingUntil && str[_i] && str[_i].trim() && (!str[_i - 1] || !str[_i - 1].trim())) {
|
|
268
|
-
wordCount += 1;
|
|
269
|
-
}
|
|
270
|
-
if (!doNothingUntil && (!str[_i] || "\r\n".includes(str[_i]) || (str[_i] === "\n" || str[_i] === "\r" || str[_i] === "\r" && str[_i + 1] === "\n") && stringLeftRight.left(str, _i) && punctuationCharsToConsiderWidowIssue.includes(str[stringLeftRight.left(str, _i)]))) {
|
|
271
|
-
if ((!opts.minWordCount || wordCount >= opts.minWordCount) && (!opts.minCharCount || charCount >= opts.minCharCount)) {
|
|
272
|
-
var finalStart;
|
|
273
|
-
var finalEnd;
|
|
274
|
-
if (lastWhitespaceStartedAt !== undefined && lastWhitespaceEndedAt !== undefined && lastEncodedNbspStartedAt !== undefined && lastEncodedNbspEndedAt !== undefined) {
|
|
275
|
-
if (lastWhitespaceStartedAt > lastEncodedNbspStartedAt) {
|
|
276
|
-
finalStart = lastWhitespaceStartedAt;
|
|
277
|
-
finalEnd = lastWhitespaceEndedAt;
|
|
278
|
-
} else {
|
|
279
|
-
finalStart = lastEncodedNbspStartedAt;
|
|
280
|
-
finalEnd = lastEncodedNbspEndedAt;
|
|
281
|
-
}
|
|
282
|
-
} else if (lastWhitespaceStartedAt !== undefined && lastWhitespaceEndedAt !== undefined) {
|
|
283
|
-
finalStart = lastWhitespaceStartedAt;
|
|
284
|
-
finalEnd = lastWhitespaceEndedAt;
|
|
285
|
-
} else if (lastEncodedNbspStartedAt !== undefined && lastEncodedNbspEndedAt !== undefined) {
|
|
286
|
-
finalStart = lastEncodedNbspStartedAt;
|
|
287
|
-
finalEnd = lastEncodedNbspEndedAt;
|
|
288
|
-
}
|
|
289
|
-
if (!(finalStart && finalEnd) && secondToLastWhitespaceStartedAt && secondToLastWhitespaceEndedAt) {
|
|
290
|
-
finalStart = secondToLastWhitespaceStartedAt;
|
|
291
|
-
finalEnd = secondToLastWhitespaceEndedAt;
|
|
292
|
-
}
|
|
293
|
-
if (finalStart && finalEnd) {
|
|
294
|
-
push(finalStart, finalEnd);
|
|
295
|
-
whatWasDone.removeWidows = true;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
resetAll();
|
|
299
|
-
}
|
|
300
|
-
if (opts.UKPostcodes && str[_i] && !str[_i].trim() && str[_i - 1] && str[_i - 1].trim() && postcodeRegexFront.test(str.slice(0, _i)) && str[stringLeftRight.right(str, _i)] && postcodeRegexEnd.test(str.slice(stringLeftRight.right(str, _i)))) {
|
|
301
|
-
push(_i, stringLeftRight.right(str, _i));
|
|
302
|
-
whatWasDone.removeWidows = true;
|
|
303
|
-
}
|
|
304
|
-
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[stringLeftRight.right(str, _i)]) && !str.slice(0, _i).trim().endsWith("br") && !str.slice(0, _i).trim().endsWith("hr") && !(str.slice(0, _i).endsWith("<") && knownHTMLTags.some(function (tag) {
|
|
305
|
-
return str.startsWith(tag, stringLeftRight.right(str, _i));
|
|
306
|
-
}))) {
|
|
307
|
-
secondToLastWhitespaceStartedAt = lastWhitespaceStartedAt;
|
|
308
|
-
secondToLastWhitespaceEndedAt = lastWhitespaceEndedAt;
|
|
309
|
-
lastWhitespaceStartedAt = _i;
|
|
310
|
-
lastWhitespaceEndedAt = undefined;
|
|
311
|
-
if (lastEncodedNbspStartedAt !== undefined || lastEncodedNbspEndedAt !== undefined) {
|
|
312
|
-
lastEncodedNbspStartedAt = undefined;
|
|
313
|
-
lastEncodedNbspEndedAt = undefined;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
var tempTailFinding = void 0;
|
|
317
|
-
if (doNothingUntil) {
|
|
318
|
-
if (typeof doNothingUntil === "string" && (!doNothingUntil.length || str.startsWith(doNothingUntil, _i))) {
|
|
319
|
-
doNothingUntil = undefined;
|
|
320
|
-
} else if (isArr(doNothingUntil) && (!doNothingUntil.length || doNothingUntil.some(function (val) {
|
|
321
|
-
if (str.startsWith(val, _i)) {
|
|
322
|
-
tempTailFinding = val;
|
|
323
|
-
i = _i;
|
|
324
|
-
return true;
|
|
325
|
-
}
|
|
326
|
-
}))) {
|
|
327
|
-
doNothingUntil = undefined;
|
|
328
|
-
_i += tempTailFinding.length;
|
|
329
|
-
if (isArr(opts.ignore) && opts.ignore.length && str[_i + 1]) {
|
|
330
|
-
opts.ignore.some(function (oneOfHeadsTailsObjs) {
|
|
331
|
-
i = _i;
|
|
332
|
-
return stringMatchLeftRight.matchRightIncl(str, _i, oneOfHeadsTailsObjs.tails, {
|
|
333
|
-
trimBeforeMatching: true,
|
|
334
|
-
cb: function cb(_char, _theRemainderOfTheString, index) {
|
|
335
|
-
if (index) {
|
|
336
|
-
_i = index - 1;
|
|
337
|
-
if (str[_i + 1] && str[_i + 1].trim()) {
|
|
338
|
-
wordCount += 1;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
i = _i;
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
if (str[_i] && "\r\n".includes(str[_i])) {
|
|
350
|
-
wordCount = 0;
|
|
351
|
-
charCount = 0;
|
|
352
|
-
}
|
|
353
|
-
if (isArr(opts.tagRanges) && opts.tagRanges.length && opts.tagRanges.some(function (rangeArr) {
|
|
354
|
-
if (_i >= rangeArr[0] && _i <= rangeArr[1] && rangeArr[1] - 1 > _i) {
|
|
355
|
-
_i = rangeArr[1] - 1;
|
|
356
|
-
i = _i;
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
})) ;
|
|
360
|
-
i = _i;
|
|
361
|
-
};
|
|
362
|
-
for (var i = 0; i <= len; i++) {
|
|
363
|
-
_loop(i);
|
|
364
|
-
}
|
|
365
|
-
rangesApply.rApply(str, rangesArr.current()).split("").forEach(function (key, i) {
|
|
366
|
-
});
|
|
367
|
-
return {
|
|
368
|
-
res: rangesApply.rApply(str, rangesArr.current(), opts.reportProgressFunc ? function (incomingPerc) {
|
|
369
|
-
currentPercentageDone = Math.floor((opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * (1 - leavePercForLastStage) + incomingPerc / 100 * (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * leavePercForLastStage);
|
|
370
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
371
|
-
lastPercentage = currentPercentageDone;
|
|
372
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
373
|
-
}
|
|
374
|
-
} : undefined),
|
|
375
|
-
ranges: rangesArr.current(),
|
|
376
|
-
log: {
|
|
377
|
-
timeTakenInMilliseconds: Date.now() - start
|
|
378
|
-
},
|
|
379
|
-
whatWasDone: whatWasDone
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
exports.defaults = defaults;
|
|
384
|
-
exports.removeWidows = removeWidows;
|
|
385
|
-
exports.version = version;
|