ranges-sort 5.0.7 → 5.0.10

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/README.md CHANGED
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 4.1.0
38
38
 
39
39
  ```js
40
40
  import { strict as assert } from "assert";
41
+
41
42
  import { rSort } from "ranges-sort";
42
43
 
43
44
  // Ranges (see codsen.com/ranges/) are sorted:
@@ -57,7 +58,7 @@ assert.deepEqual(
57
58
 
58
59
  ## Documentation
59
60
 
60
- Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API and examples.
61
+ Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API.
61
62
 
62
63
  ## Contributing
63
64
 
@@ -69,4 +70,6 @@ MIT License
69
70
 
70
71
  Copyright (c) 2010-2021 Roy Revelt and other contributors
71
72
 
73
+
72
74
  <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">
75
+
@@ -1,76 +1,10 @@
1
1
  /**
2
2
  * @name ranges-sort
3
3
  * @fileoverview Sort string index ranges
4
- * @version 5.0.7
4
+ * @version 5.0.10
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/ranges-sort/}
8
8
  */
9
9
 
10
- var version$1 = "5.0.7";
11
-
12
- const version = version$1;
13
- const defaults = {
14
- strictlyTwoElementsInRangeArrays: false,
15
- progressFn: null,
16
- };
17
- function rSort(arrOfRanges, originalOptions) {
18
- if (!Array.isArray(arrOfRanges) || !arrOfRanges.length) {
19
- return arrOfRanges;
20
- }
21
- const opts = { ...defaults, ...originalOptions };
22
- let culpritsIndex;
23
- let culpritsLen;
24
- if (opts.strictlyTwoElementsInRangeArrays &&
25
- !arrOfRanges
26
- .filter((range) => range)
27
- .every((rangeArr, indx) => {
28
- if (rangeArr.length !== 2) {
29
- culpritsIndex = indx;
30
- culpritsLen = rangeArr.length;
31
- return false;
32
- }
33
- return true;
34
- })) {
35
- 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!`);
36
- }
37
- if (!arrOfRanges
38
- .filter((range) => range)
39
- .every((rangeArr, indx) => {
40
- if (!Number.isInteger(rangeArr[0]) ||
41
- rangeArr[0] < 0 ||
42
- !Number.isInteger(rangeArr[1]) ||
43
- rangeArr[1] < 0) {
44
- culpritsIndex = indx;
45
- return false;
46
- }
47
- return true;
48
- })) {
49
- 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!`);
50
- }
51
- const maxPossibleIterations = arrOfRanges.filter((range) => range).length ** 2;
52
- let counter = 0;
53
- return Array.from(arrOfRanges)
54
- .filter((range) => range)
55
- .sort((range1, range2) => {
56
- if (opts.progressFn) {
57
- counter += 1;
58
- opts.progressFn(Math.floor((counter * 100) / maxPossibleIterations));
59
- }
60
- if (range1[0] === range2[0]) {
61
- if (range1[1] < range2[1]) {
62
- return -1;
63
- }
64
- if (range1[1] > range2[1]) {
65
- return 1;
66
- }
67
- return 0;
68
- }
69
- if (range1[0] < range2[0]) {
70
- return -1;
71
- }
72
- return 1;
73
- });
74
- }
75
-
76
- export { defaults, rSort, version };
10
+ var u="5.0.10";var m=u,c={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function g(r,l){if(!Array.isArray(r)||!r.length)return r;let n={...c,...l},s,o;if(n.strictlyTwoElementsInRangeArrays&&!r.every((e,t)=>!Array.isArray(e)||e.length!==2?(s=t,o=e.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, ${s}th range (${JSON.stringify(r[s],null,4)}) has not two but ${o} elements!`);if(!r.every((e,t)=>!Array.isArray(e)||!Number.isInteger(e[0])||e[0]<0||!Number.isInteger(e[1])||e[1]<0?(s=t,!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, ${s}th range (${JSON.stringify(r[s],null,4)}) does not consist of only natural numbers!`);let a=r.length**2,i=0;return Array.from(r).sort((e,t)=>(n.progressFn&&(i+=1,n.progressFn(Math.floor(i*100/a))),e[0]===t[0]?e[1]<t[1]?-1:e[1]>t[1]?1:0:e[0]<t[0]?-1:1))}export{c as defaults,g as rSort,m as version};
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @name ranges-sort
3
3
  * @fileoverview Sort string index ranges
4
- * @version 5.0.7
4
+ * @version 5.0.10
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/ranges-sort/}
8
8
  */
9
9
 
10
- !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).rangesSort={})}(this,(function(e){"use strict";const r={strictlyTwoElementsInRangeArrays:!1,progressFn:null};e.defaults=r,e.rSort=function(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 a=0;return Array.from(e).filter((e=>e)).sort(((e,r)=>(t.progressFn&&(a+=1,t.progressFn(Math.floor(100*a/i))),e[0]===r[0]?e[1]<r[1]?-1:e[1]>r[1]?1:0:e[0]<r[0]?-1:1)))},e.version="5.0.7",Object.defineProperty(e,"__esModule",{value:!0})}));
10
+ var rangesSort=(()=>{var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames,p=Object.getOwnPropertySymbols;var c=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var d=(e,r,t)=>r in e?u(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,l=(e,r)=>{for(var t in r||(r={}))c.call(r,t)&&d(e,t,r[t]);if(p)for(var t of p(r))b.call(r,t)&&d(e,t,r[t]);return e};var x=e=>u(e,"__esModule",{value:!0});var w=(e,r)=>{for(var t in r)u(e,t,{get:r[t],enumerable:!0})},v=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of f(r))!c.call(e,o)&&(t||o!=="default")&&u(e,o,{get:()=>r[o],enumerable:!(n=h(r,o))||n.enumerable});return e};var T=(e=>(r,t)=>e&&e.get(r)||(t=v(x({}),r,1),e&&e.set(r,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var F={};w(F,{defaults:()=>m,rSort:()=>E,version:()=>j});var y="5.0.10";var j=y,m={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function E(e,r){if(!Array.isArray(e)||!e.length)return e;let t=l(l({},m),r),n,o;if(t.strictlyTwoElementsInRangeArrays&&!e.every((s,i)=>!Array.isArray(s)||s.length!==2?(n=i,o=s.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, ${n}th range (${JSON.stringify(e[n],null,4)}) has not two but ${o} elements!`);if(!e.every((s,i)=>!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||!Number.isInteger(s[1])||s[1]<0?(n=i,!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, ${n}th range (${JSON.stringify(e[n],null,4)}) does not consist of only natural numbers!`);let g=e.length**2,a=0;return Array.from(e).sort((s,i)=>(t.progressFn&&(a+=1,t.progressFn(Math.floor(a*100/g))),s[0]===i[0]?s[1]<i[1]?-1:s[1]>i[1]?1:0:s[0]<i[0]?-1:1))}return T(F);})();
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { rSort } from "../dist/ranges-sort.esm.js";
5
6
 
6
7
  // Ranges (see codsen.com/ranges/) are sorted:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ranges-sort",
3
- "version": "5.0.7",
3
+ "version": "5.0.10",
4
4
  "description": "Sort string index ranges",
5
5
  "keywords": [
6
6
  "array",
@@ -28,89 +28,34 @@
28
28
  },
29
29
  "types": "types/index.d.ts",
30
30
  "scripts": {
31
- "build": "rollup -c",
32
- "build:esbuild": "node '../../scripts/esbuild.js'",
33
- "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
34
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
35
- "clean_types": "../../scripts/cleanTypes.js",
36
- "dev": "rollup -c --dev",
37
- "devunittest": "npm run dev && tap --only -R 'base'",
38
- "format": "npm run lect && npm run prettier && npm run lint",
39
- "lect": "lect",
40
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
41
- "perf": "node perf/check",
42
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
43
- "republish": "npm publish || :",
44
- "tap": "tap",
45
- "pretest": "npm run build",
46
- "test": "npm run test:ci && npm run perf",
47
- "test:ci": "npm run unittest && npm run test:examples && npm run format",
48
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
49
- "tsc": "tsc",
50
- "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
31
+ "build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
32
+ "dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
33
+ "dts": "rollup -c",
34
+ "examples": "node '../../ops/scripts/run-examples.js'",
35
+ "lect": "node '../../ops/lect/lect.js'",
36
+ "letspublish": "yarn publish || :",
37
+ "lint": "eslint . --fix",
38
+ "perf": "node perf/check.js",
39
+ "prepare": "echo 'ready'",
40
+ "pretest": "yarn run lect && yarn run build",
41
+ "test": "c8 yarn run unit && yarn run examples && yarn run lint",
42
+ "unit": "uvu test"
51
43
  },
52
- "tap": {
53
- "check-coverage": false,
54
- "node-arg": [
55
- "--no-warnings",
56
- "--experimental-loader",
57
- "@istanbuljs/esm-loader-hook"
44
+ "engines": {
45
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
46
+ },
47
+ "c8": {
48
+ "check-coverage": true,
49
+ "exclude": [
50
+ "**/test/**/*.*"
58
51
  ],
59
- "timeout": 0
52
+ "lines": 100
60
53
  },
61
54
  "lect": {
62
55
  "licence": {
63
56
  "extras": [
64
57
  ""
65
58
  ]
66
- },
67
- "req": "{ rSort }",
68
- "various": {
69
- "devDependencies": []
70
59
  }
71
- },
72
- "dependencies": {
73
- "@babel/runtime": "^7.16.3"
74
- },
75
- "devDependencies": {
76
- "@babel/cli": "^7.16.0",
77
- "@babel/core": "^7.16.0",
78
- "@babel/node": "^7.16.0",
79
- "@babel/plugin-external-helpers": "^7.16.0",
80
- "@babel/plugin-proposal-class-properties": "^7.16.0",
81
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
82
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
83
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
84
- "@babel/plugin-transform-runtime": "^7.16.4",
85
- "@babel/preset-env": "^7.16.4",
86
- "@babel/preset-typescript": "^7.16.0",
87
- "@babel/register": "^7.16.0",
88
- "@istanbuljs/esm-loader-hook": "^0.1.2",
89
- "@rollup/plugin-babel": "^5.3.0",
90
- "@rollup/plugin-commonjs": "^21.0.1",
91
- "@rollup/plugin-json": "^4.1.0",
92
- "@rollup/plugin-node-resolve": "^13.0.6",
93
- "@rollup/plugin-strip": "^2.1.0",
94
- "@rollup/plugin-typescript": "^8.3.0",
95
- "@types/node": "^16.11.10",
96
- "@types/tap": "^15.0.5",
97
- "@typescript-eslint/eslint-plugin": "^5.5.0",
98
- "@typescript-eslint/parser": "^5.5.0",
99
- "core-js": "^3.19.2",
100
- "cross-env": "^7.0.3",
101
- "eslint": "^8.3.0",
102
- "lect": "^0.18.7",
103
- "rollup": "^2.60.1",
104
- "rollup-plugin-ascii": "^0.0.3",
105
- "rollup-plugin-banner": "^0.2.1",
106
- "rollup-plugin-cleanup": "^3.2.1",
107
- "rollup-plugin-dts": "^4.0.1",
108
- "rollup-plugin-terser": "^7.0.2",
109
- "tap": "^15.1.5",
110
- "tslib": "^2.3.1",
111
- "typescript": "^4.5.2"
112
- },
113
- "engines": {
114
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
115
60
  }
116
61
  }
package/types/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
2
2
  declare type Ranges = Range[] | null;
3
-
4
3
  declare const version: string;
5
-
6
4
  declare type ProgressFn = (percentageDone: number) => void;
7
5
  interface Opts {
8
6
  strictlyTwoElementsInRangeArrays: boolean;
@@ -11,4 +9,4 @@ interface Opts {
11
9
  declare const defaults: Opts;
12
10
  declare function rSort(arrOfRanges: Ranges, originalOptions?: Partial<Opts>): Ranges;
13
11
 
14
- export { defaults, rSort, version };
12
+ export { Range, Ranges, defaults, rSort, version };
package/examples/api.json DELETED
@@ -1 +0,0 @@
1
- {"_quickTake.js":{"title":"Quick Take","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; rSort &#x7D; from \"ranges-sort\";\n\n// Ranges (see codsen.com/ranges/) are sorted:\nassert.deepEqual(\n rSort([\n [2, 3],\n [9, 10, \"bad grey wolf\"],\n [1, 2],\n ]),\n [\n [1, 2],\n [2, 3],\n [9, 10, \"bad grey wolf\"],\n ]\n);"}}