@wix/himalaya-cli 0.1852.0 → 0.1853.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.
Files changed (149) hide show
  1. package/dist/cli.mjs +95 -32
  2. package/guides/himi-json-output.md +8 -2
  3. package/guides/one-app-section-mappings.md +1 -1
  4. package/guides/one-app-to-himi-app.md +19 -6
  5. package/package.json +2 -2
  6. package/template-icons/bare-fashion.png +0 -0
  7. package/templates/bare-fashion/README.md +52 -0
  8. package/templates/bare-fashion/config.ts +474 -0
  9. package/templates/bare-fashion/dev/index.ts +16526 -0
  10. package/templates/bare-fashion/himalaya.content.json +70 -0
  11. package/templates/bare-fashion/himalaya.template.json +18 -0
  12. package/templates/bare-fashion/icon.png +0 -0
  13. package/templates/bare-fashion/platforms.json +3 -0
  14. package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
  15. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
  16. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
  17. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
  18. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
  19. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
  20. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
  21. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
  22. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
  23. package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  24. package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
  25. package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
  26. package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
  27. package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
  28. package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
  29. package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
  30. package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
  31. package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
  32. package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
  33. package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
  34. package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
  35. package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
  36. package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
  37. package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
  38. package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
  39. package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
  40. package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
  41. package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
  42. package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
  43. package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
  44. package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
  45. package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
  46. package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
  47. package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
  48. package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
  49. package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
  50. package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
  51. package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
  52. package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
  53. package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
  54. package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
  55. package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
  56. package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
  57. package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
  58. package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
  59. package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
  60. package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
  61. package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
  62. package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  63. package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
  64. package/templates/bare-fashion/tokens.json +348 -0
  65. package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
  66. package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
  67. package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
  68. package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
  69. package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
  70. package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
  71. package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
  72. package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
  73. package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
  74. package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
  75. package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
  76. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
  77. package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
  78. package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
  79. package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
  80. package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
  81. package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
  82. package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
  83. package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
  84. package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
  85. package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
  86. package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
  87. package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
  88. package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
  89. package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
  90. package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
  91. package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
  92. package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
  93. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
  94. package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
  95. package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
  96. package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
  97. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
  98. package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
  99. package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
  100. package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
  101. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
  102. package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
  103. package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
  104. package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
  105. package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
  106. package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
  107. package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
  108. package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
  109. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
  110. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
  111. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
  112. package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
  113. package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
  114. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
  115. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
  116. package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
  117. package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
  118. package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
  119. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
  120. package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
  121. package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
  122. package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
  123. package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
  124. package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
  125. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
  126. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
  127. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
  128. package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
  129. package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
  130. package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
  131. package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
  132. package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
  133. package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
  134. package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  135. package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
  136. package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
  137. package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
  138. package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
  139. package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
  140. package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
  141. package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  142. package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
  143. package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
  144. package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
  145. package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
  146. package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
  147. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
  148. package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
  149. package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
