@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 CHANGED
@@ -916,26 +916,81 @@ exports.phone2numeric = function (input) {
916
916
  };
917
917
 
918
918
  /*!
919
- * Parse a string as Python's `float()` does: surrounding whitespace, an
920
- * optional sign, then digits (single underscores allowed between them)
921
- * with an optional fraction and exponent, or inf / infinity / nan in any
922
- * case. Returns undefined where Python raises ValueError. @private
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
- // A trailing \s+$ takes quadratic time on a long run of whitespace inside
926
- // the value; utils.strip gives the same output in linear time.
927
- // var t = s.replace(/^\s+|\s+$/g, '');
928
- var t = utils.strip(s);
929
- if (/^[+-]?(inf|infinity)$/i.test(t)) {
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 (/^[+-]?nan$/i.test(t)) {
990
+ if (t.indexOf('nan') !== -1) {
933
991
  return NaN;
934
992
  }
935
- if (!/^[+-]?(\d(_?\d)*(\.(\d(_?\d)*)?)?|\.\d(_?\d)*)([eE][+-]?\d(_?\d)*)?$/.test(t)) {
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
@@ -32,7 +32,7 @@ exports.name = 'django';
32
32
  *
33
33
  * @type {String}
34
34
  */
35
- exports.version = "2.11.0";
35
+ exports.version = "2.12.0";
36
36
 
37
37
  /**
38
38
  * Expression-level parser — Pratt-style recursive descent that consumes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinostone/swig-django",
3
- "version": "2.11.0",
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.11.0"
25
+ "@rhinostone/swig-core": "2.12.0"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"