@decocms/apps 1.9.1 → 1.10.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.
@@ -21,3 +21,24 @@ export const formatPrice = (
21
21
  currency = "BRL",
22
22
  locale = "pt-BR",
23
23
  ) => (price != null && Number.isFinite(price) ? formatter(currency, locale).format(price) : null);
24
+
25
+ /**
26
+ * Formats a "min:max" range string (as VTEX/Shopify Intelligent Search
27
+ * facets emit) into a localised price range like "R$ 10,00 - R$ 50,00".
28
+ *
29
+ * Returns the original input untouched if either bound fails to parse,
30
+ * so this never crashes a filter UI on a bad facet value.
31
+ */
32
+ export const formatPriceRange = (
33
+ value: string,
34
+ currency = "BRL",
35
+ locale = "pt-BR",
36
+ separator = " - ",
37
+ ): string => {
38
+ if (typeof value !== "string" || !value.includes(":")) return value;
39
+ const [rawMin, rawMax] = value.split(":");
40
+ const min = formatPrice(Number(rawMin), currency, locale);
41
+ const max = formatPrice(Number(rawMax), currency, locale);
42
+ if (min == null || max == null) return value;
43
+ return `${min}${separator}${max}`;
44
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/apps",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "type": "module",
5
5
  "description": "Deco commerce apps for TanStack Start - Shopify, VTEX, commerce types, analytics utils",
6
6
  "exports": {