File: 2006_avoid_natural-compare.patch

package info (click to toggle)
eslint 5.16.0~dfsg%2B~4.16.8-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,204 kB
  • sloc: javascript: 178,762; makefile: 123; perl: 48; sh: 32
file content (119 lines) | stat: -rw-r--r-- 3,475 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Description: Avoid use of node module natural-compare
 Instead embed the module inline.
 .
 Origin: <https://github.com/litejs/natural-compare-lite/blob/v1.4.0/index.js>
Forwarded: no
Author: Jonas Smedegaard <dr@jones.dk>
Last-Update: 2019-10-19
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/lib/rules/sort-keys.js
+++ b/lib/rules/sort-keys.js
@@ -9,8 +9,7 @@
 // Requirements
 //------------------------------------------------------------------------------
 
-const astUtils = require("../util/ast-utils"),
-    naturalCompare = require("natural-compare");
+const astUtils = require("../util/ast-utils");
 
 //------------------------------------------------------------------------------
 // Helpers
@@ -33,6 +32,97 @@
 }
 
 /**
+ * Function to do "natural sort"
+ *
+ * Origin: <https://github.com/litejs/natural-compare-lite/blob/v1.4.0/index.js>
+ *
+ * @version    1.4.0
+ * @date       2015-10-26
+ * @stability  3 - Stable
+ * @author     Lauri Rooden (https://github.com/litejs/natural-compare-lite)
+ * @license    MIT License
+ * @param {string} a - The first character to compare.
+ * @param {string} b - The second character to compare.
+ * @returns {string} The equality -1 | 0 | 1.
+ * @private
+ */
+function naturalCompare(a, b) {
+    let i, codeA,
+        codeB = 1,
+        posA = 0,
+        posB = 0;
+    const alphabet = String.alphabet;
+
+    /* eslint-disable no-param-reassign */
+    /* eslint-disable no-sequences */
+
+    /**
+     * @param {string} str - string.
+     * @param {string} pos - position.
+     * @param {string} code - character codes.
+     * @returns {string} new character codes.
+     * @private
+     */
+    function getCode(str, pos, code) {
+        if (code) {
+            for (i = pos; code = getCode(str, i), code < 76 && code > 65;) {
+                ++i;
+            }
+            return +str.slice(pos - 1, i);
+        }
+        code = alphabet && alphabet.indexOf(str.charAt(pos));
+
+        let newCode;
+
+        if (code > -1) {
+            newCode = code + 76;
+        } else if ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) {
+            newCode = code;
+        } else if (code < 46) {
+            newCode = 65; // -
+        } else if (code < 48) {
+            newCode = code - 1;
+        } else if (code < 58) {
+            newCode = code + 18; // 0-9
+        } else if (code < 65) {
+            newCode = code - 11;
+        } else if (code < 91) {
+            newCode = code + 11; // A-Z
+        } else if (code < 97) {
+            newCode = code - 37;
+        } else if (code < 123) {
+            newCode = code + 5; // a-z
+        } else {
+            newCode = code - 63;
+        }
+        return newCode;
+    }
+
+    /* eslint-enable no-sequences */
+
+    if ((a += "") !== (b += "")) {
+        for (;codeB;) {
+            codeA = getCode(a, posA++);
+            codeB = getCode(b, posB++);
+
+            if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
+                codeA = getCode(a, posA, posA);
+                codeB = getCode(b, posB, posA = i);
+                posB = i;
+            }
+
+            if (codeA !== codeB) {
+                return (codeA < codeB) ? -1 : 1;
+            }
+        }
+    }
+    return 0;
+
+    /* eslint-enable no-param-reassign */
+}
+
+
+/**
  * Functions which check that the given 2 names are in specific order.
  *
  * Postfix `I` is meant insensitive.