@bigbinary/neeto-commons-frontend 2.1.34 → 2.1.35

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/README.md CHANGED
@@ -156,6 +156,7 @@ Web utility functions [↗](./docs/utils/README.md)
156
156
  - [toLocale](./docs/utils/toLocale.md)
157
157
  - [getQueryParams](./docs/utils/getQueryParams.md)
158
158
  - [joinHyphenCase](./docs/utils/joinHyphenCase.md)
159
+ - [hyphenize](./docs/utils/hyphenize.md)
159
160
  - [debounce](./docs/utils/debounce.md)
160
161
  - [hasPermission](./docs/utils/hasPermission.md)
161
162
  - [hasAnyPermission](./docs/utils/hasAnyPermission.md)
@@ -64,6 +64,7 @@ var HEADERS_KEYS = {
64
64
  contentType: "Content-Type",
65
65
  accept: "Accept"
66
66
  };
67
+ var ANY_CASE_STR = "__ANY_CASE__";
67
68
 
68
69
  var shouldNot = function shouldNot(skip) {
69
70
  return _typeof$1(skip) === "object" || !skip;
@@ -2367,19 +2368,75 @@ var replaceNullValuesWithGetter = function replaceNullValuesWithGetter(inputObje
2367
2368
  }
2368
2369
  return result;
2369
2370
  };
