@nxtedition/lib 15.0.52 → 15.0.53

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.
Files changed (2) hide show
  1. package/merge-ranges.js +23 -8
  2. package/package.json +1 -1
package/merge-ranges.js CHANGED
@@ -1,19 +1,34 @@
1
+ const EMPTY_ARR = Object.freeze([])
2
+
1
3
  module.exports = function mergeRanges(ranges) {
2
4
  if (!Array.isArray(ranges)) {
3
- return []
5
+ return EMPTY_ARR
4
6
  }
5
7
 
6
- const stack = []
8
+ if (ranges.length === 1) {
9
+ const range = ranges[0]
10
+ return Array.isArray(range) && range.length === 2 && range[1] > range[0] ? ranges : EMPTY_ARR
11
+ }
7
12
 
8
- ranges = ranges
9
- .filter((range) => range && range.length > 0 && range[1] > range[0])
10
- .sort((a, b) => a[0] - b[0])
13
+ {
14
+ // Make sure ranges are valid and copied for mutation.
15
+ const tmp = []
16
+ for (let n = 0, len = ranges.length; n < len; n++) {
17
+ const range = ranges[n]
18
+ if (Array.isArray(range) && range.length === 2 && range[1] > range[0]) {
19
+ tmp.push([range[0], range[1]])
20
+ }
21
+ }
22
+ ranges = tmp
23
+ }
11
24
 
12
- if (!ranges.length) {
13
- return []
25
+ if (ranges.length <= 1) {
26
+ return ranges
14
27
  }
15
28
 
16
- ranges = JSON.parse(JSON.stringify(ranges))
29
+ ranges.sort((a, b) => a[0] - b[0])
30
+
31
+ const stack = []
17
32
 
18
33
  // Add first range to stack
19
34
  stack.push(ranges[0])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "15.0.52",
3
+ "version": "15.0.53",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "files": [