@bigbinary/neeto-playwright-commons 1.4.1 → 1.4.2

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/index.cjs.js CHANGED
@@ -275,6 +275,62 @@ const generateStagingData = (product = "invoice") => {
275
275
  };
276
276
  };
277
277
 
278
+ const LOWERCASED = "__LOWERCASED__";
279
+ const FORMATS = {
280
+ boldList: "boldList",
281
+ list: "list",
282
+ anyCase: "anyCase",
283
+ };
284
+ const LIST_FORMATS = [FORMATS.boldList, FORMATS.list];
285
+
286
+ const cacheStore = new Map();
287
+ const fetchCachedOrInvoke = (func, lng, options) => {
288
+ var _a;
289
+ let cache = (_a = cacheStore.get(lng)) === null || _a === void 0 ? void 0 : _a.get(options);
290
+ if (cache)
291
+ return cache;
292
+ cache = func(lng, options);
293
+ const lngCache = cacheStore.get(lng);
294
+ if (lngCache)
295
+ lngCache.set(options, cache);
296
+ else
297
+ cacheStore.set(lng, new Map([[options, cache]]));
298
+ return cache;
299
+ };
300
+ const lowerCaseDynamicTextFormatter = (value, format) => {
301
+ if (!value || format === FORMATS.anyCase || typeof value !== "string") {
302
+ return value;
303
+ }
304
+ return LOWERCASED + value.toLocaleLowerCase();
305
+ };
306
+ const listFormatter = ({ value, format, lng, options, }) => {
307
+ const formatter = fetchCachedOrInvoke((lng, options) => new Intl.ListFormat(lng, options), lng, options);
308
+ let newValue = value;
309
+ if (format === FORMATS.boldList) {
310
+ newValue = value.map(item => `<strong>${item}</strong>`);
311
+ }
312
+ const items = newValue.toString().split(",");
313
+ return formatter.format(items);
314
+ };
315
+
316
+ const sentenceCase = (value) => value.charAt(0).toLocaleUpperCase() + value.slice(1);
317
+ const sentenceCaseProcessor = {
318
+ type: "postProcessor",
319
+ name: "sentenceCaseProcessor",
320
+ process: (value) => {
321
+ const shouldSentenceCase = value.startsWith(LOWERCASED);
322
+ value = value.replaceAll(LOWERCASED, "");
323
+ return shouldSentenceCase ? sentenceCase(value) : value;
324
+ },
325
+ };
326
+ const removeTagsProcessor = {
327
+ type: "postProcessor",
328
+ name: "removeTagsProcessor",
329
+ process: function (value) {
330
+ return value.replace(/<\/?[^>]+(>|$)/g, "");
331
+ },
332
+ };
333
+
278
334
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
279
335
 
280
336
  var tasks = {};
@@ -7019,19 +7075,27 @@ const i18nFixture = {
7019
7075
  resources: { en: { translation } },
7020
7076
  interpolation: {
7021
7077
  defaultVariables: { taxonomies },
7078
+ escapeValue: false,
7079
+ skipOnVariables: false,
7080
+ alwaysFormat: true,
7081
+ format: (value, format, lng, options) => {
7082
+ let newValue = value;
7083
+ if (LIST_FORMATS.includes(format !== null && format !== void 0 ? format : "")) {
7084
+ newValue = listFormatter({
7085
+ value: newValue,
7086
+ format,
7087
+ lng,
7088
+ options,
7089
+ });
7090
+ return newValue;
7091
+ }
7092
+ return lowerCaseDynamicTextFormatter(newValue, format);
7093
+ },
7022
7094
  },
7023
- postProcess: "removeTags",
7095
+ postProcess: ["removeTagsProcessor", "sentenceCaseProcessor"],
7024
7096
  };
7025
7097
  const i18nInitialized = await playwrightI18nextFixture.initI18n({
7026
- plugins: [
7027
- {
7028
- type: "postProcessor",
7029
- name: "removeTags",
7030
- process: function (value) {
7031
- return value.replace(/<\/?[^>]+(>|$)/g, "");
7032
- },
7033
- },
7034
- ],
7098
+ plugins: [removeTagsProcessor, sentenceCaseProcessor],
7035
7099
  options,
7036
7100
  // Fetch translations in every test or fetch once
7037
7101
  cache: true,