Update src/extensions/jwArray/index.js
Browse files
src/extensions/jwArray/index.js
CHANGED
|
@@ -12,14 +12,23 @@ let arrayLimit = 2 ** 32
|
|
| 12 |
* @returns {string}
|
| 13 |
*/
|
| 14 |
function formatNumber(x) {
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
}
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
function clampIndex(x) {
|
| 24 |
return Math.min(Math.max(x, 0), arrayLimit)
|
| 25 |
}
|
|
@@ -78,7 +87,7 @@ class ArrayType {
|
|
| 78 |
case "boolean":
|
| 79 |
return x ? "true" : "false"
|
| 80 |
case "string":
|
| 81 |
-
return `"${Cast.toString(x)}"`
|
| 82 |
}
|
| 83 |
} catch {}
|
| 84 |
return "?"
|
|
|
|
| 12 |
* @returns {string}
|
| 13 |
*/
|
| 14 |
function formatNumber(x) {
|
| 15 |
+
if (x >= 1e6) {
|
| 16 |
+
return x.toExponential(4)
|
| 17 |
+
} else {
|
| 18 |
+
x = Math.floor(x * 1000) / 1000
|
| 19 |
+
return x.toFixed(Math.min(3, (String(x).split('.')[1] || '').length))
|
| 20 |
+
}
|
| 21 |
}
|
| 22 |
|
| 23 |
+
const escapeHTML = unsafe => {
|
| 24 |
+
return unsafe
|
| 25 |
+
.replaceAll("&", "&")
|
| 26 |
+
.replaceAll("<", "<")
|
| 27 |
+
.replaceAll(">", ">")
|
| 28 |
+
.replaceAll('"', """)
|
| 29 |
+
.replaceAll("'", "'")
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
function clampIndex(x) {
|
| 33 |
return Math.min(Math.max(x, 0), arrayLimit)
|
| 34 |
}
|
|
|
|
| 87 |
case "boolean":
|
| 88 |
return x ? "true" : "false"
|
| 89 |
case "string":
|
| 90 |
+
return `"${escapeHTML(Cast.toString(x))}"`
|
| 91 |
}
|
| 92 |
} catch {}
|
| 93 |
return "?"
|