@rhinostone/swig-django 2.11.0 → 2.12.0
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/lib/filters.js +69 -14
- package/lib/index.js +1 -1
- package/package.json +2 -2
package/lib/filters.js
CHANGED
|
@@ -916,26 +916,81 @@ exports.phone2numeric = function (input) {
|
|
|
916
916
|
};
|
|
917
917
|
|
|
918
918
|
/*!
|
|
919
|
-
*
|
|
920
|
-
*
|
|
921
|
-
*
|
|
922
|
-
*
|
|
919
|
+
* Decimal digits outside ASCII, which Python's `float()` reads as their
|
|
920
|
+
* values: a regex for one such digit, and one for any character outside
|
|
921
|
+
* ASCII. Built in a try/catch because an engine without Unicode property
|
|
922
|
+
* escapes (ES2018) throws on them; it gets null, and does not read
|
|
923
|
+
* non-ASCII digits as numbers. @private
|
|
924
|
+
*/
|
|
925
|
+
var pyDigits = (function () {
|
|
926
|
+
try {
|
|
927
|
+
return { decimal: new RegExp('\\p{Nd}', 'u'), nonAscii: new RegExp('[^\\x00-\\x7f]', 'gu') };
|
|
928
|
+
} catch (e) {
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
}());
|
|
932
|
+
|
|
933
|
+
/*!
|
|
934
|
+
* The whitespace Python's `float()` strips around a number: the ASCII
|
|
935
|
+
* whitespace of C's `isspace`, and Python's whitespace above U+007F. The
|
|
936
|
+
* separators U+001C to U+001F are whitespace to `str.isspace()`, but make
|
|
937
|
+
* `float()` raise. @private
|
|
938
|
+
*/
|
|
939
|
+
var FLOAT_SPACE = new RegExp('[\\t\\n\\v\\f\\r \\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]'),
|
|
940
|
+
PY_FLOAT = /^[+-]?(?:(?:\d(?:_?\d)*(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:e[+-]?\d(?:_?\d)*)?|inf(?:inity)?|nan)$/i;
|
|
941
|
+
|
|
942
|
+
/*!
|
|
943
|
+
* The ASCII digit for a non-ASCII decimal digit, which Python's `float()`
|
|
944
|
+
* reads as its value (Unicode encodes decimal digits in runs of ten, from 0
|
|
945
|
+
* to 9). Any other character is kept, and makes the number invalid.
|
|
946
|
+
* @private
|
|
947
|
+
*/
|
|
948
|
+
function decimalValue(ch) {
|
|
949
|
+
var cp = ch.codePointAt(0), zero = cp;
|
|
950
|
+
if (!pyDigits.decimal.test(ch)) {
|
|
951
|
+
return ch;
|
|
952
|
+
}
|
|
953
|
+
while (pyDigits.decimal.test(String.fromCodePoint(zero - 1))) {
|
|
954
|
+
zero -= 1;
|
|
955
|
+
}
|
|
956
|
+
return String((cp - zero) % 10);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/*!
|
|
960
|
+
* Read a string as Python's `float()` does: digits (single underscores
|
|
961
|
+
* allowed between them) with an optional sign, fraction and exponent, or
|
|
962
|
+
* inf, infinity or nan in any case, inside optional whitespace. A decimal
|
|
963
|
+
* digit of any script reads as its value, and the whitespace is Python's,
|
|
964
|
+
* not what `\s` matches: U+0085 is whitespace there, U+FEFF is not.
|
|
965
|
+
* Returns undefined where Python raises ValueError. @private
|
|
923
966
|
*/
|
|
924
967
|
function pyFloat(s) {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
968
|
+
var start = 0, end, t;
|
|
969
|
+
if (pyDigits) {
|
|
970
|
+
s = s.replace(pyDigits.nonAscii, decimalValue);
|
|
971
|
+
}
|
|
972
|
+
// A pattern such as \s+$ takes quadratic time on a long run of whitespace
|
|
973
|
+
// inside the value, so the ends are trimmed with a loop (this reader once
|
|
974
|
+
// trimmed with s.replace(/^\s+|\s+$/g, '')).
|
|
975
|
+
end = s.length;
|
|
976
|
+
while (start < end && FLOAT_SPACE.test(s.charAt(start))) {
|
|
977
|
+
start += 1;
|
|
978
|
+
}
|
|
979
|
+
while (end > start && FLOAT_SPACE.test(s.charAt(end - 1))) {
|
|
980
|
+
end -= 1;
|
|
981
|
+
}
|
|
982
|
+
t = s.slice(start, end);
|
|
983
|
+
if (!PY_FLOAT.test(t)) {
|
|
984
|
+
return undefined;
|
|
985
|
+
}
|
|
986
|
+
t = t.replace(/_/g, '').toLowerCase();
|
|
987
|
+
if (t.indexOf('inf') !== -1) {
|
|
930
988
|
return (t.charAt(0) === '-') ? -Infinity : Infinity;
|
|
931
989
|
}
|
|
932
|
-
if (
|
|
990
|
+
if (t.indexOf('nan') !== -1) {
|
|
933
991
|
return NaN;
|
|
934
992
|
}
|
|
935
|
-
|
|
936
|
-
return undefined;
|
|
937
|
-
}
|
|
938
|
-
return parseFloat(t.replace(/_/g, ''));
|
|
993
|
+
return Number(t);
|
|
939
994
|
}
|
|
940
995
|
|
|
941
996
|
/**
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinostone/swig-django",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Django-syntax frontend for the @rhinostone/swig-core template engine. Part of the @rhinostone/swig multi-flavor family.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"template",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node": ">=12"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@rhinostone/swig-core": "2.
|
|
25
|
+
"@rhinostone/swig-core": "2.12.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|