thm-p3-configurator 0.0.407 → 0.0.409

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.
@@ -1,22 +1,69 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.array.includes.js");
3
4
  require("core-js/modules/es.array.sort.js");
5
+ require("core-js/modules/es.regexp.exec.js");
6
+ require("core-js/modules/es.regexp.test.js");
7
+ require("core-js/modules/es.string.includes.js");
8
+ require("core-js/modules/es.string.replace.js");
4
9
  require("core-js/modules/es.string.trim.js");
5
10
  require("core-js/modules/esnext.iterator.constructor.js");
6
11
  require("core-js/modules/esnext.iterator.filter.js");
12
+ require("core-js/modules/esnext.iterator.find.js");
7
13
  require("core-js/modules/esnext.iterator.map.js");
8
14
  Object.defineProperty(exports, "__esModule", {
9
15
  value: true
10
16
  });
11
- exports.buildCountryDropdownOptions = void 0;
17
+ exports.isDutchPostalCode = exports.isBelgianPostalCode = exports.getCountryOptionForPostalCode = exports.buildCountryDropdownOptions = void 0;
18
+ require("core-js/modules/es.array.includes.js");
12
19
  require("core-js/modules/es.array.sort.js");
20
+ require("core-js/modules/es.regexp.exec.js");
21
+ require("core-js/modules/es.regexp.test.js");
22
+ require("core-js/modules/es.string.includes.js");
23
+ require("core-js/modules/es.string.replace.js");
13
24
  require("core-js/modules/es.string.trim.js");
14
25
  require("core-js/modules/esnext.iterator.constructor.js");
15
26
  require("core-js/modules/esnext.iterator.filter.js");
27
+ require("core-js/modules/esnext.iterator.find.js");
16
28
  require("core-js/modules/esnext.iterator.map.js");
17
29
  var _constants__ = require("../__constants__");
18
30
  const PRIORITY_COUNTRY_LABELS = [_constants__.COUNTRY_NAMES.NETHERLANDS, _constants__.COUNTRY_NAMES.BELGIUM, _constants__.COUNTRY_NAMES.BELGIUM_FALLBACK];
19
31
  const normalizeCountryLabel = label => (label || '').trim().toUpperCase();
32
+ const normalizeCountryLabelForMatch = function normalizeCountryLabelForMatch() {
33
+ let label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
34
+ return label.normalize('NFD').replace(/[\u0300-\u036f]/g, '').trim().toUpperCase();
35
+ };
36
+
37
+ /**
38
+ * @description Checks if a string is a valid Dutch postal code (e.g. 1234AB)
39
+ */
40
+ const isDutchPostalCode = postalCode => {
41
+ if (!postalCode) return false;
42
+ const cleanedPostalCode = postalCode.replace(/\s/g, '');
43
+ return /^[1-9][0-9]{3}[A-Z]{2}$/i.test(cleanedPostalCode);
44
+ };
45
+
46
+ /**
47
+ * @description Checks if a string is a valid Belgian postal code (e.g. 1000)
48
+ */
49
+ exports.isDutchPostalCode = isDutchPostalCode;
50
+ const isBelgianPostalCode = postalCode => {
51
+ if (!postalCode) return false;
52
+ const cleanedPostalCode = postalCode.replace(/\s/g, '');
53
+ return /^[1-9][0-9]{3}$/.test(cleanedPostalCode);
54
+ };
55
+ exports.isBelgianPostalCode = isBelgianPostalCode;
56
+ const BELGIUM_MATCH_LABELS = [_constants__.COUNTRY_NAMES.BELGIUM, _constants__.COUNTRY_NAMES.BELGIUM_FALLBACK].map(normalizeCountryLabelForMatch);
57
+
58
+ /**
59
+ * @description Infers a country dropdown option from a postal code (NL/BE formats).
60
+ */
61
+ const getCountryOptionForPostalCode = exports.getCountryOptionForPostalCode = function getCountryOptionForPostalCode(postalCode) {
62
+ let countryOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
63
+ const targetLabels = isDutchPostalCode(postalCode) ? [normalizeCountryLabelForMatch(_constants__.COUNTRY_NAMES.NETHERLANDS)] : isBelgianPostalCode(postalCode) ? BELGIUM_MATCH_LABELS : null;
64
+ if (!targetLabels) return null;
65
+ return countryOptions.find(option => targetLabels.includes(normalizeCountryLabelForMatch(option === null || option === void 0 ? void 0 : option.label))) || null;
66
+ };
20
67
  const getCountrySortPriority = label => {
21
68
  const normalized = normalizeCountryLabel(label);
22
69
  const index = PRIORITY_COUNTRY_LABELS.findIndex(priorityLabel => normalizeCountryLabel(priorityLabel) === normalized);
@@ -64,6 +64,18 @@ Object.keys(_singleOrderCustomerDetails).forEach(function (key) {
64
64
  }
65
65
  });
66
66
  });
67
+ var _countryOptions = require("./countryOptions");
68
+ Object.keys(_countryOptions).forEach(function (key) {
69
+ if (key === "default" || key === "__esModule") return;
70
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
71
+ if (key in exports && exports[key] === _countryOptions[key]) return;
72
+ Object.defineProperty(exports, key, {
73
+ enumerable: true,
74
+ get: function get() {
75
+ return _countryOptions[key];
76
+ }
77
+ });
78
+ });
67
79
  function _interopRequireDefault(e) {
68
80
  return e && e.__esModule ? e : {
69
81
  default: e
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.407",
3
+ "version": "0.0.409",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",