@@ -0,0 +1,529 @@
1
+ // ECMA-402 is NOT part of the Tier-5 floor. Measured across the engines we actually ship
2
+ // (engine-parity runners, #1367):
3
+ //
4
+ // engine typeof Intl
5
+ // V8 (web, Android WebView) object
6
+ // JSC (iOS, macOS) object
7
+ // QuickJS-ng (watchOS, Wear OS) **undefined**
8
+ //
9
+ // The wrist engine has no ECMA-402 at all — `grep -c Intl quickjs.c` → 0, and its maintainer
10
+ // ruled ICU out as too large (quickjs-ng#467). RFC 0051's per-surface projection does NOT subset
11
+ // destinations: a watch keeps every screen the phone has and only REMAPS which one an entry
12
+ // opens. So any screen in a watch/Wear-enabled app can execute on QuickJS, and a bare `Intl.*`
13
+ // there is a `ReferenceError`.
14
+ //
15
+ // That is not hypothetical. `himi-branded-lite-order.formatDate` called `new Intl.DateTimeFormat`
16
+ // unguarded and with no try/catch, which KILLS the screen on the wrist rather than degrading it.
17
+ // `himi-events-detail` had the softer version — a guarded `Intl.NumberFormat` whose catch left a
18
+ // ticket price rendering "25" where the phone shows "$25", i.e. a price that reads as a quantity.
19
+ //
20
+ // These helpers are the sanctioned way to format across the whole fleet: real ECMA-402 where it
21
+ // exists, a deterministic en-US-shaped fallback where it does not, and never a throw.
22
+
23
+ import { appLocale } from "./app-locale.js";
24
+
25
+ /** Is ECMA-402 actually present in THIS engine? Cheap, and safe in a realm without `Intl`. */
26
+ export function hasIntl(): boolean {
27
+ return typeof Intl !== "undefined";
28
+ }
29
+
30
+ const MONTHS_SHORT = [
31
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
32
+ ] as const;
33
+
34
+ function pad2(n: number): string {
35
+ return n < 10 ? `0${n}` : `${n}`;
36
+ }
37
+
38
+ /** `h:mm AM/PM`, matching what `timeStyle: "short"` renders for en-US. */
39
+ function clock12(d: Date): string {
40
+ const h = d.getHours();
41
+ const suffix = h < 12 ? "AM" : "PM";
42
+ const hour = h % 12 === 0 ? 12 : h % 12;
43
+ return `${hour}:${pad2(d.getMinutes())} ${suffix}`;
44
+ }
45
+
46
+ const WEEKDAYS_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] as const;
47
+
48
+ const MONTHS_LONG = [
49
+ "January", "February", "March", "April", "May", "June",
50
+ "July", "August", "September", "October", "November", "December",
51
+ ] as const;
52
+
53
+ /**
54
+ * A DateTimeFormat for `timeZone` when one is given and this engine knows it. An unknown or
55
+ * malformed IANA id is a RangeError in ECMA-402; these helpers never throw, so it degrades to
56
+ * the device zone rather than killing the screen. Without Intl there is no zone database at all,
57
+ * and the fallbacks below render in the device zone for the same reason.
58
+ *
59
+ * Formatters are memoised per (locale, zone, options): a management page formats several dates
60
+ * per row, and building a DateTimeFormat (or throwing on a bad zone) each time is not free on
61
+ * JSC or QuickJS. Only call it where `hasIntl()` holds — every caller does.
62
+ */
63
+ const FORMATTERS = new Map<string, Intl.DateTimeFormat>();
64
+ function dateFormat(locale: string, options: Intl.DateTimeFormatOptions, timeZone?: string): Intl.DateTimeFormat {
65
+ const key = `${locale}|${timeZone ?? ""}|${JSON.stringify(options)}`;
66
+ let formatter = FORMATTERS.get(key);
67
+ if (!formatter) {
68
+ if (hasIntl()) {
69
+ if (timeZone) {
70
+ try {
71
+ formatter = new Intl.DateTimeFormat(locale, { ...options, timeZone });
72
+ } catch {
73
+ /* unknown zone: device zone below, remembered under this key */
74
+ }
75
+ }
76
+ formatter ??= new Intl.DateTimeFormat(locale, options);
77
+ FORMATTERS.set(key, formatter);
78
+ }
79
+ }
80
+ return formatter as Intl.DateTimeFormat;
81
+ }
82
+
83
+ // The four shapes below are not invented — they are the option bags this corpus actually uses,
84
+ // counted across every bundle: "Jan 5, 2026" (33 sites), "Jan 5" (11), "Mon, Jan 5, 3:07 PM" (8)
85
+ // and "Jan 5, 3:07 PM" (4). Naming them means a conversion is a one-line swap rather than a
86
+ // judgement call about which fallback is close enough, and every one is diffed against real
87
+ // ECMA-402 in engine-intl-fallback.test.ts.
88
+
89
+ /** `{ month: "short", day: "numeric", year: "numeric" }` — "Jan 5, 2026". */
90
+ export function formatDateMedium(date: Date, locale = appLocale(), timeZone?: string): string {
91
+ if (hasIntl()) {
92
+ return dateFormat(locale, { month: "short", day: "numeric", year: "numeric" }, timeZone).format(date);
93
+ }
94
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
95
+ }
96
+
97
+ /** `{ month: "short", year: "numeric" }` — "Jul 2026", without parsing a localized day.
98
+ * Like the other date helpers, an engine without Intl keeps the documented en-US fallback. */
99
+ export function formatMonthYear(date: Date, locale = "en-US", timeZone?: string): string {
100
+ if (hasIntl()) return dateFormat(locale, { month: "short", year: "numeric" }, timeZone).format(date);
101
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getFullYear()}`;
102
+ }
103
+
104
+ /** `{ month: "short", day: "numeric" }` — "Jan 5". */
105
+ export function formatMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
106
+ if (hasIntl()) {
107
+ return dateFormat(locale, { month: "short", day: "numeric" }, timeZone).format(date);
108
+ }
109
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}`;
110
+ }
111
+
112
+ /** `{ month: "long", day: "numeric" }` — "January 5". */
113
+ export function formatMonthDayLong(date: Date, locale = appLocale(), timeZone?: string): string {
114
+ if (hasIntl()) {
115
+ return dateFormat(locale, { month: "long", day: "numeric" }, timeZone).format(date);
116
+ }
117
+ return `${MONTHS_LONG[date.getMonth()]} ${date.getDate()}`;
118
+ }
119
+
120
+ const WEEKDAYS_LONG = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] as const;
121
+
122
+ /** `{ weekday: "short" }` — "Mon". */
123
+ export function formatWeekdayShort(date: Date, locale = appLocale(), timeZone?: string): string {
124
+ if (hasIntl()) return dateFormat(locale, { weekday: "short" }, timeZone).format(date);
125
+ return WEEKDAYS_SHORT[date.getDay()]!;
126
+ }
127
+
128
+ /** `{ weekday: "short", month: "short", day: "numeric" }` — "Mon, Jan 5". */
129
+ export function formatWeekdayMonthDay(date: Date, locale = appLocale(), timeZone?: string): string {
130
+ if (hasIntl()) {
131
+ return dateFormat(locale, { weekday: "short", month: "short", day: "numeric" }, timeZone).format(date);
132
+ }
133
+ return `${WEEKDAYS_SHORT[date.getDay()]}, ${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}`;
134
+ }
135
+
136
+ /** `{ weekday: "long", month: "long", day: "numeric" }` — "Monday, January 5". */
137
+ export function formatWeekdayMonthDayLong(date: Date, locale = appLocale(), timeZone?: string): string {
138
+ if (hasIntl()) {
139
+ return dateFormat(locale, { weekday: "long", month: "long", day: "numeric" }, timeZone).format(date);
140
+ }
141
+ return `${WEEKDAYS_LONG[date.getDay()]}, ${MONTHS_LONG[date.getMonth()]} ${date.getDate()}`;
142
+ }
143
+
144
+ /** `{ weekday: "short", month: "short", day: "numeric", hour: "numeric", minute: "2-digit" }`
145
+ * — "Mon, Jan 5, 3:07 PM". */
146
+ export function formatWeekdayDateTime(date: Date, locale = appLocale(), timeZone?: string): string {
147
+ if (hasIntl()) {
148
+ return dateFormat(locale, {
149
+ weekday: "short", month: "short", day: "numeric", hour: "numeric", minute: "2-digit",
150
+ }, timeZone).format(date);
151
+ }
152
+ return `${WEEKDAYS_SHORT[date.getDay()]}, ${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${clock12(date)}`;
153
+ }
154
+
155
+ /** `{ month: "short", day: "numeric", hour: "numeric", minute: "2-digit" }` — "Jan 5, 3:07 PM". */
156
+ export function formatMonthDayTime(date: Date, locale = appLocale(), timeZone?: string): string {
157
+ if (hasIntl()) {
158
+ return dateFormat(locale, {
159
+ month: "short", day: "numeric", hour: "numeric", minute: "2-digit",
160
+ }, timeZone).format(date);
161
+ }
162
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${clock12(date)}`;
163
+ }
164
+
165
+ /**
166
+ * `dateStyle: "medium", timeStyle: "short"` — "Jan 5, 2026, 3:07 PM".
167
+ * Falls back to the same SHAPE (not a different one) so a screen does not visibly change
168
+ * character between a phone and a watch.
169
+ */
170
+ export function formatDateTimeMedium(date: Date, locale = appLocale()): string {
171
+ if (hasIntl()) {
172
+ return new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short" }).format(date);
173
+ }
174
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}, ${clock12(date)}`;
175
+ }
176
+
177
+ /**
178
+ * Currency, e.g. "$25.00". The fallback covers the symbol-prefix currencies these apps actually
179
+ * use and degrades to "CODE amount" for anything else — deliberately NOT a bare number, because
180
+ * that is the exact defect this exists to prevent (a price rendering as a quantity).
181
+ */
182
+ const CURRENCY_SYMBOL: Record<string, string> = {
183
+ USD: "$", EUR: "€", GBP: "£", ILS: "₪", JPY: "¥", CAD: "CA$", AUD: "A$",
184
+ };
185
+
186
+ /**
187
+ * ISO 4217 minor units, for the currencies that are NOT the default 2.
188
+ *
189
+ * Without this the fallback rendered every non-JPY currency with 2 decimals while Intl used the
190
+ * currency's natural precision — so a Bahraini price was "BHD 25.00" on the wrist and
191
+ * "BHD 25.000" on the phone. Formatting money differently per engine is the exact defect this
192
+ * helper exists to prevent, so the table is part of the contract, not a nicety.
193
+ */
194
+ const CURRENCY_DIGITS: Record<string, number> = {
195
+ // Zero-decimal
196
+ BIF: 0, CLP: 0, DJF: 0, GNF: 0, ISK: 0, JPY: 0, KMF: 0, KRW: 0, PYG: 0, RWF: 0,
197
+ UGX: 0, UYI: 0, VND: 0, VUV: 0, XAF: 0, XOF: 0, XPF: 0,
198
+ // Three-decimal
199
+ BHD: 3, IQD: 3, JOD: 3, KWD: 3, LYD: 3, OMR: 3, TND: 3,
200
+ // Four-decimal
201
+ CLF: 4, UYW: 4,
202
+ };
203
+
204
+ export function formatCurrency(
205
+ amount: number,
206
+ currency = "USD",
207
+ locale = appLocale(),
208
+ /** Omit for the currency's natural digits. Pass 0 to render a whole amount as "$25" rather
209
+ * than "$25.00" — Intl clamps the minimum down to match, so max<min does not throw here. */
210
+ maximumFractionDigits?: number,
211
+ ): string {
212
+ if (!Number.isFinite(amount)) return "";
213
+ if (hasIntl()) {
214
+ // The Intl branch CAN throw: `new Intl.NumberFormat(…, { currency })` raises a RangeError for
215
+ // any code that is not three letters ("US", "12", ""), and a currency arriving from payload
216
+ // data is exactly where that happens. This helper replaced call sites that had their own
217
+ // try/catch (himi-events-detail's tierPrice returned the raw amount), so without this the
218
+ // refactor would have REMOVED a safety net and turned a degraded price into a dead service on
219
+ // web, iOS and Android alike — worse than the wrist bug it was written to fix.
220
+ //
221
+ // Falling through to the fallback rather than rethrowing also degrades better than the code
222
+ // it replaced: that returned a bare number, this still carries the currency code.
223
+ try {
224
+ return new Intl.NumberFormat(locale, {
225
+ style: "currency",
226
+ currency,
227
+ ...(maximumFractionDigits != null ? { maximumFractionDigits } : {}),
228
+ }).format(amount);
229
+ } catch { /* malformed currency — use the engine-independent path below */ }
230
+ }
231
+ // A blank/whitespace currency would otherwise produce " 25.00" — a bare number, which is the
232
+ // very defect this helper exists to prevent. Fall back to the documented default rather than
233
+ // emitting an unlabelled amount. (Found by the "never a bare number" assertion, not by reading.)
234
+ const code = (currency || "").trim().toUpperCase() || "USD";
235
+ const symbol = CURRENCY_SYMBOL[code];
236
+ // The sign goes OUTSIDE the symbol: ECMA-402 renders -42.5 USD as "-$42.50", not "$-42.50".
237
+ // Caught by diffing this fallback against Intl rather than by reading it.
238
+ const sign = amount < 0 ? "-" : "";
239
+ const abs = Math.abs(amount);
240
+ const digits = maximumFractionDigits ?? CURRENCY_DIGITS[code] ?? 2;
241
+ const raw = abs.toFixed(digits);
242
+ // Same trap as formatNumber: `toFixed` goes EXPONENTIAL at >=1e21, and groupThousands would
243
+ // then comma up the exponent ("1e,+21"). No real price is that large, but emitting garbage is
244
+ // never the right answer to an unexpected input.
245
+ const fixed = raw.includes("e") || raw.includes("E") ? String(abs) : groupThousands(raw);
246
+ return symbol ? `${sign}${symbol}${fixed}` : `${sign}${code} ${fixed}`;
247
+ }
248
+
249
+ /** "1234567.89" → "1,234,567.89". `toLocaleString` cannot be used: on QuickJS it silently
250
+ * returns the UNGROUPED string rather than throwing, which is why the wrist showed "1234.5"
251
+ * where every other engine showed "1,234.5". */
252
+ function groupThousands(fixed: string): string {
253
+ const [whole, frac] = fixed.split(".");
254
+ const sign = whole.startsWith("-") ? "-" : "";
255
+ const digits = sign ? whole.slice(1) : whole;
256
+ let out = "";
257
+ for (let i = 0; i < digits.length; i++) {
258
+ if (i > 0 && (digits.length - i) % 3 === 0) out += ",";
259
+ out += digits[i];
260
+ }
261
+ return frac ? `${sign}${out}.${frac}` : `${sign}${out}`;
262
+ }
263
+
264
+ /**
265
+ * Plain grouped number, e.g. "1,234.5".
266
+ *
267
+ * Two things the first cut of this got wrong, both found by diffing against Intl over values
268
+ * chosen to be AWKWARD rather than tidy:
269
+ *
270
+ * • `Intl.NumberFormat` defaults to `maximumFractionDigits: 3`. Feeding it `2/3` gives
271
+ * "0.667"; a fallback built on `String(value)` gave "0.6666666666666666".
272
+ * • `String(value)` is EXPONENTIAL outside ~1e21 / 1e-7, and the grouping loop below happily
273
+ * inserted commas into the exponent — `1e21` came out as "1e,+21" and `1e-7` as "1,e-7".
274
+ * Garbage, and silently so, because nothing in the corpus's tidy test numbers reached it.
275
+ */
276
+ export function formatNumber(value: number, locale = appLocale()): string {
277
+ if (!Number.isFinite(value)) return "";
278
+ if (hasIntl()) return new Intl.NumberFormat(locale).format(value);
279
+ // `toFixed` itself returns exponential notation at >=1e21, so anything that big keeps the
280
+ // plain JS form rather than being mangled. Intl would expand it in full; a number that large
281
+ // is not a price or a count, and an honest "1e+21" beats a wrong "1e,+21".
282
+ const fixed = value.toFixed(3);
283
+ if (fixed.includes("e") || fixed.includes("E")) return String(value);
284
+ // Trailing zeros go, so an integer stays "1,000" instead of "1,000.000".
285
+ const trimmed = fixed.includes(".") ? fixed.replace(/0+$/, "").replace(/\.$/, "") : fixed;
286
+ return groupThousands(trimmed);
287
+ }
288
+
289
+ /** Strip combining marks so "Ändern" folds to "andern". `String.prototype.normalize` is
290
+ * ECMA-262, NOT ECMA-402 — which is exactly why it is usable here: it exists on the engine that
291
+ * has no `Intl`. The range is the Unicode combining-diacritical block, written as an explicit
292
+ * range rather than a `\p{M}` property escape so no engine needs RegExp property support. */
293
+ function foldDiacritics(s: string): string {
294
+ try {
295
+ return s.normalize("NFD").replace(/[̀-ͯ]/g, "");
296
+ } catch {
297
+ return s; // no normalize (should not happen) — degrade to the un-folded form
298
+ }
299
+ }
300
+
301
+ /**
302
+ * Locale-aware string ordering for SORTS.
303
+ *
304
+ * `localeCompare` is the trap here, because it does not throw where ECMA-402 is missing — it
305
+ * silently falls back to codepoint order. Measured on the engines we ship, that is not a subtle
306
+ * difference: for a realistic product list the wrist produced
307
+ *
308
+ * Banana, Zoë, andern, apple, cherry, Ändern, Über, éclair ← raw codepoint (QuickJS-ng)
309
+ * andern, Ändern, apple, Banana, cherry, éclair, Über, Zoë ← ICU (V8/JSC)
310
+ *
311
+ * i.e. a list that looks shuffled rather than sorted, with no error anywhere to explain it.
312
+ *
313
+ * The phone path is UNCHANGED — it is still `Intl.Collator`, so nothing about existing ordering
314
+ * moves. Only the engine that lacked ECMA-402 changes, and it changes from codepoint order to a
315
+ * case-folded, diacritic-folded comparison that agreed with ICU on 576/576 pairs of the probe
316
+ * corpus (accents included). This is deliberately NOT "pick one algorithm for every engine":
317
+ * that framing would have traded a wrist bug for a phone regression, and it is unnecessary.
318
+ */
319
+ export function compareText(a: string, b: string, locale = "en"): number {
320
+ if (hasIntl()) return new Intl.Collator(locale).compare(a, b);
321
+ const fa = foldDiacritics(a.toLowerCase());
322
+ const fb = foldDiacritics(b.toLowerCase());
323
+ if (fa < fb) return -1;
324
+ if (fa > fb) return 1;
325
+ // Same letters ignoring case and accents — fall back through the finer distinctions so the
326
+ // order is TOTAL (a comparator that returns 0 for distinct strings makes a sort unstable).
327
+ const ca = a.toLowerCase(), cb = b.toLowerCase();
328
+ if (ca < cb) return -1;
329
+ if (ca > cb) return 1;
330
+ if (a === b) return 0;
331
+ // en-US collation puts lowercase before uppercase for the same letter, which is the OPPOSITE
332
+ // of codepoint order — hence the inversion rather than a plain comparison.
333
+ return a > b ? -1 : 1;
334
+ }
335
+
336
+ /**
337
+ * Ordering for machine timestamps (ISO-8601, RFC-3339) and other fixed-format ASCII keys.
338
+ *
339
+ * Exists to keep `localeCompare` away from them. Sorting `"2026-01-05T15:07:00Z"` through a
340
+ * COLLATOR is the wrong tool — collation carries locale rules a timestamp has no use for, and on
341
+ * an engine without ECMA-402 it silently becomes codepoint order anyway. Measured: for ISO
342
+ * strings, plain comparison and `localeCompare` agree on 36/36 pairs, so this is a no-op on
343
+ * every engine AND removes the engine-variance question entirely.
344
+ */
345
+ export function compareIso(a: string, b: string): number {
346
+ return a < b ? -1 : a > b ? 1 : 0;
347
+ }
348
+
349
+ const MONTH_INDEX: Record<string, number> = {
350
+ jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5,
351
+ jul: 6, aug: 7, sep: 8, oct: 9, nov: 10, dec: 11,
352
+ };
353
+
354
+ /**
355
+ * Epoch-ms for a date string that may be ISO-8601 **or** RFC-822/2822 ("Sun, 02 Aug 2026"), the
356
+ * shape RSS feeds use. `NaN` when it is neither.
357
+ *
358
+ * Hand-parsed rather than handed to `Date.parse` because `Date.parse` is only SPECIFIED for the
359
+ * ISO format — everything else is implementation-defined, which is precisely the kind of
360
+ * per-engine variance this module exists to remove.
361
+ */
362
+ export function parseDateish(value: string): number {
363
+ if (!value) return NaN;
364
+ // ISO / RFC-3339 — `Date` parses this by spec on every engine.
365
+ if (/^\d{4}-\d{2}-\d{2}/.test(value)) return new Date(value).getTime();
366
+ // RFC-822/2822: "[Ddd, ]DD Mon YYYY[ HH:MM[:SS]]"
367
+ const m = value.match(/(\d{1,2})\s+([A-Za-z]{3})[a-z]*\s+(\d{4})(?:\s+(\d{2}):(\d{2})(?::(\d{2}))?)?/);
368
+ if (!m) return NaN;
369
+ const month = MONTH_INDEX[m[2].toLowerCase()];
370
+ if (month === undefined) return NaN;
371
+ return Date.UTC(Number(m[3]), month, Number(m[1]), Number(m[4] ?? 0), Number(m[5] ?? 0), Number(m[6] ?? 0));
372
+ }
373
+
374
+ /**
375
+ * Chronological ordering for date strings — ASCENDING (oldest first); negate for newest-first.
376
+ *
377
+ * This exists because comparing RFC-822 dates as STRINGS sorts by weekday name. Measured on the
378
+ * podcast corpus, a "latest episodes" list built that way rendered
379
+ *
380
+ * Wed, 01 Jan 2025 ← shown FIRST
381
+ * Tue, 21 Jul 2026
382
+ * …
383
+ * Fri, 15 Aug 2026 ← the newest episode, shown LAST
384
+ *
385
+ * and it was wrong on EVERY engine, not just the one missing ECMA-402 — a plain product bug that
386
+ * the engine work happened to surface. Unparseable values sort last rather than throwing, so one
387
+ * malformed feed entry cannot take the screen down.
388
+ */
389
+ export function compareDate(a: string, b: string): number {
390
+ const ta = parseDateish(a);
391
+ const tb = parseDateish(b);
392
+ const aBad = Number.isNaN(ta);
393
+ const bBad = Number.isNaN(tb);
394
+ if (aBad && bBad) return compareIso(a, b); // both unparseable — arbitrary but TOTAL
395
+ if (aBad) return 1;
396
+ if (bBad) return -1;
397
+ return ta - tb;
398
+ }
399
+
400
+ /**
401
+ * Newest-first, which is what every call site here actually wants.
402
+ *
403
+ * A separate function rather than asking callers to write `-compareDate(a, b)`, because negating
404
+ * also flips the unparseable-values-last rule to unparseable-values-FIRST — a malformed feed entry
405
+ * would head the "latest episodes" list. My own test caught that on the negation idiom, which is
406
+ * exactly the footgun worth deleting rather than documenting.
407
+ */
408
+ export function compareDateDesc(a: string, b: string): number {
409
+ const ta = parseDateish(a);
410
+ const tb = parseDateish(b);
411
+ const aBad = Number.isNaN(ta);
412
+ const bBad = Number.isNaN(tb);
413
+ if (aBad && bBad) return compareIso(a, b);
414
+ if (aBad) return 1; // unparseable stays LAST in this direction too
415
+ if (bBad) return -1;
416
+ return tb - ta;
417
+ }
418
+
419
+ // --- [branded-lite-qa] #3079: one pattern per fact ---------------------------------------
420
+ //
421
+ // Before these existed, four screens formatted the same money four ways — Shop "69.00 ₪" (Wix's
422
+ // pre-formatted string), Services "₪70" (0 decimals), Menu "₪32.00", Plans "$24" — and two
423
+ // screens formatted the same clock two ways (Events "9:00 PM-11:00 PM", Reserve "20:00").
424
+ // Customers read that as sloppiness, and a whole "₪70" beside "₪69.50" reads as a different
425
+ // kind of number. So: one money pattern, one clock, one range.
426
+
427
+ // Money uses `formatCurrency(amount, currency)` — English unless the app pins another language, see app-locale — the currency's NATURAL decimals
428
+ // ("₪70.00", "¥500") — for Shop, Menu and every other price. The one exception is a Bookings
429
+ // SERVICE price (`_shared/wix-service-price.ts`): it drops the cents of a whole amount ("₪70",
430
+ // "₪69.50"), the format the redesigned service screen and services list were approved with. It
431
+ // must read the same on every screen that shows a service (the list, the service screen, the
432
+ // time screen, Home, the agenda); do not put those back on natural decimals one screen at a time.
433
+
434
+ const KNOWN_SYMBOLS = new Set(Object.values(CURRENCY_SYMBOL));
435
+
436
+ /** Wix hands some prices over PRE-formatted in the site's regional style — "69.00 ₪" with the
437
+ * symbol trailing, often wrapped in bidi marks. Reorder those to the house pattern ("₪69.00") so
438
+ * they match every price we format ourselves. Only an en-shaped number ("69.00", "1,234.50") with
439
+ * a known trailing symbol is reordered: a comma-decimal or space-grouped string ("69,00 €",
440
+ * "1 234,56 €") is kept as Wix wrote it, because half-converting it would be worse. Anything else
441
+ * ("Market price") is returned trimmed. The store SDK's product price applies the same rule. */
442
+ export function normalizeFormattedPrice(formatted: string): string {
443
+ const raw = (formatted || "").replace(/[‎‏]/g, "").trim();
444
+ const m = /^(-?)(\d{1,3}(?:,\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?)[\s  ]*(\S+)$/.exec(raw);
445
+ if (!m || !KNOWN_SYMBOLS.has(m[3])) return raw;
446
+ return `${m[1]}${m[3]}${m[2]}`;
447
+ }
448
+
449
+ function clockParts(d: Date, locale: string, timeZone?: string): { time: string; meridiem: string } {
450
+ const full = hasIntl()
451
+ ? dateFormat(locale, { hour: "numeric", minute: "2-digit", hour12: true }, timeZone).format(d)
452
+ : clock12(d);
453
+ // ICU puts a narrow no-break space before the meridiem; normalize so callers can split on it.
454
+ const clean = full.replace(/[  ]/g, " ");
455
+ const m = /^(.*?)\s*([AP]\.?\s?M\.?)$/i.exec(clean);
456
+ return m ? { time: m[1], meridiem: m[2] } : { time: clean, meridiem: "" };
457
+ }
458
+
459
+ /** "8:00 PM" — the one clock every customer screen uses (12-hour, en-US shape). */
460
+ export function formatClock(date: Date, locale = appLocale(), timeZone?: string): string {
461
+ const { time, meridiem } = clockParts(date, locale, timeZone);
462
+ return meridiem ? `${time} ${meridiem}` : time;
463
+ }
464
+
465
+ /** "10:00 – 11:15 AM" when both ends share the meridiem, "11:30 AM – 12:45 PM" otherwise. The meridiem is whatever the
466
+ * locale writes (`AM`, `p. m.`), so it is compared as a whole, never as the last word of the text. */
467
+ export function formatClockRange(start: Date, end: Date, locale = appLocale(), timeZone?: string): string {
468
+ const a = clockParts(start, locale, timeZone), b = clockParts(end, locale, timeZone);
469
+ if (a.meridiem && a.meridiem === b.meridiem) return `${a.time} – ${b.time} ${b.meridiem}`;
470
+ return `${formatClock(start, locale, timeZone)} – ${formatClock(end, locale, timeZone)}`;
471
+ }
472
+
473
+ /** Is this ISO instant before `now`? A missing or unparseable value is NOT past — "no expiry"
474
+ * must never classify an offer as expired. */
475
+ export function isPastDate(iso: string | undefined | null, now: number = Date.now()): boolean {
476
+ if (!iso) return false;
477
+ const t = Date.parse(iso);
478
+ return !Number.isNaN(t) && t < now;
479
+ }
480
+
481
+ /** The calendar day `date` falls on in `timeZone` (device zone when absent, unknown, or when
482
+ * the engine has no Intl), as `YYYY-MM-DD`. For "is this today / this year" comparisons. */
483
+ export function calendarDay(date: Date, timeZone?: string): string {
484
+ if (hasIntl()) {
485
+ const parts = dateFormat("en-CA", { year: "numeric", month: "2-digit", day: "2-digit" }, timeZone).formatToParts(date);
486
+ const get = (type: string) => parts.find((p) => p.type === type)?.value ?? "";
487
+ return `${get("year")}-${get("month")}-${get("day")}`;
488
+ }
489
+ return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`;
490
+ }
491
+
492
+ /**
493
+ * [timeZone]'s offset from UTC in ms at instant [at] (Asia/Jerusalem in winter: 7_200_000), or NaN
494
+ * where it cannot be known — no ECMA-402 (the wrist engines) or a zone this engine does not know.
495
+ * Callers fall back to the device zone on NaN, as the formatters above do.
496
+ */
497
+ export function zoneOffsetAt(at: number, timeZone: string): number {
498
+ if (hasIntl() && Number.isFinite(at)) {
499
+ try {
500
+ const parts = new Intl.DateTimeFormat("en-US", {
501
+ timeZone, hourCycle: "h23", year: "numeric", month: "2-digit", day: "2-digit",
502
+ hour: "2-digit", minute: "2-digit", second: "2-digit",
503
+ }).formatToParts(new Date(at));
504
+ const n = (type: string) => Number(parts.find((p) => p.type === type)?.value);
505
+ return Date.UTC(n("year"), n("month") - 1, n("day"), n("hour") % 24, n("minute"), n("second")) - at;
506
+ } catch {
507
+ /* a zone this engine does not know: NaN below */
508
+ }
509
+ }
510
+ return NaN;
511
+ }
512
+
513
+ /** Long zone label plus its short offset, e.g. "Israel Standard Time (GMT+2)". An engine
514
+ * without ECMA-402 has no zone database, so callers omit the supplementary label there. */
515
+ export function formatTimeZoneLabel(date: Date, timeZone: string, locale = "en"): string {
516
+ if (hasIntl()) {
517
+ if (!timeZone) return "";
518
+ try {
519
+ const parts = new Intl.DateTimeFormat(locale, { timeZone, timeZoneName: "long" }).formatToParts(date);
520
+ const name = parts.find((part) => part.type === "timeZoneName")?.value || timeZone;
521
+ const offset = new Intl.DateTimeFormat(locale, { timeZone, timeZoneName: "shortOffset" })
522
+ .formatToParts(date).find((part) => part.type === "timeZoneName")?.value;
523
+ return offset ? `${name} (${offset.replace(/:00$/, "")})` : name;
524
+ } catch {
525
+ return timeZone;
526
+ }
527
+ }
528
+ return "";
529
+ }