diff options
author | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
commit | 99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch) | |
tree | e663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /school/node_modules/ranges-merge/dist/ranges-merge.esm.js | |
parent | 9871b03912fc28ad38b4037ebf26a78aa937baba (diff) | |
download | pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2 pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip |
Update - This is an automated commit
Diffstat (limited to 'school/node_modules/ranges-merge/dist/ranges-merge.esm.js')
-rw-r--r-- | school/node_modules/ranges-merge/dist/ranges-merge.esm.js | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/school/node_modules/ranges-merge/dist/ranges-merge.esm.js b/school/node_modules/ranges-merge/dist/ranges-merge.esm.js new file mode 100644 index 0000000..45d08d4 --- /dev/null +++ b/school/node_modules/ranges-merge/dist/ranges-merge.esm.js @@ -0,0 +1,107 @@ +/** + * @name ranges-merge + * @fileoverview Merge and sort string index ranges + * @version 7.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/ranges-merge/} + */ + +import { rSort } from 'ranges-sort'; + +var version$1 = "7.1.0"; + +const version = version$1; +const defaults = { + mergeType: 1, + progressFn: null, + joinRangesThatTouchEdges: true +}; +function rMerge(arrOfRanges, originalOpts) { + function isObj(something) { + return something && typeof something === "object" && !Array.isArray(something); + } + if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) { + return null; + } + let opts; + if (originalOpts) { + if (isObj(originalOpts)) { + opts = { ...defaults, + ...originalOpts + }; + if (opts.progressFn && isObj(opts.progressFn) && !Object.keys(opts.progressFn).length) { + opts.progressFn = null; + } else if (opts.progressFn && typeof opts.progressFn !== "function") { + throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof opts.progressFn}", equal to ${JSON.stringify(opts.progressFn, null, 4)}`); + } + if (opts.mergeType && +opts.mergeType !== 1 && +opts.mergeType !== 2) { + throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof opts.mergeType}", equal to ${JSON.stringify(opts.mergeType, null, 4)}`); + } + if (typeof opts.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 opts.joinRangesThatTouchEdges}", equal to ${JSON.stringify(opts.joinRangesThatTouchEdges, null, 4)}`); + } + } else { + throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`); + } + } else { + opts = { ...defaults + }; + } + const filtered = arrOfRanges + .filter(range => range).map(subarr => [...subarr]).filter( + rangeArr => rangeArr[2] !== undefined || rangeArr[0] !== rangeArr[1]); + let sortedRanges; + let lastPercentageDone; + let percentageDone; + if (opts.progressFn) { + sortedRanges = rSort(filtered, { + progressFn: percentage => { + percentageDone = Math.floor(percentage / 5); + if (percentageDone !== lastPercentageDone) { + lastPercentageDone = percentageDone; + opts.progressFn(percentageDone); + } + } + }); + } else { + sortedRanges = rSort(filtered); + } + if (!sortedRanges) { + return null; + } + const len = sortedRanges.length - 1; + for (let i = len; i > 0; i--) { + if (opts.progressFn) { + percentageDone = Math.floor((1 - i / len) * 78) + 21; + if (percentageDone !== lastPercentageDone && percentageDone > lastPercentageDone) { + lastPercentageDone = percentageDone; + opts.progressFn(percentageDone); + } + } + if (sortedRanges[i][0] <= sortedRanges[i - 1][0] || !opts.joinRangesThatTouchEdges && sortedRanges[i][0] < sortedRanges[i - 1][1] || opts.joinRangesThatTouchEdges && sortedRanges[i][0] <= sortedRanges[i - 1][1]) { + sortedRanges[i - 1][0] = Math.min(sortedRanges[i][0], sortedRanges[i - 1][0]); + sortedRanges[i - 1][1] = Math.max(sortedRanges[i][1], sortedRanges[i - 1][1]); + if (sortedRanges[i][2] !== undefined && (sortedRanges[i - 1][0] >= sortedRanges[i][0] || sortedRanges[i - 1][1] <= sortedRanges[i][1])) { + if (sortedRanges[i - 1][2] !== null) { + if (sortedRanges[i][2] === null && sortedRanges[i - 1][2] !== null) { + sortedRanges[i - 1][2] = null; + } else if (sortedRanges[i - 1][2] != null) { + if (+opts.mergeType === 2 && sortedRanges[i - 1][0] === sortedRanges[i][0]) { + sortedRanges[i - 1][2] = sortedRanges[i][2]; + } else { + sortedRanges[i - 1][2] += sortedRanges[i][2]; + } + } else { + sortedRanges[i - 1][2] = sortedRanges[i][2]; + } + } + } + sortedRanges.splice(i, 1); + i = sortedRanges.length; + } + } + return sortedRanges.length ? sortedRanges : null; +} + +export { defaults, rMerge, version }; |