diff options
Diffstat (limited to 'school/node_modules/ranges-merge')
-rw-r--r-- | school/node_modules/ranges-merge/CHANGELOG.md | 152 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/LICENSE | 22 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/README.md | 76 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/dist/ranges-merge.cjs.js | 125 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/dist/ranges-merge.dev.umd.js | 230 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/dist/ranges-merge.esm.js | 107 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/dist/ranges-merge.umd.js | 18 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/examples/_quickTake.js | 26 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/examples/api.json | 1 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/package.json | 122 | ||||
-rw-r--r-- | school/node_modules/ranges-merge/types/index.d.ts | 13 |
11 files changed, 892 insertions, 0 deletions
diff --git a/school/node_modules/ranges-merge/CHANGELOG.md b/school/node_modules/ranges-merge/CHANGELOG.md new file mode 100644 index 0000000..7cae559 --- /dev/null +++ b/school/node_modules/ranges-merge/CHANGELOG.md @@ -0,0 +1,152 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## 7.1.0 (2021-05-24) + +### Features + +- config file based major bump blacklisting ([e15f9bb](https://github.com/codsen/codsen/commit/e15f9bba1c4fd5f847ac28b3f38fa6ee633f5dca)) + +## 7.0.15 (2021-04-11) + +### Reverts + +- Revert "chore: setup refresh" ([23cf206](https://github.com/codsen/codsen/commit/23cf206970a087ff0fa04e61f94d919f59ab3881)) + +## 7.0.1 (2021-01-28) + +### Bug Fixes + +- add testStats to npmignore ([f3c84e9](https://github.com/codsen/codsen/commit/f3c84e95afc5514214312f913692d85b2e12eb29)) + +## 7.0.0 (2021-01-23) + +### Features + +- rewrite in TS and start using named exports ([3fdf215](https://github.com/codsen/codsen/commit/3fdf2155ff9c0a20661f81b4d679956cd49c989d)) + +### BREAKING CHANGES + +- previously: `import rMerge from ...` - now `import { rMerge } from ...` + +## 6.2.0 (2020-11-29) + +### Features + +- simplify with unary plus operator ([39a9f57](https://git.sr.ht/~royston/codsen/commit/39a9f57fd3f8387bec2db70b7e514581184f7803)) + +## 6.1.0 (2020-11-29) + +### Features + +- simplify with unary plus operator ([39a9f57](https://git.sr.ht/~royston/codsen/commit/39a9f57fd3f8387bec2db70b7e514581184f7803)) + +## 6.0.0 (2020-11-28) + +Accidental version bump during migration to sourcehut. Sorry about that. + +## 5.0.0 (2020-09-07) + +### Features + +- discard any null ranges when merging ([ae51bce](https://gitlab.com/codsen/codsen/commit/ae51bce0bcbdb4012548887a31633eaafda5dfdc)) +- return null instead of empty array ([27fa708](https://gitlab.com/codsen/codsen/commit/27fa70879ef0fb65594ffa55de17a26d64353186)) + +### BREAKING CHANGES + +- return null instead of empty array + +## 4.3.0 (2020-02-01) + +### Features + +- remove a dependency, rebase a little ([625ba18](https://gitlab.com/codsen/codsen/commit/625ba1871fe12efe1f36fbbb4f67b7025d5905a9)) + +## 4.2.0 (2019-06-01) + +### Features + +- Tweak API to correctly interpret opts.processFn given as an empty plain object ([bcedd6e](https://gitlab.com/codsen/codsen/commit/bcedd6e)) + +## 4.1.0 (2019-03-17) + +### Features + +- opts.joinRangesThatTouchEdges ([40cf7e6](https://gitlab.com/codsen/codsen/commit/40cf7e6)) + +## 3.12.0 (2019-01-20) + +- ✨ Various documentation and setup tweaks after we migrated to monorepo +- ✨ Setup refresh: updated dependencies and all config files using automated tools + +## 3.8.0 (2018-12-26) + +- ✨ Improvements against input argument mutation ([924c7ae](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-merge/commits/924c7ae)) +- ✨ Removes ranges with no third arg with identical start and end points ([707553b](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-merge/commits/707553b)) + +## 3.7.0 (2018-11-29) + +- ✨ Second input argument - `progressFn` is added, it will report percentage done so far. It's used in worker setups. + +## 3.6.0 (2018-10-25) + +- ✨ Updated all dependencies +- ✨ Restored coveralls.io reporting +- ✨ Restored unit test linting + +## 3.5.0 (2018-08-17) + +- ✨ Apparently the input arguments were mutated on some cases. That's fixed now. + +## 3.4.0 (2018-08-16) + +- ✨ Now, ranges with identical starting and ending points with no third argument (nothing to add) will be removed. They're futile anyway. It's like saying at this index... and saying nothing else. + +## 3.3.0 (2018-06-11) + +GitHub sold us out. In the meantime, we: + +- ✨ Migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit) +- ✨ Dropped BitHound (RIP) and Travis +- ✨ Removed `package-lock` + +## 3.2.0 (2018-05-26) + +- ✨ Set up [Prettier](https://prettier.io) on a custom ESLint rule set. +- ✨ Removed `package.lock` and `.editorconfig` +- ✨ Wired Rollup to remove comments from non-dev builds. This means we can now leave the `console.log`s in the source code — there's no need to comment-out `console.log` statements or care about them not spilling into production. Now it's done automatically. +- ✨ Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed. This is important because now code coverage is real again and now there are no excuses not to perfect it. + +## 3.1.0 (2017-12-29) + +- ✨ If third argument is `null` on any side being merged, output is always `null`. This will stand for explicit "no" to remove any content to be added. Sibling [libraries](https://github.com/codsen/string-slices-array-push) will tap this feature. + +Previously `null` would have been turned into a string and shown/concatenated like that which was meaningless and kindof erroneous. We never used `null` anyway. That's why this is not a major semver bump but minor - it's only a feature, an extension of the API. + +## 3.0.0 (2017-12-05) + +- ✨ If you have two ranges where second-one completely overlaps the first-one and the first has third argument, something to insert in its place, that third argument will be discarded upon merge. + +Let's say you got these two ranges: + +```js +[ + [5, 6, " "], + [1, 10], +]; +``` + +Previously, result would be `[1, 10, ' ']`. Now result will be `[1, 10]`. This is logical, because each range should take care to consider its vicinity. If `[1, 10]` came in without instructions to add something in its place, we assume this was intentional. + +This change is logical and natural but I'm bumping major version just in case it breaks somebody's unit tests. + +## 2.0.0 (2017-12-04) + +- ✨ Rebased the source in ES Modules +- ✨ Set up Rollup and now we are generating three builds: CommonJS, UMD and ES Modules (native code). + +## 1.0.0 (2017-09-18) + +- First public release diff --git a/school/node_modules/ranges-merge/LICENSE b/school/node_modules/ranges-merge/LICENSE new file mode 100644 index 0000000..9ea205b --- /dev/null +++ b/school/node_modules/ranges-merge/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2010-%YEAR% Roy Revelt and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file diff --git a/school/node_modules/ranges-merge/README.md b/school/node_modules/ranges-merge/README.md new file mode 100644 index 0000000..d1f9e21 --- /dev/null +++ b/school/node_modules/ranges-merge/README.md @@ -0,0 +1,76 @@ +# ranges-merge + +> Merge and sort string index ranges + +<div class="package-badges"> + <a href="https://www.npmjs.com/package/ranges-merge" rel="nofollow noreferrer noopener"> + <img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm"> + </a> + <a href="https://codsen.com/os/ranges-merge" rel="nofollow noreferrer noopener"> + <img src="https://img.shields.io/badge/-codsen-blue?style=flat-square" alt="page on codsen.com"> + </a> + <a href="https://github.com/codsen/codsen/tree/main/packages/ranges-merge" rel="nofollow noreferrer noopener"> + <img src="https://img.shields.io/badge/-github-blue?style=flat-square" alt="page on github"> + </a> + <a href="https://npmcharts.com/compare/ranges-merge?interval=30" rel="nofollow noreferrer noopener" target="_blank"> + <img src="https://img.shields.io/npm/dm/ranges-merge.svg?style=flat-square" alt="Downloads per month"> + </a> + <a href="https://prettier.io" rel="nofollow noreferrer noopener" target="_blank"> + <img src="https://img.shields.io/badge/code_style-prettier-brightgreen.svg?style=flat-square" alt="Code style: prettier"> + </a> + <img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT License"> + <a href="https://liberamanifesto.com" rel="nofollow noreferrer noopener" target="_blank"> + <img src="https://img.shields.io/badge/libera-manifesto-lightgrey.svg?style=flat-square" alt="libera manifesto"> + </a> +</div> + +## Install + +```bash +npm i ranges-merge +``` + +## Quick Take + +```js +import { strict as assert } from "assert"; +import { rMerge } from "ranges-merge"; + +// joining edges: +assert.deepEqual( + rMerge([ + [1, 2], + [2, 3], + [9, 10], + ]), + [ + [1, 3], + [9, 10], + ] +); + +// an overlap: +assert.deepEqual( + rMerge([ + [1, 5], + [2, 10], + ]), + [[1, 10]] +); +``` + +## Documentation + +Please [visit codsen.com](https://codsen.com/os/ranges-merge/) for a full description of the API and examples. + +## Contributing + +To report bugs or request features or assistance, [raise an issue](https://github.com/codsen/codsen/issues/new/choose) on GitHub. + +## Licence + +MIT License + +Copyright (c) 2010-2021 Roy Revelt and other contributors + +<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"> diff --git a/school/node_modules/ranges-merge/dist/ranges-merge.cjs.js b/school/node_modules/ranges-merge/dist/ranges-merge.cjs.js new file mode 100644 index 0000000..39ca466 --- /dev/null +++ b/school/node_modules/ranges-merge/dist/ranges-merge.cjs.js @@ -0,0 +1,125 @@ +/** + * @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/} + */ + +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray'); +var _objectSpread = require('@babel/runtime/helpers/objectSpread2'); +var _typeof = require('@babel/runtime/helpers/typeof'); +var rangesSort = require('ranges-sort'); + +function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } + +var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray); +var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread); +var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); + +var version$1 = "7.1.0"; + +var version = version$1; +var defaults = { + mergeType: 1, + progressFn: null, + joinRangesThatTouchEdges: true +}; +function rMerge(arrOfRanges, originalOpts) { + function isObj(something) { + return something && _typeof__default['default'](something) === "object" && !Array.isArray(something); + } + if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) { + return null; + } + var opts; + if (originalOpts) { + if (isObj(originalOpts)) { + opts = _objectSpread__default['default'](_objectSpread__default['default']({}, 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: \"".concat(_typeof__default['default'](opts.progressFn), "\", equal to ").concat(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: \"".concat(_typeof__default['default'](opts.mergeType), "\", equal to ").concat(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: \"".concat(_typeof__default['default'](opts.joinRangesThatTouchEdges), "\", equal to ").concat(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".concat(JSON.stringify(originalOpts, null, 4), " (type ").concat(_typeof__default['default'](originalOpts), ")")); + } + } else { + opts = _objectSpread__default['default']({}, defaults); + } + var filtered = arrOfRanges + .filter(function (range) { + return range; + }).map(function (subarr) { + return _toConsumableArray__default['default'](subarr); + }).filter( + function (rangeArr) { + return rangeArr[2] !== undefined || rangeArr[0] !== rangeArr[1]; + }); + var sortedRanges; + var lastPercentageDone; + var percentageDone; + if (opts.progressFn) { + sortedRanges = rangesSort.rSort(filtered, { + progressFn: function progressFn(percentage) { + percentageDone = Math.floor(percentage / 5); + if (percentageDone !== lastPercentageDone) { + lastPercentageDone = percentageDone; + opts.progressFn(percentageDone); + } + } + }); + } else { + sortedRanges = rangesSort.rSort(filtered); + } + if (!sortedRanges) { + return null; + } + var len = sortedRanges.length - 1; + for (var 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; +} + +exports.defaults = defaults; +exports.rMerge = rMerge; +exports.version = version; diff --git a/school/node_modules/ranges-merge/dist/ranges-merge.dev.umd.js b/school/node_modules/ranges-merge/dist/ranges-merge.dev.umd.js new file mode 100644 index 0000000..6886133 --- /dev/null +++ b/school/node_modules/ranges-merge/dist/ranges-merge.dev.umd.js @@ -0,0 +1,230 @@ +/** + * @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/} + */ + +(function (global, factory) { +typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : +typeof define === 'function' && define.amd ? define(['exports'], factory) : +(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.rangesMerge = {})); +}(this, (function (exports) { 'use strict'; + +/** + * @name ranges-sort + * @fileoverview Sort string index ranges + * @version 4.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/ranges-sort/} + */ +const defaults$1 = { + strictlyTwoElementsInRangeArrays: false, + progressFn: null +}; +function rSort(arrOfRanges, originalOptions) { + if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) { + return arrOfRanges; + } + const opts = { ...defaults$1, + ...originalOptions + }; + let culpritsIndex; + let culpritsLen; + if (opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.filter(range => range).every((rangeArr, indx) => { + if (rangeArr.length !== 2) { + culpritsIndex = indx; + culpritsLen = rangeArr.length; + return false; + } + return true; + })) { + 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, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) has not two but ${culpritsLen} elements!`); + } + if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => { + if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) { + culpritsIndex = indx; + return false; + } + return true; + })) { + 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, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) does not consist of only natural numbers!`); + } + const maxPossibleIterations = arrOfRanges.filter(range => range).length ** 2; + let counter = 0; + return Array.from(arrOfRanges).filter(range => range).sort((range1, range2) => { + if (opts.progressFn) { + counter += 1; + opts.progressFn(Math.floor(counter * 100 / maxPossibleIterations)); + } + if (range1[0] === range2[0]) { + if (range1[1] < range2[1]) { + return -1; + } + if (range1[1] > range2[1]) { + return 1; + } + return 0; + } + if (range1[0] < range2[0]) { + return -1; + } + return 1; + }); +} + +var version$1 = "7.1.0"; + +const version = version$1; +const defaults = { + mergeType: 1, + progressFn: null, + joinRangesThatTouchEdges: true, +}; +// merges the overlapping ranges +// case #1. exact extension: +// [ [1, 5], [5, 10] ] => [ [1, 10] ] +// case #2. overlap: +// [ [1, 4], [3, 5] ] => [ [1, 5] ] +function rMerge(arrOfRanges, originalOpts) { + // + // internal functions: + // --------------------------------------------------------------------------- + function isObj(something) { + return (something && typeof something === "object" && !Array.isArray(something)); + } + // quick ending: + // --------------------------------------------------------------------------- + if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) { + return null; + } + let opts; + if (originalOpts) { + if (isObj(originalOpts)) { + opts = { ...defaults, ...originalOpts }; + // 1. validate opts.progressFn + 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)}`); + } + // 2. validate opts.mergeType + 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)}`); + } + // 3. validate opts.joinRangesThatTouchEdges + 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 }; + } + // progress-wise, sort takes first 20% + // two-level-deep array clone: + const filtered = arrOfRanges + // filter out null + .filter((range) => range) + .map((subarr) => [...subarr]) + .filter( + // filter out futile ranges with identical starting and ending points with + // nothing to add (no 3rd argument) + (rangeArr) => rangeArr[2] !== undefined || rangeArr[0] !== rangeArr[1]); + let sortedRanges; + let lastPercentageDone; + let percentageDone; + if (opts.progressFn) { + // progress already gets reported in [0,100] range, so we just need to + // divide by 5 in order to "compress" that into 20% range. + sortedRanges = rSort(filtered, { + progressFn: (percentage) => { + percentageDone = Math.floor(percentage / 5); + // ensure each percent is passed only once: + if (percentageDone !== lastPercentageDone) { + lastPercentageDone = percentageDone; + opts.progressFn(percentageDone); + } + }, + }); + } + else { + sortedRanges = rSort(filtered); + } + if (!sortedRanges) { + return null; + } + const len = sortedRanges.length - 1; + // reset 80% of progress is this loop: + // loop from the end: + 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); + // console.log( + // `153 REPORTING ${`\u001b[${33}m${`doneSoFar`}\u001b[${39}m`} = ${doneSoFar}` + // ); + } + } + // if current range is before the preceding-one + 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]); + // tend the third argument, "what to insert" + if (sortedRanges[i][2] !== undefined && + (sortedRanges[i - 1][0] >= sortedRanges[i][0] || + sortedRanges[i - 1][1] <= sortedRanges[i][1])) { + // if the value of the range before exists: + 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 there's a clash of "insert" values: + if (+opts.mergeType === 2 && + sortedRanges[i - 1][0] === sortedRanges[i][0]) { + // take the value from the range that's on the right: + sortedRanges[i - 1][2] = sortedRanges[i][2]; + } + else { + sortedRanges[i - 1][2] += + sortedRanges[i][2]; + } + } + else { + sortedRanges[i - 1][2] = sortedRanges[i][2]; + } + } + } + // get rid of the second element: + sortedRanges.splice(i, 1); + // reset the traversal, start from the end again + i = sortedRanges.length; + } + } + return sortedRanges.length ? sortedRanges : null; +} + +exports.defaults = defaults; +exports.rMerge = rMerge; +exports.version = version; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); 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 }; diff --git a/school/node_modules/ranges-merge/dist/ranges-merge.umd.js b/school/node_modules/ranges-merge/dist/ranges-merge.umd.js new file mode 100644 index 0000000..9275312 --- /dev/null +++ b/school/node_modules/ranges-merge/dist/ranges-merge.umd.js @@ -0,0 +1,18 @@ +/** + * @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/} + */ + +!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).rangesMerge={})}(this,(function(e){"use strict"; +/** + * @name ranges-sort + * @fileoverview Sort string index ranges + * @version 4.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/ranges-sort/} + */const r={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function n(e,n){if(!Array.isArray(e)||!e.length)return e;const t={...r,...n};let s,o;if(t.strictlyTwoElementsInRangeArrays&&!e.filter((e=>e)).every(((e,r)=>2===e.length||(s=r,o=e.length,!1))))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, ${s}th range (${JSON.stringify(e[s],null,4)}) has not two but ${o} elements!`);if(!e.filter((e=>e)).every(((e,r)=>!(!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0)||(s=r,!1))))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, ${s}th range (${JSON.stringify(e[s],null,4)}) does not consist of only natural numbers!`);const i=e.filter((e=>e)).length**2;let g=0;return Array.from(e).filter((e=>e)).sort(((e,r)=>(t.progressFn&&(g+=1,t.progressFn(Math.floor(100*g/i))),e[0]===r[0]?e[1]<r[1]?-1:e[1]>r[1]?1:0:e[0]<r[0]?-1:1)))}const t={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};e.defaults=t,e.rMerge=function(e,r){function s(e){return e&&"object"==typeof e&&!Array.isArray(e)}if(!Array.isArray(e)||!e.length)return null;let o;if(r){if(!s(r))throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(r,null,4)} (type ${typeof r})`);if(o={...t,...r},o.progressFn&&s(o.progressFn)&&!Object.keys(o.progressFn).length)o.progressFn=null;else if(o.progressFn&&"function"!=typeof o.progressFn)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(o.mergeType&&1!=+o.mergeType&&2!=+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("boolean"!=typeof o.joinRangesThatTouchEdges)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 o={...t};const i=e.filter((e=>e)).map((e=>[...e])).filter((e=>void 0!==e[2]||e[0]!==e[1]));let g,a,l;if(g=o.progressFn?n(i,{progressFn:e=>{l=Math.floor(e/5),l!==a&&(a=l,o.progressFn(l))}}):n(i),!g)return null;const u=g.length-1;for(let e=u;e>0;e--)o.progressFn&&(l=Math.floor(78*(1-e/u))+21,l!==a&&l>a&&(a=l,o.progressFn(l))),(g[e][0]<=g[e-1][0]||!o.joinRangesThatTouchEdges&&g[e][0]<g[e-1][1]||o.joinRangesThatTouchEdges&&g[e][0]<=g[e-1][1])&&(g[e-1][0]=Math.min(g[e][0],g[e-1][0]),g[e-1][1]=Math.max(g[e][1],g[e-1][1]),void 0!==g[e][2]&&(g[e-1][0]>=g[e][0]||g[e-1][1]<=g[e][1])&&null!==g[e-1][2]&&(null===g[e][2]&&null!==g[e-1][2]?g[e-1][2]=null:null!=g[e-1][2]?2==+o.mergeType&&g[e-1][0]===g[e][0]?g[e-1][2]=g[e][2]:g[e-1][2]+=g[e][2]:g[e-1][2]=g[e][2]),g.splice(e,1),e=g.length);return g.length?g:null},e.version="7.1.0",Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/school/node_modules/ranges-merge/examples/_quickTake.js b/school/node_modules/ranges-merge/examples/_quickTake.js new file mode 100644 index 0000000..9be2945 --- /dev/null +++ b/school/node_modules/ranges-merge/examples/_quickTake.js @@ -0,0 +1,26 @@ +// Quick Take + +import { strict as assert } from "assert"; +import { rMerge } from "../dist/ranges-merge.esm.js"; + +// joining edges: +assert.deepEqual( + rMerge([ + [1, 2], + [2, 3], + [9, 10], + ]), + [ + [1, 3], + [9, 10], + ] +); + +// an overlap: +assert.deepEqual( + rMerge([ + [1, 5], + [2, 10], + ]), + [[1, 10]] +); diff --git a/school/node_modules/ranges-merge/examples/api.json b/school/node_modules/ranges-merge/examples/api.json new file mode 100644 index 0000000..c6b6496 --- /dev/null +++ b/school/node_modules/ranges-merge/examples/api.json @@ -0,0 +1 @@ +{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { rMerge } from \"ranges-merge\";\n\n// joining edges:\nassert.deepEqual(\n rMerge([\n [1, 2],\n [2, 3],\n [9, 10],\n ]),\n [\n [1, 3],\n [9, 10],\n ]\n);\n\n// an overlap:\nassert.deepEqual(\n rMerge([\n [1, 5],\n [2, 10],\n ]),\n [[1, 10]]\n);"}}
\ No newline at end of file diff --git a/school/node_modules/ranges-merge/package.json b/school/node_modules/ranges-merge/package.json new file mode 100644 index 0000000..c289848 --- /dev/null +++ b/school/node_modules/ranges-merge/package.json @@ -0,0 +1,122 @@ +{ + "name": "ranges-merge", + "version": "7.1.0", + "description": "Merge and sort string index ranges", + "keywords": [ + "index", + "join", + "manage", + "merge", + "multiple", + "ranges", + "slices", + "string", + "substring", + "two" + ], + "homepage": "https://codsen.com/os/ranges-merge/", + "repository": { + "type": "git", + "url": "https://github.com/codsen/codsen.git", + "directory": "packages/ranges-merge" + }, + "license": "MIT", + "author": { + "name": "Roy Revelt", + "email": "roy@codsen.com", + "url": "https://codsen.com" + }, + "main": "dist/ranges-merge.cjs.js", + "module": "dist/ranges-merge.esm.js", + "browser": "dist/ranges-merge.umd.js", + "types": "types/index.d.ts", + "scripts": { + "build": "rollup -c", + "esbuild": "node '../../scripts/esbuild.js'", + "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'", + "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov", + "dev": "rollup -c --dev", + "devunittest": "npm run dev && tap --only -R 'base'", + "format": "npm run lect && npm run prettier && npm run lint", + "lect": "lect", + "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet", + "perf": "node perf/check", + "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent", + "republish": "npm publish || :", + "tap": "tap", + "tsc": "tsc", + "pretest": "npm run build", + "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format", + "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier", + "unittest": "./node_modules/.bin/tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf", + "clean_cov": "../../scripts/leaveCoverageTotalOnly.js", + "clean_types": "../../scripts/cleanTypes.js" + }, + "tap": { + "coverage-report": [ + "json-summary", + "text" + ], + "nyc-arg": [ + "--exclude=**/*.cjs.js", + "--exclude=**/*.umd.js" + ], + "timeout": 0 + }, + "lect": { + "licence": { + "extras": [ + "" + ] + }, + "req": "{ rMerge }", + "various": { + "devDependencies": [ + "lodash.clonedeep" + ] + } + }, + "dependencies": { + "@babel/runtime": "^7.14.0", + "ranges-push": "^5.1.0", + "ranges-sort": "^4.1.0" + }, + "devDependencies": { + "@babel/cli": "^7.14.3", + "@babel/core": "^7.14.3", + "@babel/node": "^7.14.2", + "@babel/plugin-external-helpers": "^7.12.13", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.2", + "@babel/plugin-proposal-object-rest-spread": "^7.14.2", + "@babel/plugin-proposal-optional-chaining": "^7.14.2", + "@babel/plugin-transform-runtime": "^7.14.3", + "@babel/preset-env": "^7.14.2", + "@babel/preset-typescript": "^7.13.0", + "@babel/register": "^7.13.16", + "@rollup/plugin-babel": "^5.3.0", + "@rollup/plugin-commonjs": "^19.0.0", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^13.0.0", + "@rollup/plugin-strip": "^2.0.1", + "@rollup/plugin-typescript": "^8.2.1", + "@types/node": "^15.6.0", + "@types/tap": "^15.0.1", + "@typescript-eslint/eslint-plugin": "^4.24.0", + "@typescript-eslint/parser": "^4.24.0", + "core-js": "^3.12.1", + "cross-env": "^7.0.3", + "eslint": "^7.27.0", + "lect": "^0.17.0", + "lodash.clonedeep": "^4.5.0", + "rollup": "^2.49.0", + "rollup-plugin-ascii": "^0.0.3", + "rollup-plugin-banner": "^0.2.1", + "rollup-plugin-cleanup": "^3.2.1", + "rollup-plugin-dts": "^3.0.1", + "rollup-plugin-terser": "^7.0.2", + "tap": "^14.11.0", + "tslib": "^2.2.0", + "typescript": "^4.2.4" + } +} diff --git a/school/node_modules/ranges-merge/types/index.d.ts b/school/node_modules/ranges-merge/types/index.d.ts new file mode 100644 index 0000000..688f7c2 --- /dev/null +++ b/school/node_modules/ranges-merge/types/index.d.ts @@ -0,0 +1,13 @@ +declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined]; + +declare const version: string; +declare type ProgressFn = (percentageDone: number) => void; +interface Opts { + mergeType: 1 | 2 | "1" | "2"; + progressFn: null | undefined | ProgressFn; + joinRangesThatTouchEdges: boolean; +} +declare const defaults: Opts; +declare function rMerge(arrOfRanges: Range[] | null, originalOpts?: Partial<Opts>): Range[] | null; + +export { defaults, rMerge, version }; |