summaryrefslogtreecommitdiff
path: root/includes/external/school/node_modules/ranges-apply/dist/ranges-apply.esm.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
committerMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
commit3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch)
tree75be5fba4368472fb11c8015aee026b2b9a71888 /includes/external/school/node_modules/ranges-apply/dist/ranges-apply.esm.js
parent8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff)
downloadpluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'includes/external/school/node_modules/ranges-apply/dist/ranges-apply.esm.js')
-rw-r--r--includes/external/school/node_modules/ranges-apply/dist/ranges-apply.esm.js103
1 files changed, 103 insertions, 0 deletions
diff --git a/includes/external/school/node_modules/ranges-apply/dist/ranges-apply.esm.js b/includes/external/school/node_modules/ranges-apply/dist/ranges-apply.esm.js
new file mode 100644
index 0000000..16073b1
--- /dev/null
+++ b/includes/external/school/node_modules/ranges-apply/dist/ranges-apply.esm.js
@@ -0,0 +1,103 @@
+/**
+ * @name ranges-apply
+ * @fileoverview Take an array of string index ranges, delete/replace the string according to them
+ * @version 5.1.0
+ * @author Roy Revelt, Codsen Ltd
+ * @license MIT
+ * {@link https://codsen.com/os/ranges-apply/}
+ */
+
+import { rMerge } from 'ranges-merge';
+
+var version$1 = "5.1.0";
+
+const version = version$1;
+function rApply(str, originalRangesArr, progressFn) {
+ let percentageDone = 0;
+ let lastPercentageDone = 0;
+ if (arguments.length === 0) {
+ throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");
+ }
+ if (typeof str !== "string") {
+ throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof str}, equal to: ${JSON.stringify(str, null, 4)}`);
+ }
+ if (originalRangesArr && !Array.isArray(originalRangesArr)) {
+ throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof originalRangesArr}, equal to: ${JSON.stringify(originalRangesArr, null, 4)}`);
+ }
+ if (progressFn && typeof progressFn !== "function") {
+ throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof progressFn}, equal to: ${JSON.stringify(progressFn, null, 4)}`);
+ }
+ if (!originalRangesArr || !originalRangesArr.filter(range => range).length) {
+ return str;
+ }
+ let rangesArr;
+ if (Array.isArray(originalRangesArr) && Number.isInteger(originalRangesArr[0]) && Number.isInteger(originalRangesArr[1])) {
+ rangesArr = [Array.from(originalRangesArr)];
+ } else {
+ rangesArr = Array.from(originalRangesArr);
+ }
+ const len = rangesArr.length;
+ let counter = 0;
+ rangesArr.filter(range => range).forEach((el, i) => {
+ if (progressFn) {
+ percentageDone = Math.floor(counter / len * 10);
+ /* istanbul ignore else */
+ if (percentageDone !== lastPercentageDone) {
+ lastPercentageDone = percentageDone;
+ progressFn(percentageDone);
+ }
+ }
+ if (!Array.isArray(el)) {
+ throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${i}th element not an array: ${JSON.stringify(el, null, 4)}, which is ${typeof el}`);
+ }
+ if (!Number.isInteger(el[0])) {
+ if (!Number.isInteger(+el[0]) || +el[0] < 0) {
+ throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${i}th element, array ${JSON.stringify(el, null, 0)}. Its first element is not an integer, string index, but ${typeof el[0]}, equal to: ${JSON.stringify(el[0], null, 4)}.`);
+ } else {
+ rangesArr[i][0] = +rangesArr[i][0];
+ }
+ }
+ if (!Number.isInteger(el[1])) {
+ if (!Number.isInteger(+el[1]) || +el[1] < 0) {
+ throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${i}th element, array ${JSON.stringify(el, null, 0)}. Its second element is not an integer, string index, but ${typeof el[1]}, equal to: ${JSON.stringify(el[1], null, 4)}.`);
+ } else {
+ rangesArr[i][1] = +rangesArr[i][1];
+ }
+ }
+ counter += 1;
+ });
+ const workingRanges = rMerge(rangesArr, {
+ progressFn: perc => {
+ if (progressFn) {
+ percentageDone = 10 + Math.floor(perc / 10);
+ /* istanbul ignore else */
+ if (percentageDone !== lastPercentageDone) {
+ lastPercentageDone = percentageDone;
+ progressFn(percentageDone);
+ }
+ }
+ }
+ });
+ const len2 = Array.isArray(workingRanges) ? workingRanges.length : 0;
+ /* istanbul ignore else */
+ if (len2 > 0) {
+ const tails = str.slice(workingRanges[len2 - 1][1]);
+ str = workingRanges.reduce((acc, _val, i, arr) => {
+ if (progressFn) {
+ percentageDone = 20 + Math.floor(i / len2 * 80);
+ /* istanbul ignore else */
+ if (percentageDone !== lastPercentageDone) {
+ lastPercentageDone = percentageDone;
+ progressFn(percentageDone);
+ }
+ }
+ const beginning = i === 0 ? 0 : arr[i - 1][1];
+ const ending = arr[i][0];
+ return acc + str.slice(beginning, ending) + (arr[i][2] || "");
+ }, "");
+ str += tails;
+ }
+ return str;
+}
+
+export { rApply, version };