ranges-sort 5.0.5 → 5.0.11

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-2021 Roy Revelt and other contributors
3
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -26,18 +26,17 @@
26
26
 
27
27
  ## Install
28
28
 
29
- This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:
29
+ The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `4.1.0`.
30
30
 
31
31
  ```bash
32
32
  npm i ranges-sort
33
33
  ```
34
34
 
35
- If you need a legacy version which works with `require`, use version 4.1.0
36
-
37
35
  ## Quick Take
38
36
 
39
37
  ```js
40
38
  import { strict as assert } from "assert";
39
+
41
40
  import { rSort } from "ranges-sort";
42
41
 
43
42
  // Ranges (see codsen.com/ranges/) are sorted:
@@ -57,7 +56,7 @@ assert.deepEqual(
57
56
 
58
57
  ## Documentation
59
58
 
60
- Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API and examples.
59
+ Please [visit codsen.com](https://codsen.com/os/ranges-sort/) for a full description of the API.
61
60
 
62
61
  ## Contributing
63
62
 
@@ -67,6 +66,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
67
66
 
68
67
  MIT License
69
68
 
70
- Copyright (c) 2010-2021 Roy Revelt and other contributors
69
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
71
70
 
72
71
  <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">
@@ -1,68 +1,10 @@
1
1
  /**
2
2
  * @name ranges-sort
3
3
  * @fileoverview Sort string index ranges
4
- * @version 5.0.5
4
+ * @version 5.0.11
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.5";
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,
22
- ...originalOptions
23
- };
24
- let culpritsIndex;
25
- let culpritsLen;
26
- if (opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.filter(range => range).every((rangeArr, indx) => {
27
- if (rangeArr.length !== 2) {
28
- culpritsIndex = indx;
29
- culpritsLen = rangeArr.length;
30
- return false;
31
- }
32
- return true;
33
- })) {
34
- 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!`);
35
- }
36
- if (!arrOfRanges.filter(range => range).every((rangeArr, indx) => {
37
- if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) {
38
- culpritsIndex = indx;
39
- return false;
40
- }
41
- return true;
42
- })) {
43
- 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!`);
44
- }
45
- const maxPossibleIterations = arrOfRanges.filter(range => range).length ** 2;
46
- let counter = 0;
47
- return Array.from(arrOfRanges).filter(range => range).sort((range1, range2) => {
48
- if (opts.progressFn) {
49
- counter += 1;
50
- opts.progressFn(Math.floor(counter * 100 / maxPossibleIterations));
51
- }
52
- if (range1[0] === range2[0]) {
53
- if (range1[1] < range2[1]) {
54
- return -1;
55
- }
56
- if (range1[1] > range2[1]) {
57
- return 1;
58
- }
59
- return 0;
60
- }
61
- if (range1[0] < range2[0]) {
62
- return -1;
63
- }
64
- return 1;
65
- });
66
- }
67
-
68
- export { defaults, rSort, version };
10
+ var u="5.0.11";var m=u,d={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function g(r,l){if(!Array.isArray(r)||!r.length)return r;let n={...d,...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{d 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.5
4
+ * @version 5.0.11
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.5",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 d=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var c=(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={}))d.call(r,t)&&c(e,t,r[t]);if(p)for(var t of p(r))b.call(r,t)&&c(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))!d.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.11";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.5",
3
+ "version": "5.0.11",
4
4
  "description": "Sort string index ranges",
5
5
  "keywords": [
6
6
  "array",
@@ -28,93 +28,36 @@
28
28
  },
29
29
  "types": "types/index.d.ts",
30
30
  "scripts": {
31
- "build": "rollup -c",
32
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
33
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
34
- "clean_types": "../../scripts/cleanTypes.js",
35
- "dev": "rollup -c --dev",
36
- "devunittest": "npm run dev && tap --only -R 'base'",
37
- "esbuild": "node '../../scripts/esbuild.js'",
38
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
39
- "format": "npm run lect && npm run prettier && npm run lint",
40
- "lect": "lect",
41
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
42
- "perf": "node perf/check",
43
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
44
- "republish": "npm publish || :",
45
- "tap": "tap",
46
- "pretest": "npm run build",
47
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
48
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
49
- "tsc": "tsc",
50
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
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 && yarn run prettier 'types/index.d.ts' --write",
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
+ "prettier": "prettier",
41
+ "prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
42
+ "pretest": "yarn run lect && yarn run build",
43
+ "test": "c8 yarn run unit && yarn run examples && yarn run lint",
44
+ "unit": "uvu test"
51
45
  },
52
- "tap": {
53
- "check-coverage": false,
54
- "coverage-report": [
55
- "json-summary",
56
- "text"
57
- ],
58
- "node-arg": [
59
- "--no-warnings",
60
- "--experimental-loader",
61
- "@istanbuljs/esm-loader-hook"
46
+ "engines": {
47
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
48
+ },
49
+ "c8": {
50
+ "check-coverage": true,
51
+ "exclude": [
52
+ "**/test/**/*.*"
62
53
  ],
63
- "timeout": 0
54
+ "lines": 100
64
55
  },
65
56
  "lect": {
66
57
  "licence": {
67
58
  "extras": [
68
59
  ""
69
60
  ]
70
- },
71
- "req": "{ rSort }",
72
- "various": {
73
- "devDependencies": []
74
61
  }
75
- },
76
- "dependencies": {
77
- "@babel/runtime": "^7.16.0"
78
- },
79
- "devDependencies": {
80
- "@babel/cli": "^7.16.0",
81
- "@babel/core": "^7.16.0",
82
- "@babel/node": "^7.16.0",
83
- "@babel/plugin-external-helpers": "^7.16.0",
84
- "@babel/plugin-proposal-class-properties": "^7.16.0",
85
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
86
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
87
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
88
- "@babel/plugin-transform-runtime": "^7.16.0",
89
- "@babel/preset-env": "^7.16.0",
90
- "@babel/preset-typescript": "^7.16.0",
91
- "@babel/register": "^7.16.0",
92
- "@istanbuljs/esm-loader-hook": "^0.1.2",
93
- "@rollup/plugin-babel": "^5.3.0",
94
- "@rollup/plugin-commonjs": "^21.0.1",
95
- "@rollup/plugin-json": "^4.1.0",
96
- "@rollup/plugin-node-resolve": "^13.0.6",
97
- "@rollup/plugin-strip": "^2.1.0",
98
- "@rollup/plugin-typescript": "^8.3.0",
99
- "@types/node": "^16.11.6",
100
- "@types/tap": "^15.0.5",
101
- "@typescript-eslint/eslint-plugin": "^5.3.0",
102
- "@typescript-eslint/parser": "^5.3.0",
103
- "core-js": "^3.19.1",
104
- "cross-env": "^7.0.3",
105
- "eslint": "^8.2.0",
106
- "lect": "^0.18.5",
107
- "rollup": "^2.59.0",
108
- "rollup-plugin-ascii": "^0.0.3",
109
- "rollup-plugin-banner": "^0.2.1",
110
- "rollup-plugin-cleanup": "^3.2.1",
111
- "rollup-plugin-dts": "^4.0.1",
112
- "rollup-plugin-terser": "^7.0.2",
113
- "tap": "^15.0.10",
114
- "tslib": "^2.3.1",
115
- "typescript": "^4.4.4"
116
- },
117
- "engines": {
118
- "node": ">=12"
119
62
  }
120
63
  }
package/types/index.d.ts CHANGED
@@ -1,14 +1,17 @@
1
- declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
1
+ declare type Range =
2
+ | [from: number, to: number]
3
+ | [from: number, to: number, whatToInsert: string | null | undefined];
2
4
  declare type Ranges = Range[] | null;
3
-
4
5
  declare const version: string;
5
-
6
6
  declare type ProgressFn = (percentageDone: number) => void;
7
7
  interface Opts {
8
- strictlyTwoElementsInRangeArrays: boolean;
9
- progressFn: undefined | null | ProgressFn;
8
+ strictlyTwoElementsInRangeArrays: boolean;
9
+ progressFn: undefined | null | ProgressFn;
10
10
  }
11
11
  declare const defaults: Opts;
12
- declare function rSort(arrOfRanges: Ranges, originalOptions?: Partial<Opts>): Ranges;
12
+ declare function rSort(
13
+ arrOfRanges: Ranges,
14
+ originalOptions?: Partial<Opts>
15
+ ): Ranges;
13
16
 
14
- export { defaults, rSort, version };
17
+ 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);"}}