2370
- var getSentenceCaseProcessor = function getSentenceCaseProcessor() {
2371
- return {
2372
- type: "postProcessor",
2373
- name: "sentenceCasePlaceholderAndTypography",
2374
- process: function process(value, keys) {
2375
- if (keys.some(function (str) {
2376
- return (str.startsWith("placeholder.") || str.startsWith("typography.")) && !str.includes("anyCase.");
2377
- })) {
2378
- return value.charAt(0).toLocaleUpperCase() + value.slice(1).toLocaleLowerCase();
2371
+
2372
+ /*
2373
+ For some reason dynamic values available via options param doesn't have formatter 'anyCase' applied.
2374
+ So here we are just re applying.
2375
+ */
2376
+ var wrapAnyCaseIfApplicable = function wrapAnyCaseIfApplicable(value, dynamic) {
2377
+ return Object.keys(dynamic).map(function (item) {
2378
+ var format = anyCaseFormatter(dynamic[item]);
2379
+ if (value.includes(format)) return format;
2380
+ return dynamic[item];
2381
+ });
2382
+ };
2383
+ var isAnyCaseStr = function isAnyCaseStr(str) {
2384
+ return str.startsWith(ANY_CASE_STR) && str.endsWith(ANY_CASE_STR);
2385
+ };
2386
+ var lowerCaseDynamicText = function lowerCaseDynamicText(value, dynamic) {
2387
+ /*
2388
+ Example:
2389
+ translation: {
2390
+ create: "Create {{entity1}}, {{entity2, anyCase}} and {{entity3}} and apply COLOR"
2391
+ }
2392
+ // ...
2393
+ t("create", {entity1: "Car", entity2: 'BuS', enity3: "Truck"});
2394
+ */
2395
+
2396
+ // example: ['Car', '__ANY_CASE__BuS__ANY_CASE__', 'Truck']
2397
+ var dynamicArr = wrapAnyCaseIfApplicable(value, dynamic);
2398
+ //example pattern: (Car)|(__ANY_CASE__BuS__ANY_CASE__)|(Bus)
2399
+ var regexPattern = dynamicArr.map(function (delimiter) {
2400
+ return "(".concat(delimiter, ")");
2401
+ }).join("|");
2402
+ /* Generated array
2403
+ [
2404
+ 'Create ', // static
2405
+ 'Car', // dynamic
2406
+ ', ', // static
2407
+ '__ANY_CASE__BuS__ANY_CASE__', // dynamic
2408
+ ' and ', // static
2409
+ 'Truck', // dynamic
2410
+ ' and apply COLOR' // static
2411
+ ]
2412
+ */
2413
+ var splitArr = value.split(new RegExp(regexPattern)).filter(Boolean);
2414
+ return splitArr.map(function (item, index) {
2415
+ if (dynamicArr.includes(item)) {
2416
+ if (isAnyCaseStr(item)) {
2417
+ return item.replaceAll(ANY_CASE_STR, "");
2418
+ } else if (index === 0) {
2419
+ // Don't lower case if it is first word.
2420
+ return item;
2379
2421
  }
2380
- return value;
2422
+ return item.toLocaleLowerCase();
2381
2423
  }
2382
- };
2424
+ return item;
2425
+ }).join("");
2426
+ };
2427
+ var sentenceCaseProcessor = {
2428
+ type: "postProcessor",
2429
+ name: "sentenceCaseProcessor",
2430
+ process: function process(value, _, options) {
2431
+ var dynamic = ramda.omit(["lng", "lngs", "ns"], options); // removes default args
2432
+ if (ramda.isEmpty(dynamic)) return value; // Do nothing if no dynamic values
2433
+
2434
+ return lowerCaseDynamicText(value, dynamic);
2435
+ }
2436
+ };
2437
+ var anyCaseFormatter = function anyCaseFormatter(value) {
2438
+ if (value) return ANY_CASE_STR + value + ANY_CASE_STR;
2439
+ return value;
2383
2440
  };
2384
2441
 
2385
2442
  var generic = {
@@ -2500,7 +2557,7 @@ var commonsEn = {
2500
2557
  // eslint-disable-next-line import/no-mutable-exports
2501
2558
  exports.taxonomies = {};
2502
2559
  var initializeI18n = function initializeI18n(hostTranslations) {
2503
- var _window$globalProps, _i18n$services$format;
2560
+ var _window$globalProps, _i18n$services$format, _i18n$services$format2;
2504
2561
  var packageTranslations = preval.require("./configs/scripts/getPkgTranslations.js");
2505
2562
  var commonsTranslations = {
2506
2563
  en: {
@@ -2508,10 +2565,16 @@ var initializeI18n = function initializeI18n(hostTranslations) {
2508
2565
  }
2509
2566
  };
2510
2567
  var resources = [hostTranslations, commonsTranslations, packageTranslations].reduce(ramda.mergeDeepLeft);
2511
- if ((_window$globalProps = window.globalProps) !== null && _window$globalProps !== void 0 && _window$globalProps.taxonomies) {
2512
- exports.taxonomies = replaceNullValuesWithGetter(window.globalProps.taxonomies);
2513
- }
2514
- i18n__default["default"].use(Browser).use(reactI18next.initReactI18next).use(getSentenceCaseProcessor()).init({
2568
+ var defaultTaxonomyKeys = Object.keys(resources.en.translation.taxonomyDefaultLabels || {});
2569
+ var defaultTaxonomies = Object.fromEntries(defaultTaxonomyKeys.map(function (key) {
2570
+ return [key, {
2571
+ singular: null,
2572
+ plural: null
2573
+ }];
2574
+ }));
2575
+ var hostTaxonomies = ((_window$globalProps = window.globalProps) === null || _window$globalProps === void 0 ? void 0 : _window$globalProps.taxonomies) || {};
2576
+ exports.taxonomies = replaceNullValuesWithGetter(ramda.mergeDeepLeft(hostTaxonomies, defaultTaxonomies));
2577
+ i18n__default["default"].use(Browser).use(reactI18next.initReactI18next).use(sentenceCaseProcessor).init({
2515
2578
  resources: resources,
2516
2579
  fallbackLng: "en",
2517
2580
  interpolation: {
@@ -2521,7 +2584,7 @@ var initializeI18n = function initializeI18n(hostTranslations) {
2521
2584
  escapeValue: false,
2522
2585
  skipOnVariables: false
2523
2586
  },
2524
- postProcess: ["sentenceCasePlaceholderAndTypography"],
2587
+ postProcess: ["sentenceCaseProcessor"],
2525
2588
  detection: {
2526
2589
  order: ["querystring", "cookie", "navigator", "path"],
2527
2590
  caches: ["cookie"],
@@ -2546,6 +2609,7 @@ var initializeI18n = function initializeI18n(hostTranslations) {
2546
2609
  return formatter.format(sanitizedItems);
2547
2610
  };
2548
2611
  });
2612
+ (_i18n$services$format2 = i18n__default["default"].services.formatter) === null || _i18n$services$format2 === void 0 ? void 0 : _i18n$services$format2.add("anyCase", anyCaseFormatter);
2549
2613
  };
2550
2614
 
2551
2615
  function initializeLogger() {