@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.js CHANGED
@@ -242,6 +242,62 @@ const generateStagingData = (product = "invoice") => {
242
242
  };
243
243
  };
244
244
 
245
+ const LOWERCASED = "__LOWERCASED__";
246
+ const FORMATS = {
247
+ boldList: "boldList",
248
+ list: "list",
249
+ anyCase: "anyCase",
250
+ };
251
+ const LIST_FORMATS = [FORMATS.boldList, FORMATS.list];
252
+
253
+ const cacheStore = new Map();
254
+ const fetchCachedOrInvoke = (func, lng, options) => {
255
+ var _a;
256
+ let cache = (_a = cacheStore.get(lng)) === null || _a === void 0 ? void 0 : _a.get(options);
257
+ if (cache)
258
+ return cache;
259
+ cache = func(lng, options);
260
+ const lngCache = cacheStore.get(lng);
261
+ if (lngCache)
262
+ lngCache.set(options, cache);
263
+ else
264
+ cacheStore.set(lng, new Map([[options, cache]]));
265
+ return cache;
266
+ };
267
+ const lowerCaseDynamicTextFormatter = (value, format) => {
268
+ if (!value || format === FORMATS.anyCase || typeof value !== "string") {
269
+ return value;
270
+ }
271
+ return LOWERCASED + value.toLocaleLowerCase();
272
+ };
273
+ const listFormatter = ({ value, format, lng, options, }) => {
274
+ const formatter = fetchCachedOrInvoke((lng, options) => new Intl.ListFormat(lng, options), lng, options);
275
+ let newValue = value;
276
+ if (format === FORMATS.boldList) {
277
+ newValue = value.map(item => `<strong>${item}</strong>`);
278
+ }
279
+ const items = newValue.toString().split(",");
280
+ return formatter.format(items);
281
+ };
282
+
283
+ const sentenceCase = (value) => value.charAt(0).toLocaleUpperCase() + value.slice(1);
284
+ const sentenceCaseProcessor = {
285
+ type: "postProcessor",
286
+ name: "sentenceCaseProcessor",
287
+ process: (value) => {
288
+ const shouldSentenceCase = value.startsWith(LOWERCASED);
289
+ value = value.replaceAll(LOWERCASED, "");
290
+ return shouldSentenceCase ? sentenceCase(value) : value;
291
+ },
292
+ };
293
+ const removeTagsProcessor = {
294
+ type: "postProcessor",
295
+ name: "removeTagsProcessor",
296
+ process: function (value) {
297
+ return value.replace(/<\/?[^>]+(>|$)/g, "");
298
+ },
299
+ };
300
+
245
301
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
246
302
 
247
303
  var tasks = {};
@@ -6986,19 +7042,27 @@ const i18nFixture = {
6986
7042
  resources: { en: { translation } },
6987
7043
  interpolation: {
6988
7044
  defaultVariables: { taxonomies },
7045
+ escapeValue: false,
7046
+ skipOnVariables: false,
7047
+ alwaysFormat: true,
7048
+ format: (value, format, lng, options) => {
7049
+ let newValue = value;
7050
+ if (LIST_FORMATS.includes(format !== null && format !== void 0 ? format : "")) {
7051
+ newValue = listFormatter({
7052
+ value: newValue,
7053
+ format,
7054
+ lng,
7055
+ options,
7056
+ });
7057
+ return newValue;
7058
+ }
7059
+ return lowerCaseDynamicTextFormatter(newValue, format);
7060
+ },
6989
7061
  },
6990
- postProcess: "removeTags",
7062
+ postProcess: ["removeTagsProcessor", "sentenceCaseProcessor"],
6991
7063
  };
6992
7064
  const i18nInitialized = await initI18n({
6993
- plugins: [
6994
- {
6995
- type: "postProcessor",
6996
- name: "removeTags",
6997
- process: function (value) {
6998
- return value.replace(/<\/?[^>]+(>|$)/g, "");
6999
- },
7000
- },
7001
- ],
7065
+ plugins: [removeTagsProcessor, sentenceCaseProcessor],
7002
7066
  options,
7003
7067
  // Fetch translations in every test or fetch once
7004
7068
  cache: true,