@eifi1/ui-kit 0.21.0 → 0.23.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 (320) hide show
  1. package/README.md +42 -25
  2. package/dist/chart.d.ts +19 -14
  3. package/dist/components/account-chips.d.ts +10 -3
  4. package/dist/components/account-chips.js +5 -2
  5. package/dist/components/account-chips.js.map +1 -1
  6. package/dist/components/account-settings.d.ts +33 -2
  7. package/dist/components/account-settings.js +43 -21
  8. package/dist/components/account-settings.js.map +1 -1
  9. package/dist/components/amount-input.d.ts +53 -14
  10. package/dist/components/amount-input.js +17 -28
  11. package/dist/components/amount-input.js.map +1 -1
  12. package/dist/components/autocomplete.d.ts +29 -0
  13. package/dist/components/autocomplete.js +134 -104
  14. package/dist/components/autocomplete.js.map +1 -1
  15. package/dist/components/button-group.d.ts +19 -14
  16. package/dist/components/calculator.d.ts +19 -14
  17. package/dist/components/checkbox-group.d.ts +104 -0
  18. package/dist/components/checkbox-group.js +111 -0
  19. package/dist/components/checkbox-group.js.map +1 -0
  20. package/dist/components/checkbox.d.ts +19 -0
  21. package/dist/components/checkbox.js +30 -7
  22. package/dist/components/checkbox.js.map +1 -1
  23. package/dist/components/chip.d.ts +18 -0
  24. package/dist/components/chip.js +47 -10
  25. package/dist/components/chip.js.map +1 -1
  26. package/dist/components/column-mapper.d.ts +182 -0
  27. package/dist/components/column-mapper.js +375 -0
  28. package/dist/components/column-mapper.js.map +1 -0
  29. package/dist/components/combobox-core.d.ts +39 -2
  30. package/dist/components/combobox-core.js +29 -6
  31. package/dist/components/combobox-core.js.map +1 -1
  32. package/dist/components/combobox.d.ts +91 -2
  33. package/dist/components/combobox.js +454 -308
  34. package/dist/components/combobox.js.map +1 -1
  35. package/dist/components/confirm-dialog.d.ts +69 -161
  36. package/dist/components/confirm-dialog.js +7 -8
  37. package/dist/components/confirm-dialog.js.map +1 -1
  38. package/dist/components/copy-button.d.ts +16 -11
  39. package/dist/components/country-select.d.ts +167 -0
  40. package/dist/components/country-select.js +293 -0
  41. package/dist/components/country-select.js.map +1 -0
  42. package/dist/components/currency-select.d.ts +17 -1
  43. package/dist/components/currency-select.js +56 -23
  44. package/dist/components/currency-select.js.map +1 -1
  45. package/dist/components/danger-confirm.d.ts +69 -166
  46. package/dist/components/danger-confirm.js +144 -50
  47. package/dist/components/danger-confirm.js.map +1 -1
  48. package/dist/components/data-table-cells.d.ts +1 -2
  49. package/dist/components/data-table-filter-popover.d.ts +1 -2
  50. package/dist/components/data-table-filters.d.ts +1 -2
  51. package/dist/components/data-table-labels.d.ts +4 -97
  52. package/dist/components/data-table-labels.js +9 -1
  53. package/dist/components/data-table-labels.js.map +1 -1
  54. package/dist/components/data-table-pagination.d.ts +3 -1
  55. package/dist/components/data-table.d.ts +1 -2
  56. package/dist/components/data-table.js +98 -3
  57. package/dist/components/data-table.js.map +1 -1
  58. package/dist/components/date-picker.d.ts +66 -5
  59. package/dist/components/date-picker.js +378 -66
  60. package/dist/components/date-picker.js.map +1 -1
  61. package/dist/components/entity-combobox.d.ts +42 -1
  62. package/dist/components/entity-combobox.js +154 -113
  63. package/dist/components/entity-combobox.js.map +1 -1
  64. package/dist/components/facing-pair.d.ts +19 -14
  65. package/dist/components/field-parts.d.ts +224 -0
  66. package/dist/components/field-parts.js +156 -0
  67. package/dist/components/field-parts.js.map +1 -0
  68. package/dist/components/field-strip.d.ts +105 -0
  69. package/dist/components/field-strip.js +46 -0
  70. package/dist/components/field-strip.js.map +1 -0
  71. package/dist/components/file-button.d.ts +19 -14
  72. package/dist/components/file-button.js +13 -3
  73. package/dist/components/file-button.js.map +1 -1
  74. package/dist/components/file-dropzone.d.ts +41 -15
  75. package/dist/components/file-dropzone.js +57 -34
  76. package/dist/components/file-dropzone.js.map +1 -1
  77. package/dist/components/form-actions.d.ts +18 -13
  78. package/dist/components/form-actions.js +69 -5
  79. package/dist/components/form-actions.js.map +1 -1
  80. package/dist/components/iban-input.d.ts +69 -0
  81. package/dist/components/iban-input.js +125 -0
  82. package/dist/components/iban-input.js.map +1 -0
  83. package/dist/components/icon-picker.d.ts +21 -2
  84. package/dist/components/icon-picker.js +19 -4
  85. package/dist/components/icon-picker.js.map +1 -1
  86. package/dist/components/inline-edit-field.d.ts +167 -0
  87. package/dist/components/inline-edit-field.js +293 -0
  88. package/dist/components/inline-edit-field.js.map +1 -0
  89. package/dist/components/language-select.d.ts +130 -0
  90. package/dist/components/language-select.js +18 -0
  91. package/dist/components/language-select.js.map +1 -0
  92. package/dist/components/line-items.d.ts +25 -3
  93. package/dist/components/line-items.js +55 -46
  94. package/dist/components/line-items.js.map +1 -1
  95. package/dist/components/list.d.ts +25 -0
  96. package/dist/components/list.js +16 -5
  97. package/dist/components/list.js.map +1 -1
  98. package/dist/components/money-field.d.ts +32 -14
  99. package/dist/components/money-field.js.map +1 -1
  100. package/dist/components/month-picker.d.ts +52 -4
  101. package/dist/components/month-picker.js +291 -86
  102. package/dist/components/month-picker.js.map +1 -1
  103. package/dist/components/multi-entity-combobox.d.ts +26 -1
  104. package/dist/components/multi-entity-combobox.js +143 -102
  105. package/dist/components/multi-entity-combobox.js.map +1 -1
  106. package/dist/components/multi-select.d.ts +8 -1
  107. package/dist/components/multi-select.js +9 -4
  108. package/dist/components/multi-select.js.map +1 -1
  109. package/dist/components/number-field.d.ts +34 -19
  110. package/dist/components/number-field.js +6 -20
  111. package/dist/components/number-field.js.map +1 -1
  112. package/dist/components/number-input.d.ts +79 -19
  113. package/dist/components/number-input.js +90 -38
  114. package/dist/components/number-input.js.map +1 -1
  115. package/dist/components/numpad-sheet.d.ts +19 -14
  116. package/dist/components/one-time-code-input.d.ts +100 -0
  117. package/dist/components/one-time-code-input.js +137 -0
  118. package/dist/components/one-time-code-input.js.map +1 -0
  119. package/dist/components/phone-input.d.ts +69 -0
  120. package/dist/components/phone-input.js +171 -0
  121. package/dist/components/phone-input.js.map +1 -0
  122. package/dist/components/reauth-dialog.d.ts +2 -2
  123. package/dist/components/reauth-dialog.js +6 -8
  124. package/dist/components/reauth-dialog.js.map +1 -1
  125. package/dist/components/series-chart.d.ts +19 -14
  126. package/dist/components/settings-fields.d.ts +19 -14
  127. package/dist/components/share-card.d.ts +16 -11
  128. package/dist/components/sign-chip.d.ts +66 -0
  129. package/dist/components/sign-chip.js +39 -0
  130. package/dist/components/sign-chip.js.map +1 -0
  131. package/dist/components/swatch-picker.d.ts +43 -2
  132. package/dist/components/swatch-picker.js +80 -32
  133. package/dist/components/swatch-picker.js.map +1 -1
  134. package/dist/components/switch.d.ts +19 -0
  135. package/dist/components/switch.js +24 -6
  136. package/dist/components/switch.js.map +1 -1
  137. package/dist/components/text-link.d.ts +18 -13
  138. package/dist/components/tile-radio.d.ts +88 -13
  139. package/dist/components/tile-radio.js +28 -11
  140. package/dist/components/tile-radio.js.map +1 -1
  141. package/dist/components/time-input.d.ts +24 -15
  142. package/dist/components/time-input.js.map +1 -1
  143. package/dist/components/toggle-group.d.ts +47 -1
  144. package/dist/components/toggle-group.js +110 -69
  145. package/dist/components/toggle-group.js.map +1 -1
  146. package/dist/components/trigger-aria.d.ts +3 -0
  147. package/dist/components/trigger-aria.js +3 -1
  148. package/dist/components/trigger-aria.js.map +1 -1
  149. package/dist/components/ui.d.ts +16 -11
  150. package/dist/components/ui.js +284 -88
  151. package/dist/components/ui.js.map +1 -1
  152. package/dist/components/use-table-state.d.ts +1 -2
  153. package/dist/{data-table-3mi2R3so.d.ts → data-table-labels-B7OdnM0S.d.ts} +140 -3
  154. package/dist/data-table.d.ts +1 -2
  155. package/dist/data-table.js +2 -1
  156. package/dist/data-table.js.map +1 -1
  157. package/dist/feedback/feedback-attachment.d.ts +1 -1
  158. package/dist/feedback/feedback-attachment.js +348 -41
  159. package/dist/feedback/feedback-attachment.js.map +1 -1
  160. package/dist/feedback/feedback-dialog.d.ts +1 -1
  161. package/dist/feedback/feedback-dialog.js.map +1 -1
  162. package/dist/feedback/feedback-inbox.d.ts +3 -2
  163. package/dist/feedback/feedback-inbox.js.map +1 -1
  164. package/dist/feedback/feedback-thread.d.ts +68 -253
  165. package/dist/feedback/feedback-thread.js +46 -10
  166. package/dist/feedback/feedback-thread.js.map +1 -1
  167. package/dist/{kit-labels-D1J2_jyD.d.ts → feedback-BxeQVzwq.d.ts} +1206 -20
  168. package/dist/{feedback-attachment-WFiXJ8We.d.ts → feedback-attachment-fGAzZPf0.d.ts} +178 -11
  169. package/dist/feedback.d.ts +66 -2
  170. package/dist/hooks/use-file-drop.d.ts +19 -14
  171. package/dist/i18n/defaults.d.ts +19 -14
  172. package/dist/i18n/defaults.js +19 -2
  173. package/dist/i18n/defaults.js.map +1 -1
  174. package/dist/i18n/german.d.ts +19 -14
  175. package/dist/i18n/german.js +84 -5
  176. package/dist/i18n/german.js.map +1 -1
  177. package/dist/i18n/kit-labels.d.ts +15 -10
  178. package/dist/i18n/kit-labels.js +8 -2
  179. package/dist/i18n/kit-labels.js.map +1 -1
  180. package/dist/i18n/languages.d.ts +19 -14
  181. package/dist/i18n/locales/de-CH.d.ts +19 -14
  182. package/dist/i18n/locales/en.d.ts +19 -14
  183. package/dist/i18n/locales/en.js +16 -0
  184. package/dist/i18n/locales/en.js.map +1 -1
  185. package/dist/i18n/locales/es.d.ts +19 -14
  186. package/dist/i18n/locales/es.js +83 -5
  187. package/dist/i18n/locales/es.js.map +1 -1
  188. package/dist/i18n/locales/fr.d.ts +19 -14
  189. package/dist/i18n/locales/fr.js +82 -5
  190. package/dist/i18n/locales/fr.js.map +1 -1
  191. package/dist/i18n/locales/hu.d.ts +19 -14
  192. package/dist/i18n/locales/hu.js +85 -5
  193. package/dist/i18n/locales/hu.js.map +1 -1
  194. package/dist/i18n/locales/it.d.ts +19 -14
  195. package/dist/i18n/locales/it.js +84 -5
  196. package/dist/i18n/locales/it.js.map +1 -1
  197. package/dist/i18n/locales/zh.d.ts +19 -14
  198. package/dist/i18n/locales/zh.js +80 -5
  199. package/dist/i18n/locales/zh.js.map +1 -1
  200. package/dist/i18n/review.d.ts +19 -14
  201. package/dist/i18n/review.js +27 -1
  202. package/dist/i18n/review.js.map +1 -1
  203. package/dist/index.d.ts +21 -10
  204. package/dist/index.js +73 -2
  205. package/dist/index.js.map +1 -1
  206. package/dist/lib/column-mapping.d.ts +81 -0
  207. package/dist/lib/column-mapping.js +108 -0
  208. package/dist/lib/column-mapping.js.map +1 -0
  209. package/dist/lib/countries.d.ts +43 -0
  210. package/dist/lib/countries.js +39 -0
  211. package/dist/lib/countries.js.map +1 -0
  212. package/dist/lib/decimal-marks.d.ts +46 -0
  213. package/dist/lib/decimal-marks.js +40 -0
  214. package/dist/lib/decimal-marks.js.map +1 -0
  215. package/dist/lib/iban.d.ts +98 -0
  216. package/dist/lib/iban.js +154 -0
  217. package/dist/lib/iban.js.map +1 -0
  218. package/dist/lib/isin.d.ts +30 -0
  219. package/dist/lib/isin.js +36 -0
  220. package/dist/lib/isin.js.map +1 -0
  221. package/dist/lib/phone.d.ts +69 -0
  222. package/dist/lib/phone.js +121 -0
  223. package/dist/lib/phone.js.map +1 -0
  224. package/dist/lib/table-text.d.ts +109 -1
  225. package/dist/lib/table-text.js +122 -1
  226. package/dist/lib/table-text.js.map +1 -1
  227. package/dist/rhf/fields.d.ts +233 -18
  228. package/dist/rhf/fields.js +456 -3
  229. package/dist/rhf/fields.js.map +1 -1
  230. package/dist/rhf/form.d.ts +19 -14
  231. package/dist/rhf.d.ts +22 -15
  232. package/dist/rhf.js.map +1 -1
  233. package/dist/shell/app-shell.d.ts +18 -13
  234. package/dist/shell/top-bar-brand.d.ts +19 -14
  235. package/dist/shell/topbar-action-menu.d.ts +36 -3
  236. package/dist/shell/topbar-action-menu.js +74 -33
  237. package/dist/shell/topbar-action-menu.js.map +1 -1
  238. package/dist/shell.d.ts +18 -13
  239. package/dist/table-text.d.ts +1 -1
  240. package/dist/tour/tour.js +20 -24
  241. package/dist/tour/tour.js.map +1 -1
  242. package/dist/wizard/stepper-nav.d.ts +49 -16
  243. package/dist/wizard/stepper-nav.js +4 -0
  244. package/dist/wizard/stepper-nav.js.map +1 -1
  245. package/dist/wizard.d.ts +19 -14
  246. package/package.json +1 -1
  247. package/src/components/account-chips.tsx +17 -3
  248. package/src/components/account-settings.tsx +92 -26
  249. package/src/components/amount-input.tsx +68 -56
  250. package/src/components/autocomplete.tsx +198 -114
  251. package/src/components/checkbox-group.tsx +229 -0
  252. package/src/components/checkbox.tsx +72 -8
  253. package/src/components/chip.tsx +80 -10
  254. package/src/components/column-mapper.tsx +666 -0
  255. package/src/components/combobox-core.tsx +82 -9
  256. package/src/components/combobox.tsx +661 -340
  257. package/src/components/confirm-dialog.tsx +12 -8
  258. package/src/components/country-select.tsx +556 -0
  259. package/src/components/currency-select.tsx +109 -33
  260. package/src/components/danger-confirm.tsx +429 -82
  261. package/src/components/data-table-labels.ts +16 -1
  262. package/src/components/data-table.tsx +175 -6
  263. package/src/components/date-picker.tsx +595 -71
  264. package/src/components/entity-combobox.tsx +235 -124
  265. package/src/components/field-parts.tsx +403 -0
  266. package/src/components/field-strip.tsx +149 -0
  267. package/src/components/file-button.tsx +36 -3
  268. package/src/components/file-dropzone.tsx +106 -38
  269. package/src/components/form-actions.tsx +147 -6
  270. package/src/components/iban-input.tsx +231 -0
  271. package/src/components/icon-picker.tsx +47 -6
  272. package/src/components/inline-edit-field.tsx +533 -0
  273. package/src/components/language-select.tsx +78 -0
  274. package/src/components/line-items.tsx +35 -2
  275. package/src/components/list.tsx +55 -6
  276. package/src/components/money-field.tsx +13 -0
  277. package/src/components/month-picker.tsx +400 -63
  278. package/src/components/multi-entity-combobox.tsx +207 -120
  279. package/src/components/multi-select.tsx +80 -58
  280. package/src/components/number-field.tsx +28 -46
  281. package/src/components/number-input.tsx +210 -43
  282. package/src/components/one-time-code-input.tsx +288 -0
  283. package/src/components/phone-input.tsx +299 -0
  284. package/src/components/reauth-dialog.tsx +17 -18
  285. package/src/components/sign-chip.tsx +103 -0
  286. package/src/components/swatch-picker.tsx +143 -31
  287. package/src/components/switch.tsx +58 -7
  288. package/src/components/tile-radio.tsx +145 -29
  289. package/src/components/time-input.tsx +8 -1
  290. package/src/components/toggle-group.tsx +206 -73
  291. package/src/components/trigger-aria.ts +5 -0
  292. package/src/components/ui.tsx +479 -138
  293. package/src/data-table.ts +2 -1
  294. package/src/feedback/feedback-attachment.tsx +597 -46
  295. package/src/feedback/feedback-dialog.tsx +9 -3
  296. package/src/feedback/feedback-inbox.tsx +3 -2
  297. package/src/feedback/feedback-thread.tsx +113 -9
  298. package/src/i18n/defaults.ts +18 -1
  299. package/src/i18n/german.ts +89 -0
  300. package/src/i18n/kit-labels.tsx +82 -2
  301. package/src/i18n/locales/en.ts +36 -4
  302. package/src/i18n/locales/es.ts +87 -0
  303. package/src/i18n/locales/fr.ts +87 -0
  304. package/src/i18n/locales/hu.ts +83 -0
  305. package/src/i18n/locales/it.ts +88 -0
  306. package/src/i18n/locales/zh.ts +76 -0
  307. package/src/i18n/review.ts +26 -0
  308. package/src/index.ts +71 -3
  309. package/src/lib/column-mapping.ts +234 -0
  310. package/src/lib/countries.ts +91 -0
  311. package/src/lib/decimal-marks.ts +99 -0
  312. package/src/lib/iban.ts +171 -0
  313. package/src/lib/isin.ts +62 -0
  314. package/src/lib/phone.ts +211 -0
  315. package/src/lib/table-text.ts +271 -0
  316. package/src/rhf/fields.tsx +860 -9
  317. package/src/rhf.ts +3 -1
  318. package/src/shell/topbar-action-menu.tsx +134 -38
  319. package/src/tour/tour.tsx +66 -28
  320. package/src/wizard/stepper-nav.tsx +35 -1
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The locale's decimal mark, as far as a field can type it: "," or "." (kastlan 40).
3
+ * A mark outside those two (Arabic's "٫") is not one {@link sanitizeLive} lets
4
+ * through, so those locales keep the dot rather than get a field that eats the key it
5
+ * shows. `undefined` is the runtime's own locale, which is what `Intl` reads it as.
6
+ */
7
+ declare function decimalMark(locale: string | undefined): "," | ".";
8
+ /**
9
+ * Which typed mark is the decimal one (keksdose G1). {@link sanitizeLive} folds every
10
+ * "," into ".", so on its own it read the German "1.234,56" as 1.23456 — and a money
11
+ * field's settle then made that 1.23, final. This decides per operand, from the
12
+ * typist's own text, before that fold:
13
+ *
14
+ * - both marks present: the one that is not the locale's is grouping, and goes;
15
+ * - in a "," locale, only "." present: grouping when it cannot be a decimal as a
16
+ * German reader writes it — twice ("1.234.567"), or in thousands shape ("1.234",
17
+ * "12.500") — otherwise a decimal ("1.5", typed by a dot-decimal habit);
18
+ * - in a "." locale, only "," present: grouping when it appears twice ("1,234,567");
19
+ * once it stays a decimal, because Swiss and German typists write "1,5" in a
20
+ * de-CH form (kastlan 40) and a unit price "1,789" is a decimal.
21
+ *
22
+ * Only a keystroke's text comes through here. A calculator result is dot-decimal
23
+ * already, and "1.234" from `100/81.03…` is never a thousand.
24
+ */
25
+ declare function normalizeTypedMarks(raw: string, mark: "," | "."): string;
26
+ /** What a keystroke's raw text reports: grouping read off, then the field's live
27
+ * sanitising (comma → dot, stray characters out, one decimal point per operand). */
28
+ declare function readTyped(raw: string, mark: "," | "."): string;
29
+ /**
30
+ * Whether the field may keep SHOWING `raw` — the typist's own text — while it holds
31
+ * `canonical` (dot-decimal, as `onChange` reported it).
32
+ *
33
+ * Showing the typed text rather than re-spelling the value is what keeps the caret
34
+ * where the typist put it, and what keeps a grouping "." from being turned into a ","
35
+ * under their fingers — after which no rule could tell the two apart (keksdose G1).
36
+ * But only text that says the same as the value, and says it with nothing the field
37
+ * would have DROPPED: a letter, or a second decimal point in one operand ("1.2.3"),
38
+ * must not stay on screen while the value says "1.23" (Keksdose live #201 is the bug
39
+ * that showing it would bring back). Grouping marks and grouping spaces may stay.
40
+ */
41
+ declare function showsTyped(raw: string, mark: "," | ".", canonical: string): boolean;
42
+ /** A dot-decimal text spelt in `mark` — display only, one character for one, so a
43
+ * re-spelling never moves a caret. */
44
+ declare function localizeMark(text: string, mark: "," | "."): string;
45
+
46
+ export { decimalMark, localizeMark, normalizeTypedMarks, readTyped, showsTyped };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { sanitizeLive } from "./calc.js";
3
+ function decimalMark(locale) {
4
+ try {
5
+ const part = new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === "decimal");
6
+ return part?.value === "," ? "," : ".";
7
+ } catch {
8
+ return ".";
9
+ }
10
+ }
11
+ function normalizeTypedMarks(raw, mark) {
12
+ const other = mark === "," ? "." : ",";
13
+ return raw.replace(/[0-9.,]+/g, (operand) => {
14
+ const hasMark = operand.includes(mark);
15
+ const count = operand.split(other).length - 1;
16
+ if (count === 0) return operand;
17
+ const grouping = hasMark ? true : count > 1 || mark === "," && /^\d{1,3}(\.\d{3})+$/.test(operand);
18
+ return grouping ? operand.split(other).join("") : operand;
19
+ });
20
+ }
21
+ function readTyped(raw, mark) {
22
+ return sanitizeLive(normalizeTypedMarks(raw, mark));
23
+ }
24
+ const GROUP_SPACING = /[\s'’\u00a0\u202f]/g;
25
+ function showsTyped(raw, mark, canonical) {
26
+ const read = normalizeTypedMarks(raw, mark).replace(GROUP_SPACING, "");
27
+ const sanitized = sanitizeLive(read);
28
+ return sanitized === read.replace(/,/g, ".") && sanitized === sanitizeLive(canonical);
29
+ }
30
+ function localizeMark(text, mark) {
31
+ return mark === "," ? text.replace(/\./g, ",") : text;
32
+ }
33
+ export {
34
+ decimalMark,
35
+ localizeMark,
36
+ normalizeTypedMarks,
37
+ readTyped,
38
+ showsTyped
39
+ };
40
+ //# sourceMappingURL=decimal-marks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/decimal-marks.ts"],"sourcesContent":["/**\n * The locale's decimal mark and the reading of typed grouping marks, shared by the\n * kit's numeric text fields: {@link AmountInput}, {@link NumberInput} and, through\n * NumberInput, {@link NumberField} and {@link MoneyField}.\n *\n * Package-private — not re-exported from the barrel. It lives here rather than in\n * `calc.ts` because that module is re-exported wholesale (`export * from\n * \"./lib/calc\"`), and these are the fields' plumbing, not API.\n *\n * WHY ONE MODULE. AmountInput learned the locale's mark (kastlan 40) and the grouping\n * parse (keksdose G1); NumberInput learned neither, so the same \"1.234,56\" a German\n * user typed into a money field read as 1234.56 and, typed into the budget-goal field\n * next to it, as 1.23456 (keksdose K5). Two private copies of the same rule are how\n * that happened, so the rule now has one home.\n */\nimport { sanitizeLive } from \"./calc\";\n\n/**\n * The locale's decimal mark, as far as a field can type it: \",\" or \".\" (kastlan 40).\n * A mark outside those two (Arabic's \"٫\") is not one {@link sanitizeLive} lets\n * through, so those locales keep the dot rather than get a field that eats the key it\n * shows. `undefined` is the runtime's own locale, which is what `Intl` reads it as.\n */\nexport function decimalMark(locale: string | undefined): \",\" | \".\" {\n try {\n const part = new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === \"decimal\");\n return part?.value === \",\" ? \",\" : \".\";\n } catch {\n // An invalid tag throws a RangeError; a typo in a locale must not take the form down.\n return \".\";\n }\n}\n\n/**\n * Which typed mark is the decimal one (keksdose G1). {@link sanitizeLive} folds every\n * \",\" into \".\", so on its own it read the German \"1.234,56\" as 1.23456 — and a money\n * field's settle then made that 1.23, final. This decides per operand, from the\n * typist's own text, before that fold:\n *\n * - both marks present: the one that is not the locale's is grouping, and goes;\n * - in a \",\" locale, only \".\" present: grouping when it cannot be a decimal as a\n * German reader writes it — twice (\"1.234.567\"), or in thousands shape (\"1.234\",\n * \"12.500\") — otherwise a decimal (\"1.5\", typed by a dot-decimal habit);\n * - in a \".\" locale, only \",\" present: grouping when it appears twice (\"1,234,567\");\n * once it stays a decimal, because Swiss and German typists write \"1,5\" in a\n * de-CH form (kastlan 40) and a unit price \"1,789\" is a decimal.\n *\n * Only a keystroke's text comes through here. A calculator result is dot-decimal\n * already, and \"1.234\" from `100/81.03…` is never a thousand.\n */\nexport function normalizeTypedMarks(raw: string, mark: \",\" | \".\"): string {\n const other = mark === \",\" ? \".\" : \",\";\n return raw.replace(/[0-9.,]+/g, (operand) => {\n const hasMark = operand.includes(mark);\n const count = operand.split(other).length - 1;\n if (count === 0) return operand;\n const grouping = hasMark\n ? true\n : count > 1 || (mark === \",\" && /^\\d{1,3}(\\.\\d{3})+$/.test(operand));\n return grouping ? operand.split(other).join(\"\") : operand;\n });\n}\n\n/** What a keystroke's raw text reports: grouping read off, then the field's live\n * sanitising (comma → dot, stray characters out, one decimal point per operand). */\nexport function readTyped(raw: string, mark: \",\" | \".\"): string {\n return sanitizeLive(normalizeTypedMarks(raw, mark));\n}\n\n// Spacing a typist uses to group digits — a space, the no-break and narrow no-break\n// spaces `Intl` itself writes for fr-CH (\"1 234,5\" with U+202F), and the Swiss\n// apostrophes (\"1'234.50\"). The live sanitising drops them, so they never reach the\n// value; the draft may still show them.\nconst GROUP_SPACING = /[\\s'’\\u00a0\\u202f]/g;\n\n/**\n * Whether the field may keep SHOWING `raw` — the typist's own text — while it holds\n * `canonical` (dot-decimal, as `onChange` reported it).\n *\n * Showing the typed text rather than re-spelling the value is what keeps the caret\n * where the typist put it, and what keeps a grouping \".\" from being turned into a \",\"\n * under their fingers — after which no rule could tell the two apart (keksdose G1).\n * But only text that says the same as the value, and says it with nothing the field\n * would have DROPPED: a letter, or a second decimal point in one operand (\"1.2.3\"),\n * must not stay on screen while the value says \"1.23\" (Keksdose live #201 is the bug\n * that showing it would bring back). Grouping marks and grouping spaces may stay.\n */\nexport function showsTyped(raw: string, mark: \",\" | \".\", canonical: string): boolean {\n const read = normalizeTypedMarks(raw, mark).replace(GROUP_SPACING, \"\");\n const sanitized = sanitizeLive(read);\n // Nothing dropped: the read text is the sanitised one, but for which mark it uses.\n return sanitized === read.replace(/,/g, \".\") && sanitized === sanitizeLive(canonical);\n}\n\n/** A dot-decimal text spelt in `mark` — display only, one character for one, so a\n * re-spelling never moves a caret. */\nexport function localizeMark(text: string, mark: \",\" | \".\"): string {\n return mark === \",\" ? text.replace(/\\./g, \",\") : text;\n}\n"],"mappings":";AAeA,SAAS,oBAAoB;AAQtB,SAAS,YAAY,QAAuC;AACjE,MAAI;AACF,UAAM,OAAO,IAAI,KAAK,aAAa,MAAM,EAAE,cAAc,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS;AAC9F,WAAO,MAAM,UAAU,MAAM,MAAM;AAAA,EACrC,QAAQ;AAEN,WAAO;AAAA,EACT;AACF;AAmBO,SAAS,oBAAoB,KAAa,MAAyB;AACxE,QAAM,QAAQ,SAAS,MAAM,MAAM;AACnC,SAAO,IAAI,QAAQ,aAAa,CAAC,YAAY;AAC3C,UAAM,UAAU,QAAQ,SAAS,IAAI;AACrC,UAAM,QAAQ,QAAQ,MAAM,KAAK,EAAE,SAAS;AAC5C,QAAI,UAAU,EAAG,QAAO;AACxB,UAAM,WAAW,UACb,OACA,QAAQ,KAAM,SAAS,OAAO,sBAAsB,KAAK,OAAO;AACpE,WAAO,WAAW,QAAQ,MAAM,KAAK,EAAE,KAAK,EAAE,IAAI;AAAA,EACpD,CAAC;AACH;AAIO,SAAS,UAAU,KAAa,MAAyB;AAC9D,SAAO,aAAa,oBAAoB,KAAK,IAAI,CAAC;AACpD;AAMA,MAAM,gBAAgB;AAcf,SAAS,WAAW,KAAa,MAAiB,WAA4B;AACnF,QAAM,OAAO,oBAAoB,KAAK,IAAI,EAAE,QAAQ,eAAe,EAAE;AACrE,QAAM,YAAY,aAAa,IAAI;AAEnC,SAAO,cAAc,KAAK,QAAQ,MAAM,GAAG,KAAK,cAAc,aAAa,SAAS;AACtF;AAIO,SAAS,aAAa,MAAc,MAAyB;AAClE,SAAO,SAAS,MAAM,KAAK,QAAQ,OAAO,GAAG,IAAI;AACnD;","names":[]}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * IBAN helpers — ISO 13616 — for kastlan (supplier and customer bank details, the
3
+ * Swiss QR-bill) and keksdose (the accounts behind a household's transfers).
4
+ *
5
+ * Both apps validated an IBAN the same partial way: a regex for the shape, sometimes a
6
+ * mod-97, never the per-country length — so a Swiss IBAN with a digit missing passed
7
+ * as long as the shorter string happened to sum right, and "CH" followed by 22
8
+ * characters (a German length) was accepted as Swiss. And kastlan's QR-bill needs a
9
+ * second distinction neither had: a **QR-IBAN** (the institution id at positions 5–9 is
10
+ * 30000–31999) is the only account a QR-bill with a QR reference can be paid to, and it
11
+ * cannot receive an ordinary transfer — so a regular IBAN typed where a QR-IBAN is
12
+ * needed, or the other way round, is a payment that bounces weeks later.
13
+ *
14
+ * Everything here works on the **electronic format** (no spaces, upper case), which is
15
+ * what to store; {@link formatIban} is the paper format, which is what to show.
16
+ *
17
+ * Validation is the registry's two rules, nothing more: the length for the country and
18
+ * the mod-97 check digits. It does not check each country's BBAN layout (which places
19
+ * hold letters), nor whether the bank exists — a checksum catches a typo, not a closed
20
+ * account.
21
+ */
22
+ /**
23
+ * The IBAN length for each country in the SWIFT IBAN Registry (2025 edition) — the
24
+ * whole string, country code and check digits included.
25
+ *
26
+ * A country that is not in the table does not issue IBANs, so {@link isValidIban}
27
+ * refuses it ("XX" is a typo, not an exotic bank). Territories that use another
28
+ * country's code (Åland under FI, Guernsey under GB, the French overseas departments
29
+ * under FR) are covered by that code, as the registry lists them.
30
+ */
31
+ declare const IBAN_LENGTHS: Readonly<Record<string, number>>;
32
+ /**
33
+ * Which kind of IBAN a field accepts. `"any"`: every valid IBAN. `"qr"`: only a
34
+ * QR-IBAN (a QR-bill with a QR reference — kastlan's payment slips). `"plain"`: every
35
+ * valid IBAN EXCEPT a QR-IBAN (an account for ordinary transfers, which a QR-IBAN
36
+ * cannot receive).
37
+ */
38
+ type IbanKind = "qr" | "plain" | "any";
39
+ /**
40
+ * Why a value is not the IBAN a field wants, most fundamental first:
41
+ *
42
+ * - `"format"` — it does not start with a two-letter country code and two digits;
43
+ * - `"country"` — the first two letters are not a country in {@link IBAN_LENGTHS};
44
+ * - `"length"` — the wrong number of characters for that country;
45
+ * - `"checksum"` — the mod-97 check digits do not match (a typo, a swapped pair);
46
+ * - `"qrRequired"` — a valid IBAN, but not a QR-IBAN where `kind="qr"` needs one;
47
+ * - `"qrNotAllowed"` — a valid QR-IBAN where `kind="plain"` refuses one.
48
+ */
49
+ type IbanProblem = "format" | "country" | "length" | "checksum" | "qrRequired" | "qrNotAllowed";
50
+ /**
51
+ * The electronic format: every character that is not a letter or a digit dropped, the
52
+ * letters in upper case. Spaces, non-breaking spaces, hyphens and dots — what a paste
53
+ * from an invoice, a PDF or an e-banking screen carries — all go.
54
+ *
55
+ * A leading `"IBAN"` (the paper format's label: "IBAN CH56 …") is dropped too, but only
56
+ * in front of a country code and check digits, so typing the word does not make it
57
+ * vanish under the caret.
58
+ */
59
+ declare function compactIban(value: string): string;
60
+ /**
61
+ * The paper format: {@link compactIban}, then groups of four separated by a single
62
+ * space ("CH09 0000 0000 0000 0000 1"). The last group is whatever is left over.
63
+ */
64
+ declare function formatIban(value: string): string;
65
+ /**
66
+ * The two check digits for a country code and a BBAN (the account part after them):
67
+ * `98 − ((BBAN + country + "00") mod 97)`, letters expanded A = 10 … Z = 35.
68
+ *
69
+ * What an app needs to BUILD an IBAN — a test fixture, a demo, a migration that
70
+ * assembles one from a clearing number and an account number — rather than to check
71
+ * one. Both arguments are compacted first.
72
+ */
73
+ declare function ibanCheckDigits(country: string, bban: string): string;
74
+ /**
75
+ * The first thing wrong with `value` as an IBAN of `kind`, or `null` when it is one.
76
+ * The value is compacted first, so the paper format is accepted. An empty value is
77
+ * `"format"`: whether a field may be left empty is the form's rule, not the IBAN's.
78
+ */
79
+ declare function ibanProblem(value: string, kind?: IbanKind): IbanProblem | null;
80
+ /**
81
+ * Whether `value` is a valid IBAN: a registry country, that country's length, and
82
+ * matching mod-97 check digits. Spaces and lower case are fine (see
83
+ * {@link compactIban}); what to store is the compact form.
84
+ */
85
+ declare function isValidIban(value: string): boolean;
86
+ /**
87
+ * Whether `value` is a valid **QR-IBAN**: a valid Swiss or Liechtenstein IBAN whose
88
+ * institution id — positions 5 to 9, the QR-IID — lies in 30000–31999 (SIX, Swiss
89
+ * Implementation Guidelines for the QR-bill).
90
+ *
91
+ * The distinction is not cosmetic (kastlan): a QR-bill with a QR reference can only be
92
+ * paid to a QR-IBAN, and a QR-IBAN can receive nothing else — so an app that prints
93
+ * payment slips needs one, and an app that stores an account for ordinary transfers
94
+ * must not take one.
95
+ */
96
+ declare function isQrIban(value: string): boolean;
97
+
98
+ export { IBAN_LENGTHS, type IbanKind, type IbanProblem, compactIban, formatIban, ibanCheckDigits, ibanProblem, isQrIban, isValidIban };
@@ -0,0 +1,154 @@
1
+ "use client";
2
+ const IBAN_LENGTHS = Object.freeze({
3
+ AD: 24,
4
+ AE: 23,
5
+ AL: 28,
6
+ AT: 20,
7
+ AZ: 28,
8
+ BA: 20,
9
+ BE: 16,
10
+ BG: 22,
11
+ BH: 22,
12
+ BI: 27,
13
+ BR: 29,
14
+ BY: 28,
15
+ CH: 21,
16
+ CR: 22,
17
+ CY: 28,
18
+ CZ: 24,
19
+ DE: 22,
20
+ DJ: 27,
21
+ DK: 18,
22
+ DO: 28,
23
+ EE: 20,
24
+ EG: 29,
25
+ ES: 24,
26
+ FI: 18,
27
+ FK: 18,
28
+ FO: 18,
29
+ FR: 27,
30
+ GB: 22,
31
+ GE: 22,
32
+ GI: 23,
33
+ GL: 18,
34
+ GR: 27,
35
+ GT: 28,
36
+ HN: 28,
37
+ HR: 21,
38
+ HU: 28,
39
+ IE: 22,
40
+ IL: 23,
41
+ IQ: 23,
42
+ IS: 26,
43
+ IT: 27,
44
+ JO: 30,
45
+ KW: 30,
46
+ KZ: 20,
47
+ LB: 28,
48
+ LC: 32,
49
+ LI: 21,
50
+ LT: 20,
51
+ LU: 20,
52
+ LV: 21,
53
+ LY: 25,
54
+ MC: 27,
55
+ MD: 24,
56
+ ME: 22,
57
+ MK: 19,
58
+ MN: 20,
59
+ MR: 27,
60
+ MT: 31,
61
+ MU: 30,
62
+ NI: 28,
63
+ NL: 18,
64
+ NO: 15,
65
+ OM: 23,
66
+ PK: 24,
67
+ PL: 28,
68
+ PS: 29,
69
+ PT: 25,
70
+ QA: 29,
71
+ RO: 24,
72
+ RS: 22,
73
+ RU: 33,
74
+ SA: 24,
75
+ SC: 31,
76
+ SD: 18,
77
+ SE: 24,
78
+ SI: 19,
79
+ SK: 24,
80
+ SM: 27,
81
+ SO: 23,
82
+ ST: 25,
83
+ SV: 28,
84
+ TL: 23,
85
+ TN: 24,
86
+ TR: 26,
87
+ UA: 29,
88
+ VA: 22,
89
+ VG: 24,
90
+ XK: 20,
91
+ YE: 30
92
+ });
93
+ function compactIban(value) {
94
+ const compact = value.replace(/[^0-9A-Za-z]/g, "").toUpperCase();
95
+ return /^IBAN[A-Z]{2}\d{2}/.test(compact) ? compact.slice(4) : compact;
96
+ }
97
+ function formatIban(value) {
98
+ return compactIban(value).replace(/(.{4})(?=.)/g, "$1 ");
99
+ }
100
+ function mod97(digits) {
101
+ let rest = 0;
102
+ for (let i = 0; i < digits.length; i += 7) {
103
+ rest = Number(`${rest}${digits.slice(i, i + 7)}`) % 97;
104
+ }
105
+ return rest;
106
+ }
107
+ function expandLetters(value) {
108
+ return value.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
109
+ }
110
+ function ibanCheckDigits(country, bban) {
111
+ const rearranged = `${compactIban(bban)}${compactIban(country)}00`;
112
+ const check = 98 - mod97(expandLetters(rearranged));
113
+ return String(check).padStart(2, "0");
114
+ }
115
+ function ibanProblem(value, kind = "any") {
116
+ const iban = compactIban(value);
117
+ if (!/^[A-Z]{2}\d{2}/.test(iban)) return "format";
118
+ const expected = IBAN_LENGTHS[iban.slice(0, 2)];
119
+ if (expected === void 0) return "country";
120
+ if (iban.length !== expected) return "length";
121
+ const check = iban.slice(2, 4);
122
+ if (check === "00" || check === "01" || check === "99") return "checksum";
123
+ if (mod97(expandLetters(`${iban.slice(4)}${iban.slice(0, 4)}`)) !== 1) return "checksum";
124
+ if (kind === "any") return null;
125
+ const qr = qrIid(iban);
126
+ if (kind === "qr" && !qr) return "qrRequired";
127
+ if (kind === "plain" && qr) return "qrNotAllowed";
128
+ return null;
129
+ }
130
+ function isValidIban(value) {
131
+ return ibanProblem(value) === null;
132
+ }
133
+ function qrIid(iban) {
134
+ const country = iban.slice(0, 2);
135
+ if (country !== "CH" && country !== "LI") return false;
136
+ const iid = iban.slice(4, 9);
137
+ if (!/^\d{5}$/.test(iid)) return false;
138
+ const n = Number(iid);
139
+ return n >= 3e4 && n <= 31999;
140
+ }
141
+ function isQrIban(value) {
142
+ const iban = compactIban(value);
143
+ return ibanProblem(iban) === null && qrIid(iban);
144
+ }
145
+ export {
146
+ IBAN_LENGTHS,
147
+ compactIban,
148
+ formatIban,
149
+ ibanCheckDigits,
150
+ ibanProblem,
151
+ isQrIban,
152
+ isValidIban
153
+ };
154
+ //# sourceMappingURL=iban.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/iban.ts"],"sourcesContent":["/**\n * IBAN helpers — ISO 13616 — for kastlan (supplier and customer bank details, the\n * Swiss QR-bill) and keksdose (the accounts behind a household's transfers).\n *\n * Both apps validated an IBAN the same partial way: a regex for the shape, sometimes a\n * mod-97, never the per-country length — so a Swiss IBAN with a digit missing passed\n * as long as the shorter string happened to sum right, and \"CH\" followed by 22\n * characters (a German length) was accepted as Swiss. And kastlan's QR-bill needs a\n * second distinction neither had: a **QR-IBAN** (the institution id at positions 5–9 is\n * 30000–31999) is the only account a QR-bill with a QR reference can be paid to, and it\n * cannot receive an ordinary transfer — so a regular IBAN typed where a QR-IBAN is\n * needed, or the other way round, is a payment that bounces weeks later.\n *\n * Everything here works on the **electronic format** (no spaces, upper case), which is\n * what to store; {@link formatIban} is the paper format, which is what to show.\n *\n * Validation is the registry's two rules, nothing more: the length for the country and\n * the mod-97 check digits. It does not check each country's BBAN layout (which places\n * hold letters), nor whether the bank exists — a checksum catches a typo, not a closed\n * account.\n */\n\n/**\n * The IBAN length for each country in the SWIFT IBAN Registry (2025 edition) — the\n * whole string, country code and check digits included.\n *\n * A country that is not in the table does not issue IBANs, so {@link isValidIban}\n * refuses it (\"XX\" is a typo, not an exotic bank). Territories that use another\n * country's code (Åland under FI, Guernsey under GB, the French overseas departments\n * under FR) are covered by that code, as the registry lists them.\n */\nexport const IBAN_LENGTHS: Readonly<Record<string, number>> = Object.freeze({\n AD: 24, AE: 23, AL: 28, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BI: 27,\n BR: 29, BY: 28, CH: 21, CR: 22, CY: 28, CZ: 24, DE: 22, DJ: 27, DK: 18, DO: 28,\n EE: 20, EG: 29, ES: 24, FI: 18, FK: 18, FO: 18, FR: 27, GB: 22, GE: 22, GI: 23,\n GL: 18, GR: 27, GT: 28, HN: 28, HR: 21, HU: 28, IE: 22, IL: 23, IQ: 23, IS: 26,\n IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28, LC: 32, LI: 21, LT: 20, LU: 20, LV: 21,\n LY: 25, MC: 27, MD: 24, ME: 22, MK: 19, MN: 20, MR: 27, MT: 31, MU: 30, NI: 28,\n NL: 18, NO: 15, OM: 23, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29, RO: 24, RS: 22,\n RU: 33, SA: 24, SC: 31, SD: 18, SE: 24, SI: 19, SK: 24, SM: 27, SO: 23, ST: 25,\n SV: 28, TL: 23, TN: 24, TR: 26, UA: 29, VA: 22, VG: 24, XK: 20, YE: 30,\n});\n\n/**\n * Which kind of IBAN a field accepts. `\"any\"`: every valid IBAN. `\"qr\"`: only a\n * QR-IBAN (a QR-bill with a QR reference — kastlan's payment slips). `\"plain\"`: every\n * valid IBAN EXCEPT a QR-IBAN (an account for ordinary transfers, which a QR-IBAN\n * cannot receive).\n */\nexport type IbanKind = \"qr\" | \"plain\" | \"any\";\n\n/**\n * Why a value is not the IBAN a field wants, most fundamental first:\n *\n * - `\"format\"` — it does not start with a two-letter country code and two digits;\n * - `\"country\"` — the first two letters are not a country in {@link IBAN_LENGTHS};\n * - `\"length\"` — the wrong number of characters for that country;\n * - `\"checksum\"` — the mod-97 check digits do not match (a typo, a swapped pair);\n * - `\"qrRequired\"` — a valid IBAN, but not a QR-IBAN where `kind=\"qr\"` needs one;\n * - `\"qrNotAllowed\"` — a valid QR-IBAN where `kind=\"plain\"` refuses one.\n */\nexport type IbanProblem = \"format\" | \"country\" | \"length\" | \"checksum\" | \"qrRequired\" | \"qrNotAllowed\";\n\n/**\n * The electronic format: every character that is not a letter or a digit dropped, the\n * letters in upper case. Spaces, non-breaking spaces, hyphens and dots — what a paste\n * from an invoice, a PDF or an e-banking screen carries — all go.\n *\n * A leading `\"IBAN\"` (the paper format's label: \"IBAN CH56 …\") is dropped too, but only\n * in front of a country code and check digits, so typing the word does not make it\n * vanish under the caret.\n */\nexport function compactIban(value: string): string {\n const compact = value.replace(/[^0-9A-Za-z]/g, \"\").toUpperCase();\n return /^IBAN[A-Z]{2}\\d{2}/.test(compact) ? compact.slice(4) : compact;\n}\n\n/**\n * The paper format: {@link compactIban}, then groups of four separated by a single\n * space (\"CH09 0000 0000 0000 0000 1\"). The last group is whatever is left over.\n */\nexport function formatIban(value: string): string {\n return compactIban(value).replace(/(.{4})(?=.)/g, \"$1 \");\n}\n\n/** The remainder of a long digit string modulo 97, a few digits at a time so it never\n * leaves the safe-integer range — ISO 7064 MOD 97-10 without a BigInt. */\nfunction mod97(digits: string): number {\n let rest = 0;\n for (let i = 0; i < digits.length; i += 7) {\n rest = Number(`${rest}${digits.slice(i, i + 7)}`) % 97;\n }\n return rest;\n}\n\n/** Letters to their two-digit numbers (A = 10 … Z = 35), digits as they are. */\nfunction expandLetters(value: string): string {\n return value.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));\n}\n\n/**\n * The two check digits for a country code and a BBAN (the account part after them):\n * `98 − ((BBAN + country + \"00\") mod 97)`, letters expanded A = 10 … Z = 35.\n *\n * What an app needs to BUILD an IBAN — a test fixture, a demo, a migration that\n * assembles one from a clearing number and an account number — rather than to check\n * one. Both arguments are compacted first.\n */\nexport function ibanCheckDigits(country: string, bban: string): string {\n const rearranged = `${compactIban(bban)}${compactIban(country)}00`;\n const check = 98 - mod97(expandLetters(rearranged));\n return String(check).padStart(2, \"0\");\n}\n\n/**\n * The first thing wrong with `value` as an IBAN of `kind`, or `null` when it is one.\n * The value is compacted first, so the paper format is accepted. An empty value is\n * `\"format\"`: whether a field may be left empty is the form's rule, not the IBAN's.\n */\nexport function ibanProblem(value: string, kind: IbanKind = \"any\"): IbanProblem | null {\n const iban = compactIban(value);\n if (!/^[A-Z]{2}\\d{2}/.test(iban)) return \"format\";\n const expected = IBAN_LENGTHS[iban.slice(0, 2)];\n if (expected === undefined) return \"country\";\n if (iban.length !== expected) return \"length\";\n // 00, 01 and 99 are never computed (98 − r lies in 2…98), but 01 ≡ 98 mod 97 and\n // would otherwise pass the remainder test below — ISO 7064 rules them out.\n const check = iban.slice(2, 4);\n if (check === \"00\" || check === \"01\" || check === \"99\") return \"checksum\";\n if (mod97(expandLetters(`${iban.slice(4)}${iban.slice(0, 4)}`)) !== 1) return \"checksum\";\n if (kind === \"any\") return null;\n const qr = qrIid(iban);\n if (kind === \"qr\" && !qr) return \"qrRequired\";\n if (kind === \"plain\" && qr) return \"qrNotAllowed\";\n return null;\n}\n\n/**\n * Whether `value` is a valid IBAN: a registry country, that country's length, and\n * matching mod-97 check digits. Spaces and lower case are fine (see\n * {@link compactIban}); what to store is the compact form.\n */\nexport function isValidIban(value: string): boolean {\n return ibanProblem(value) === null;\n}\n\n/** A CH/LI IBAN whose institution id (positions 5–9) is in the QR range. Structure\n * only — the caller has checked or will check the rest. */\nfunction qrIid(iban: string): boolean {\n const country = iban.slice(0, 2);\n if (country !== \"CH\" && country !== \"LI\") return false;\n const iid = iban.slice(4, 9);\n if (!/^\\d{5}$/.test(iid)) return false;\n const n = Number(iid);\n return n >= 30000 && n <= 31999;\n}\n\n/**\n * Whether `value` is a valid **QR-IBAN**: a valid Swiss or Liechtenstein IBAN whose\n * institution id — positions 5 to 9, the QR-IID — lies in 30000–31999 (SIX, Swiss\n * Implementation Guidelines for the QR-bill).\n *\n * The distinction is not cosmetic (kastlan): a QR-bill with a QR reference can only be\n * paid to a QR-IBAN, and a QR-IBAN can receive nothing else — so an app that prints\n * payment slips needs one, and an app that stores an account for ordinary transfers\n * must not take one.\n */\nexport function isQrIban(value: string): boolean {\n const iban = compactIban(value);\n return ibanProblem(iban) === null && qrIid(iban);\n}\n"],"mappings":";AA+BO,MAAM,eAAiD,OAAO,OAAO;AAAA,EAC1E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAC5E,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AAAA,EAAI,IAAI;AACtE,CAAC;AA+BM,SAAS,YAAY,OAAuB;AACjD,QAAM,UAAU,MAAM,QAAQ,iBAAiB,EAAE,EAAE,YAAY;AAC/D,SAAO,qBAAqB,KAAK,OAAO,IAAI,QAAQ,MAAM,CAAC,IAAI;AACjE;AAMO,SAAS,WAAW,OAAuB;AAChD,SAAO,YAAY,KAAK,EAAE,QAAQ,gBAAgB,KAAK;AACzD;AAIA,SAAS,MAAM,QAAwB;AACrC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;AACzC,WAAO,OAAO,GAAG,IAAI,GAAG,OAAO,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI;AAAA,EACtD;AACA,SAAO;AACT;AAGA,SAAS,cAAc,OAAuB;AAC5C,SAAO,MAAM,QAAQ,UAAU,CAAC,MAAM,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;AACpE;AAUO,SAAS,gBAAgB,SAAiB,MAAsB;AACrE,QAAM,aAAa,GAAG,YAAY,IAAI,CAAC,GAAG,YAAY,OAAO,CAAC;AAC9D,QAAM,QAAQ,KAAK,MAAM,cAAc,UAAU,CAAC;AAClD,SAAO,OAAO,KAAK,EAAE,SAAS,GAAG,GAAG;AACtC;AAOO,SAAS,YAAY,OAAe,OAAiB,OAA2B;AACrF,QAAM,OAAO,YAAY,KAAK;AAC9B,MAAI,CAAC,iBAAiB,KAAK,IAAI,EAAG,QAAO;AACzC,QAAM,WAAW,aAAa,KAAK,MAAM,GAAG,CAAC,CAAC;AAC9C,MAAI,aAAa,OAAW,QAAO;AACnC,MAAI,KAAK,WAAW,SAAU,QAAO;AAGrC,QAAM,QAAQ,KAAK,MAAM,GAAG,CAAC;AAC7B,MAAI,UAAU,QAAQ,UAAU,QAAQ,UAAU,KAAM,QAAO;AAC/D,MAAI,MAAM,cAAc,GAAG,KAAK,MAAM,CAAC,CAAC,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,EAAG,QAAO;AAC9E,MAAI,SAAS,MAAO,QAAO;AAC3B,QAAM,KAAK,MAAM,IAAI;AACrB,MAAI,SAAS,QAAQ,CAAC,GAAI,QAAO;AACjC,MAAI,SAAS,WAAW,GAAI,QAAO;AACnC,SAAO;AACT;AAOO,SAAS,YAAY,OAAwB;AAClD,SAAO,YAAY,KAAK,MAAM;AAChC;AAIA,SAAS,MAAM,MAAuB;AACpC,QAAM,UAAU,KAAK,MAAM,GAAG,CAAC;AAC/B,MAAI,YAAY,QAAQ,YAAY,KAAM,QAAO;AACjD,QAAM,MAAM,KAAK,MAAM,GAAG,CAAC;AAC3B,MAAI,CAAC,UAAU,KAAK,GAAG,EAAG,QAAO;AACjC,QAAM,IAAI,OAAO,GAAG;AACpB,SAAO,KAAK,OAAS,KAAK;AAC5B;AAYO,SAAS,SAAS,OAAwB;AAC/C,QAAM,OAAO,YAAY,KAAK;AAC9B,SAAO,YAAY,IAAI,MAAM,QAAQ,MAAM,IAAI;AACjD;","names":[]}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * ISIN helpers — ISO 6166 — for keksdose, whose securities holdings are keyed by ISIN
3
+ * and whose import and edit forms checked only the shape (two letters, ten
4
+ * characters): a mistyped ISIN saved happily and then matched no price feed.
5
+ *
6
+ * An ISIN is twelve characters: a two-letter prefix (the issuing country, or a
7
+ * supranational code such as `XS`), nine letters or digits (the national number) and
8
+ * one check digit. The check digit is the Luhn digit of the first eleven characters
9
+ * with every letter expanded to two digits (A = 10 … Z = 35) — which is all that is
10
+ * checked here. Whether the prefix is an assigned code, and whether the security
11
+ * exists, is a lookup, not a checksum.
12
+ */
13
+ /**
14
+ * The ISIN as it is printed: upper case, unbroken (ISO 6166 has no grouping), with
15
+ * the spaces and hyphens a paste from a broker's statement carries dropped.
16
+ */
17
+ declare function formatIsin(value: string): string;
18
+ /**
19
+ * The check digit for the first eleven characters of an ISIN (prefix and national
20
+ * number). For BUILDING one — a test fixture, a demo — rather than checking it.
21
+ */
22
+ declare function isinCheckDigit(body: string): string;
23
+ /**
24
+ * Whether `value` is a valid ISIN: two letters, nine letters or digits, one digit,
25
+ * and a matching Luhn check digit over the letter-expanded form. Spaces, hyphens and
26
+ * lower case are fine (see {@link formatIsin}).
27
+ */
28
+ declare function isValidIsin(value: string): boolean;
29
+
30
+ export { formatIsin, isValidIsin, isinCheckDigit };
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ function expandLetters(value) {
3
+ return value.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
4
+ }
5
+ function luhnSum(digits, doubleRightmost) {
6
+ let sum = 0;
7
+ let double = doubleRightmost;
8
+ for (let i = digits.length - 1; i >= 0; i--) {
9
+ let d = digits.charCodeAt(i) - 48;
10
+ if (double) {
11
+ d *= 2;
12
+ if (d > 9) d -= 9;
13
+ }
14
+ sum += d;
15
+ double = !double;
16
+ }
17
+ return sum;
18
+ }
19
+ function formatIsin(value) {
20
+ return value.replace(/[\s-]/g, "").toUpperCase();
21
+ }
22
+ function isinCheckDigit(body) {
23
+ const sum = luhnSum(expandLetters(formatIsin(body)), true);
24
+ return String((10 - sum % 10) % 10);
25
+ }
26
+ function isValidIsin(value) {
27
+ const isin = formatIsin(value);
28
+ if (!/^[A-Z]{2}[A-Z0-9]{9}\d$/.test(isin)) return false;
29
+ return luhnSum(expandLetters(isin), false) % 10 === 0;
30
+ }
31
+ export {
32
+ formatIsin,
33
+ isValidIsin,
34
+ isinCheckDigit
35
+ };
36
+ //# sourceMappingURL=isin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/isin.ts"],"sourcesContent":["/**\n * ISIN helpers — ISO 6166 — for keksdose, whose securities holdings are keyed by ISIN\n * and whose import and edit forms checked only the shape (two letters, ten\n * characters): a mistyped ISIN saved happily and then matched no price feed.\n *\n * An ISIN is twelve characters: a two-letter prefix (the issuing country, or a\n * supranational code such as `XS`), nine letters or digits (the national number) and\n * one check digit. The check digit is the Luhn digit of the first eleven characters\n * with every letter expanded to two digits (A = 10 … Z = 35) — which is all that is\n * checked here. Whether the prefix is an assigned code, and whether the security\n * exists, is a lookup, not a checksum.\n */\n\n/** Letters to their two-digit numbers (A = 10 … Z = 35), digits as they are. */\nfunction expandLetters(value: string): string {\n return value.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));\n}\n\n/** The Luhn sum of `digits` with the RIGHTMOST digit doubled first — the shape of the\n * sum when a check digit is about to be appended. */\nfunction luhnSum(digits: string, doubleRightmost: boolean): number {\n let sum = 0;\n let double = doubleRightmost;\n for (let i = digits.length - 1; i >= 0; i--) {\n let d = digits.charCodeAt(i) - 48;\n if (double) {\n d *= 2;\n if (d > 9) d -= 9;\n }\n sum += d;\n double = !double;\n }\n return sum;\n}\n\n/**\n * The ISIN as it is printed: upper case, unbroken (ISO 6166 has no grouping), with\n * the spaces and hyphens a paste from a broker's statement carries dropped.\n */\nexport function formatIsin(value: string): string {\n return value.replace(/[\\s-]/g, \"\").toUpperCase();\n}\n\n/**\n * The check digit for the first eleven characters of an ISIN (prefix and national\n * number). For BUILDING one — a test fixture, a demo — rather than checking it.\n */\nexport function isinCheckDigit(body: string): string {\n const sum = luhnSum(expandLetters(formatIsin(body)), true);\n return String((10 - (sum % 10)) % 10);\n}\n\n/**\n * Whether `value` is a valid ISIN: two letters, nine letters or digits, one digit,\n * and a matching Luhn check digit over the letter-expanded form. Spaces, hyphens and\n * lower case are fine (see {@link formatIsin}).\n */\nexport function isValidIsin(value: string): boolean {\n const isin = formatIsin(value);\n if (!/^[A-Z]{2}[A-Z0-9]{9}\\d$/.test(isin)) return false;\n return luhnSum(expandLetters(isin), false) % 10 === 0;\n}\n"],"mappings":";AAcA,SAAS,cAAc,OAAuB;AAC5C,SAAO,MAAM,QAAQ,UAAU,CAAC,MAAM,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;AACpE;AAIA,SAAS,QAAQ,QAAgB,iBAAkC;AACjE,MAAI,MAAM;AACV,MAAI,SAAS;AACb,WAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,QAAI,IAAI,OAAO,WAAW,CAAC,IAAI;AAC/B,QAAI,QAAQ;AACV,WAAK;AACL,UAAI,IAAI,EAAG,MAAK;AAAA,IAClB;AACA,WAAO;AACP,aAAS,CAAC;AAAA,EACZ;AACA,SAAO;AACT;AAMO,SAAS,WAAW,OAAuB;AAChD,SAAO,MAAM,QAAQ,UAAU,EAAE,EAAE,YAAY;AACjD;AAMO,SAAS,eAAe,MAAsB;AACnD,QAAM,MAAM,QAAQ,cAAc,WAAW,IAAI,CAAC,GAAG,IAAI;AACzD,SAAO,QAAQ,KAAM,MAAM,MAAO,EAAE;AACtC;AAOO,SAAS,YAAY,OAAwB;AAClD,QAAM,OAAO,WAAW,KAAK;AAC7B,MAAI,CAAC,0BAA0B,KAAK,IAAI,EAAG,QAAO;AAClD,SAAO,QAAQ,cAAc,IAAI,GAAG,KAAK,IAAI,OAAO;AACtD;","names":[]}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Phone numbers — E.164 in, grouped out — for kastlan's contacts, without a
3
+ * libphonenumber dependency.
4
+ *
5
+ * kastlan stored whatever was typed ("079 …", "+41 (0)79 …", "0041 79 …") and could
6
+ * neither dial nor de-duplicate it. What it needs is one canonical form to store —
7
+ * E.164, "+41210000001" — and a readable one to show. libphonenumber gets both right
8
+ * for every country, at ~150 kB of metadata in every app's bundle; the kit's apps are
9
+ * Swiss and their neighbours, so this is **light per-country rules** for the six that
10
+ * matter and a generic shape check for the rest:
11
+ *
12
+ * - **CH, LI, DE, AT, FR, IT**: the national trunk prefix is dropped (a leading 0 —
13
+ * but NOT for Italy, whose fixed-line numbers keep their 0 after +39, and not for
14
+ * Liechtenstein, which has none), and the remaining national number has to be a
15
+ * plausible length for the country.
16
+ * - **Anything else** typed with its own "+" (or "00"): the digits, 8 to 15 in all,
17
+ * are taken as an E.164 number as they stand.
18
+ *
19
+ * **The limitation:** a plausible length is not a valid number. There is no check of
20
+ * area codes or number ranges, so a well-formed number that does not exist passes, and
21
+ * a German or Austrian number (whose area codes run from one to five digits) is
22
+ * grouped only where the split is known (mobile prefixes, the largest cities) and
23
+ * otherwise shown in one block. A number these rules cannot read is not an error —
24
+ * {@link parsePhone} returns `null` and the field keeps the text as typed.
25
+ */
26
+ /** The countries with their own rules. */
27
+ type PhoneCountryCode = "CH" | "LI" | "DE" | "AT" | "FR" | "IT";
28
+ /** A country with rules, or `"other"`: a number typed with its own "+". */
29
+ type PhoneCountry = PhoneCountryCode | "other";
30
+ /** The country calling codes with rules, "+" left off: `{ CH: "41", … }`. */
31
+ declare const PHONE_DIAL_CODES: Readonly<Record<PhoneCountryCode, string>>;
32
+ /** The countries with rules, in the order a picker offers them by default. */
33
+ declare const PHONE_COUNTRIES: readonly PhoneCountryCode[];
34
+ /** What {@link parsePhone} reads out of a number. */
35
+ interface ParsedPhone {
36
+ /** The number in E.164: "+", the country code, the national number. */
37
+ e164: string;
38
+ /** The country whose rules read it, or `null` for a generic "+…" number. */
39
+ country: PhoneCountryCode | null;
40
+ /** The national significant number — the digits after the country code. For a
41
+ * generic number, every digit after the "+" (the country code is not split off). */
42
+ national: string;
43
+ }
44
+ /**
45
+ * Read a typed number. With a leading "+" or "00" the number carries its own country
46
+ * code — one of the six with rules, or any other (8–15 digits in all, the E.164
47
+ * limit). Without one it is a national number of `country` (default `"CH"`), its
48
+ * trunk 0 optional; with `country="other"` a number without "+" cannot be read.
49
+ *
50
+ * Spaces, hyphens, dots, slashes and parentheses are ignored ("(030) 1234567"), and
51
+ * so is the "(0)" of "+41 (0)21 …". Anything else — a letter, an extension ("ext. 12"), a note —
52
+ * and the result is `null`: the text is not a number these rules can read, and a field
53
+ * keeps it as it is rather than guess.
54
+ */
55
+ declare function parsePhone(input: string, country?: PhoneCountry): ParsedPhone | null;
56
+ /** The national number grouped by its country's rules ("21 000 00 01"). */
57
+ declare function formatNationalPhone(nsn: string, country: PhoneCountryCode): string;
58
+ /**
59
+ * A number for display: an E.164 number (or anything {@link parsePhone} reads with a
60
+ * "+") grouped by its country's rules — "+41 21 000 00 01" — and a generic one as
61
+ * "+" and its digits. Anything it cannot read comes back exactly as it went in, so a
62
+ * list of contacts can format every row without first sorting out the free text.
63
+ */
64
+ declare function formatPhone(value: string): string;
65
+ /** Whether `value` is in E.164 shape: "+" and 8–15 digits, nothing else. Shape only —
66
+ * what {@link PhoneInput} emits for every number it could read. */
67
+ declare function isE164(value: string): boolean;
68
+
69
+ export { PHONE_COUNTRIES, PHONE_DIAL_CODES, type ParsedPhone, type PhoneCountry, type PhoneCountryCode, formatNationalPhone, formatPhone, isE164, parsePhone };
@@ -0,0 +1,121 @@
1
+ "use client";
2
+ function cut(nsn, sizes) {
3
+ const out = [];
4
+ let at = 0;
5
+ for (const size of sizes) {
6
+ if (at >= nsn.length) break;
7
+ out.push(nsn.slice(at, at + size));
8
+ at += size;
9
+ }
10
+ if (at < nsn.length) out.push(nsn.slice(at));
11
+ return out;
12
+ }
13
+ const RULES = {
14
+ // 9 digits, 2-3-2-2 ("21 000 00 01"); the 08xx/09xx service numbers 3-3-3.
15
+ CH: {
16
+ dial: "41",
17
+ trunk: true,
18
+ min: 9,
19
+ max: 9,
20
+ group: (n) => /^[89]/.test(n) ? cut(n, [3, 3, 3]) : cut(n, [2, 3, 2, 2])
21
+ },
22
+ // 7 digits, 3-2-2 ("100 00 01"), and 9 for some mobile ranges (3-3-3). No trunk prefix.
23
+ LI: {
24
+ dial: "423",
25
+ trunk: false,
26
+ min: 7,
27
+ max: 9,
28
+ group: (n) => n.length === 7 ? cut(n, [3, 2, 2]) : n.length === 9 ? cut(n, [3, 3, 3]) : [n]
29
+ },
30
+ // Area codes of two to five digits: only the mobile prefixes and the four
31
+ // two-digit cities are split; anything else is one block rather than a wrong split.
32
+ DE: {
33
+ dial: "49",
34
+ trunk: true,
35
+ min: 6,
36
+ max: 13,
37
+ group: (n) => /^15/.test(n) ? cut(n, [4]) : /^1[67]/.test(n) ? cut(n, [3]) : /^(30|40|69|89)/.test(n) ? cut(n, [2]) : [n]
38
+ },
39
+ // Vienna is "1"; mobile numbers start 6xx; other area codes vary, so one block.
40
+ AT: {
41
+ dial: "43",
42
+ trunk: true,
43
+ min: 6,
44
+ max: 13,
45
+ group: (n) => /^6/.test(n) ? cut(n, [3]) : /^1/.test(n) ? cut(n, [1]) : [n]
46
+ },
47
+ // 9 digits, 1-2-2-2-2 ("1 99 00 00 01").
48
+ FR: { dial: "33", trunk: true, min: 9, max: 9, group: (n) => cut(n, [1, 2, 2, 2, 2]) },
49
+ // The 0 of a fixed line is part of the number ("+39 06 …"); mobiles start with 3.
50
+ IT: {
51
+ dial: "39",
52
+ trunk: false,
53
+ zeroStart: true,
54
+ min: 6,
55
+ max: 11,
56
+ group: (n) => /^3/.test(n) ? cut(n, [3, 3]) : /^0[26]/.test(n) ? cut(n, [2, 4]) : [n]
57
+ }
58
+ };
59
+ const PHONE_DIAL_CODES = Object.freeze({
60
+ CH: RULES.CH.dial,
61
+ LI: RULES.LI.dial,
62
+ DE: RULES.DE.dial,
63
+ AT: RULES.AT.dial,
64
+ FR: RULES.FR.dial,
65
+ IT: RULES.IT.dial
66
+ });
67
+ const PHONE_COUNTRIES = Object.freeze(["CH", "LI", "DE", "AT", "FR", "IT"]);
68
+ const BY_DIAL = [...PHONE_COUNTRIES].sort((a, b) => RULES[b].dial.length - RULES[a].dial.length);
69
+ function national(digits, rule) {
70
+ const nsn = rule.trunk && digits.startsWith("0") ? digits.slice(1) : digits;
71
+ if (nsn.startsWith("0") && !rule.zeroStart) return null;
72
+ if (nsn.length < rule.min || nsn.length > rule.max) return null;
73
+ return nsn;
74
+ }
75
+ function parsePhone(input, country = "CH") {
76
+ const text = input.trim();
77
+ if (text === "" || !/^\+?[\d\s().\-/]+$/.test(text)) return null;
78
+ let digits = text.replace(/\D/g, "");
79
+ let international = text.startsWith("+");
80
+ if (!international && digits.startsWith("00")) {
81
+ international = true;
82
+ digits = digits.slice(2);
83
+ }
84
+ if (international) {
85
+ digits = text.replace(/\(\s*0\s*\)/g, "").replace(/\D/g, "").replace(/^00/, "");
86
+ if (digits.startsWith("0")) return null;
87
+ const known = BY_DIAL.find((c) => digits.startsWith(RULES[c].dial));
88
+ if (known) {
89
+ const rule2 = RULES[known];
90
+ const nsn2 = national(digits.slice(rule2.dial.length), rule2);
91
+ return nsn2 === null ? null : { e164: `+${rule2.dial}${nsn2}`, country: known, national: nsn2 };
92
+ }
93
+ if (digits.length < 8 || digits.length > 15) return null;
94
+ return { e164: `+${digits}`, country: null, national: digits };
95
+ }
96
+ if (country === "other") return null;
97
+ const rule = RULES[country];
98
+ const nsn = national(digits, rule);
99
+ return nsn === null ? null : { e164: `+${rule.dial}${nsn}`, country, national: nsn };
100
+ }
101
+ function formatNationalPhone(nsn, country) {
102
+ return RULES[country].group(nsn).join(" ");
103
+ }
104
+ function formatPhone(value) {
105
+ const parsed = value.trim().startsWith("+") ? parsePhone(value, "other") : null;
106
+ if (!parsed) return value;
107
+ if (!parsed.country) return parsed.e164;
108
+ return `+${RULES[parsed.country].dial} ${formatNationalPhone(parsed.national, parsed.country)}`;
109
+ }
110
+ function isE164(value) {
111
+ return /^\+[1-9]\d{7,14}$/.test(value);
112
+ }
113
+ export {
114
+ PHONE_COUNTRIES,
115
+ PHONE_DIAL_CODES,
116
+ formatNationalPhone,
117
+ formatPhone,
118
+ isE164,
119
+ parsePhone
120
+ };
121
+ //# sourceMappingURL=phone.js.map