@bbn/bbn 2.0.237 → 2.0.239

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 (86) hide show
  1. package/dist/$.js +1 -1
  2. package/dist/bbn.js +3 -3
  3. package/dist/bbn.js.map +1 -1
  4. package/dist/bbn.sw.js +3 -3
  5. package/dist/bbn.sw.js.map +1 -1
  6. package/dist/com.js +13 -21
  7. package/dist/{vars.d.ts → data.d.ts} +1 -0
  8. package/dist/{vars.js → data.js} +1 -0
  9. package/dist/db/classes/Center.d.ts +10 -0
  10. package/dist/db/classes/Center.js +88 -0
  11. package/dist/db/classes/Object.d.ts +3 -0
  12. package/dist/db/classes/Object.js +469 -0
  13. package/dist/db/classes/ObjectProxy.d.ts +18 -0
  14. package/dist/db/classes/ObjectProxy.js +79 -0
  15. package/dist/db/classes/Proxy.d.ts +10 -0
  16. package/dist/db/classes/Proxy.js +52 -0
  17. package/dist/db/functions/fieldsFromFilter.d.ts +1 -0
  18. package/dist/db/functions/fieldsFromFilter.js +33 -0
  19. package/dist/db/functions/getPrimaryKey.d.ts +2 -0
  20. package/dist/db/functions/getPrimaryKey.js +8 -0
  21. package/dist/db/functions/requestToPromise.d.ts +1 -0
  22. package/dist/db/functions/requestToPromise.js +6 -0
  23. package/dist/db/functions/transactionDone.d.ts +1 -0
  24. package/dist/db/functions/transactionDone.js +7 -0
  25. package/dist/db/functions/transformResult.d.ts +1 -0
  26. package/dist/db/functions/transformResult.js +16 -0
  27. package/dist/db/types.d.ts +56 -0
  28. package/dist/db/types.js +1 -0
  29. package/dist/db.d.ts +3 -66
  30. package/dist/db.js +3 -558
  31. package/dist/dt/classes/{date.d.ts → Date.d.ts} +1 -1
  32. package/dist/dt/classes/{date.js → Date.js} +8 -3
  33. package/dist/dt/classes/{dateTime.d.ts → DateTime.d.ts} +1 -1
  34. package/dist/dt/classes/{dateTime.js → DateTime.js} +9 -3
  35. package/dist/dt/classes/{dt.d.ts → Dt.d.ts} +1 -1
  36. package/dist/dt/classes/{dt.js → Dt.js} +36 -48
  37. package/dist/dt/classes/Duration.js +193 -0
  38. package/dist/dt/classes/{monthDay.d.ts → MonthDay.d.ts} +1 -1
  39. package/dist/dt/classes/{monthDay.js → MonthDay.js} +2 -2
  40. package/dist/dt/classes/{time.d.ts → Time.d.ts} +1 -1
  41. package/dist/dt/classes/{time.js → Time.js} +2 -2
  42. package/dist/dt/classes/{yearMonth.d.ts → YearMonth.d.ts} +1 -1
  43. package/dist/dt/classes/{yearMonth.js → YearMonth.js} +2 -2
  44. package/dist/dt/classes/{zoned.d.ts → Zoned.d.ts} +1 -1
  45. package/dist/dt/classes/{zoned.js → Zoned.js} +9 -3
  46. package/dist/dt/functions/buildLocaleFromIntl.js +1 -1
  47. package/dist/dt/functions/guessFormat.js +1 -1
  48. package/dist/dt/functions/intl-weekinfo-polyfill.js +11 -4
  49. package/dist/dt/functions/parse.js +20 -22
  50. package/dist/dt/functions/setupIntl.js +33 -44
  51. package/dist/dt.d.ts +1 -1
  52. package/dist/dt.js +9 -8
  53. package/dist/env.d.ts +1 -1
  54. package/dist/env.js +6 -7
  55. package/dist/fn/ajax/abort.js +1 -1
  56. package/dist/fn/ajax/ajax.d.ts +1 -1
  57. package/dist/fn/ajax/ajax.js +2 -2
  58. package/dist/fn/ajax/download.js +1 -1
  59. package/dist/fn/ajax/getFileContent.js +2 -3
  60. package/dist/fn/ajax/link.js +2 -2
  61. package/dist/fn/ajax/stream.js +5 -4
  62. package/dist/fn/browser/executeSlowly.js +11 -22
  63. package/dist/fn/browser/log.js +5 -3
  64. package/dist/fn/browser/yieldToBrowser.js +7 -19
  65. package/dist/fn/html/makeReactive.js +2 -2
  66. package/dist/fn/init.d.ts +1 -1
  67. package/dist/fn/init.js +4 -5
  68. package/dist/fn/object/_filter.js +3 -2
  69. package/dist/fn/object/filter.js +2 -1
  70. package/dist/fn/phone/fphone.js +1 -2
  71. package/dist/fn/string/cast.js +1 -2
  72. package/dist/fn/string/shorten.js +1 -1
  73. package/dist/fn/string/treatForHash.js +1 -1
  74. package/dist/fn/style/addColors.d.ts +1 -1
  75. package/dist/fn/style/addColors.js +4 -4
  76. package/dist/fn/type/checkType.js +1 -2
  77. package/dist/fn/type/isCp.js +1 -2
  78. package/dist/fn/type/isHostname.js +1 -1
  79. package/dist/fn/type/isIP.js +1 -1
  80. package/dist/fn/type/isSame.js +2 -2
  81. package/dist/fn/type/isURL.js +1 -1
  82. package/dist/index-no-dep.js +11 -4
  83. package/dist/index.js +13 -4
  84. package/package.json +1 -1
  85. package/dist/dt/classes/duration.js +0 -199
  86. /package/dist/dt/classes/{duration.d.ts → Duration.d.ts} +0 -0
@@ -1,15 +1,3 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _bbnDt_value;
13
1
  import { Temporal } from 'temporal-polyfill';
14
2
  import { unitsCorrespondence, units, formatsMap } from '../vars/units.js';
15
3
  import _ from '../../_.js';
@@ -17,40 +5,20 @@ import substr from '../../fn/string/substr.js';
17
5
  import each from '../../fn/loop/each.js';
18
6
  import getRow from '../../fn/object/getRow.js';
19
7
  import isPrimitive from '../../fn/type/isPrimitive.js';
20
- import bbnDtDuration from './duration.js';
8
+ import bbnDtDuration from './Duration.js';
21
9
  export class bbnDt {
10
+ __bbnNoData = true;
11
+ __isBbnDt = true;
12
+ #value;
13
+ isValid;
14
+ defaultValue;
22
15
  constructor(value) {
23
- this.__bbnNoData = true;
24
- this.__isBbnDt = true;
25
- _bbnDt_value.set(this, void 0);
26
- this.getWeekdayIndex = (name, locale) => {
27
- const loc = locale || bbn.env.lang;
28
- const input = name.trim().toLowerCase();
29
- // Build a localized map only once per locale (optional optimization)
30
- const langs = [loc, ...navigator.languages];
31
- for (let i = 0; i < langs.length; i++) {
32
- if (!langs[i]) {
33
- continue;
34
- }
35
- const formatter = new Intl.DateTimeFormat(langs[i], { weekday: "long" });
36
- // Generate localized weekday names for Sun → Sat
37
- for (let i = 0; i < 7; i++) {
38
- // 2023-01-01 was Sunday
39
- const date = new Date(2023, 0, 1 + i);
40
- const localized = formatter.format(date).toLowerCase();
41
- if (localized === input) {
42
- return i; // JS weekday number
43
- }
44
- }
45
- }
46
- throw new Error(`Unknown weekday name '${name}' for locale '${loc}'`);
47
- };
48
16
  Object.defineProperty(this, 'isValid', {
49
17
  value: true,
50
18
  writable: false,
51
19
  configurable: true
52
20
  });
53
- __classPrivateFieldSet(this, _bbnDt_value, value, "f");
21
+ this.#value = value;
54
22
  const d = new Date();
55
23
  Object.defineProperty(this, 'defaultValue', {
56
24
  value: {
@@ -74,11 +42,13 @@ export class bbnDt {
74
42
  });
75
43
  }
76
44
  get value() {
77
- return __classPrivateFieldGet(this, _bbnDt_value, "f");
45
+ return this.#value;
78
46
  }
79
47
  get hasFullDate() {
80
48
  return !!this.value && ('year' in this.value) && ('month' in this.value) && ('day' in this.value);
81
49
  }
50
+ /** System time zone ID (e.g. "Europe/Rome") */
51
+ static systemTimeZoneId = Temporal.Now.timeZoneId();
82
52
  /**
83
53
  * Convert this.value (PlainDate, PlainTime, PlainDateTime, YearMonth,
84
54
  * MonthDay, ZonedDateTime) into epoch milliseconds, using the system
@@ -353,8 +323,8 @@ export class bbnDt {
353
323
  }
354
324
  // ---- Serialization ----
355
325
  toJSON() {
356
- if (__classPrivateFieldGet(this, _bbnDt_value, "f") && 'toZonedDateTime' in __classPrivateFieldGet(this, _bbnDt_value, "f")) {
357
- const zdt = __classPrivateFieldGet(this, _bbnDt_value, "f").toZonedDateTime(bbnDt.systemTimeZoneId);
326
+ if (this.#value && 'toZonedDateTime' in this.#value) {
327
+ const zdt = this.#value.toZonedDateTime(bbnDt.systemTimeZoneId);
358
328
  const zdt2 = zdt.withTimeZone('UTC');
359
329
  return bbn.dt(zdt2).format('YYYY-MM-DDTHH:II:SS.SSS') + 'Z';
360
330
  }
@@ -837,7 +807,7 @@ export class bbnDt {
837
807
  this.parse(value, format);
838
808
  return true;
839
809
  }
840
- catch (_a) {
810
+ catch {
841
811
  return false;
842
812
  }
843
813
  }
@@ -876,6 +846,28 @@ export class bbnDt {
876
846
  const base = new Date(2023, 0, 1 + n);
877
847
  return base.toLocaleDateString([locale || bbn.env.lang, ...navigator.languages], { weekday: m });
878
848
  }
849
+ getWeekdayIndex = (name, locale) => {
850
+ const loc = locale || bbn.env.lang;
851
+ const input = name.trim().toLowerCase();
852
+ // Build a localized map only once per locale (optional optimization)
853
+ const langs = [loc, ...navigator.languages];
854
+ for (let i = 0; i < langs.length; i++) {
855
+ if (!langs[i]) {
856
+ continue;
857
+ }
858
+ const formatter = new Intl.DateTimeFormat(langs[i], { weekday: "long" });
859
+ // Generate localized weekday names for Sun → Sat
860
+ for (let i = 0; i < 7; i++) {
861
+ // 2023-01-01 was Sunday
862
+ const date = new Date(2023, 0, 1 + i);
863
+ const localized = formatter.format(date).toLowerCase();
864
+ if (localized === input) {
865
+ return i; // JS weekday number
866
+ }
867
+ }
868
+ }
869
+ throw new Error(`Unknown weekday name '${name}' for locale '${loc}'`);
870
+ };
879
871
  /**
880
872
  * Returns a NEW date that is the next (or previous if past=true)
881
873
  * occurrence of the given weekday, starting from this.#value.
@@ -1008,7 +1000,6 @@ export class bbnDt {
1008
1000
  : _('The same %s', u);
1009
1001
  }
1010
1002
  startOf(unit = 'd') {
1011
- var _a, _b;
1012
1003
  const u = unitsCorrespondence[unit] || unit;
1013
1004
  if (!u) {
1014
1005
  throw new Error('Invalid unit for startOf: ' + unit);
@@ -1045,7 +1036,7 @@ export class bbnDt {
1045
1036
  const diffToMonday = dow - 1; // 0 for Monday
1046
1037
  const newDate = d.subtract({ days: diffToMonday });
1047
1038
  if ('toPlainDateTime' in v) {
1048
- v = zeroTime(newDate.toPlainDateTime((_b = (_a = v.toPlainTime) === null || _a === void 0 ? void 0 : _a.call(v)) !== null && _b !== void 0 ? _b : Temporal.PlainTime.from('00:00')));
1039
+ v = zeroTime(newDate.toPlainDateTime(v.toPlainTime?.() ?? Temporal.PlainTime.from('00:00')));
1049
1040
  }
1050
1041
  else {
1051
1042
  v = newDate; // PlainDate case
@@ -1230,7 +1221,4 @@ export class bbnDt {
1230
1221
  return this.unix(true);
1231
1222
  }
1232
1223
  }
1233
- _bbnDt_value = new WeakMap();
1234
- /** System time zone ID (e.g. "Europe/Rome") */
1235
- bbnDt.systemTimeZoneId = Temporal.Now.timeZoneId();
1236
1224
  export default bbnDt;
@@ -0,0 +1,193 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ import { units, unitsCorrespondence } from '../vars/units.js';
3
+ import getRow from '../../fn/object/getRow.js';
4
+ const DURATION_RELATIVE_TO = Temporal.ZonedDateTime.from('1970-01-01T00:00Z[UTC]');
5
+ export default class bbnDtDuration {
6
+ #value;
7
+ #unit;
8
+ static fromUnit(value, unit) {
9
+ const realUnit = unitsCorrespondence[unit] || 'ms';
10
+ if (!realUnit) {
11
+ throw new Error('Invalid unit for duration: ' + unit);
12
+ }
13
+ const ctx = [
14
+ realUnit === 'y' ? value : 0,
15
+ realUnit === 'm' ? value : 0,
16
+ realUnit === 'w' ? value : 0,
17
+ realUnit === 'd' ? value : 0,
18
+ realUnit === 'h' ? value : 0,
19
+ realUnit === 'i' ? value : 0,
20
+ realUnit === 's' ? value : 0,
21
+ ['y', 'm', 'w', 'd', 'h', 'i', 's'].includes(realUnit) ? 0 : value
22
+ ];
23
+ const dur = new Temporal.Duration(...ctx);
24
+ return new bbnDtDuration(dur);
25
+ }
26
+ constructor(y, m, w, d, h, i, s, ms, unit) {
27
+ if (y instanceof Temporal.Duration) {
28
+ this.#value = y;
29
+ }
30
+ else if (typeof y === 'object') {
31
+ this.#value = new Temporal.Duration(y.years || 0, y.months || 0, y.weeks || 0, y.days || 0, y.hours || 0, y.minutes || 0, y.seconds || 0, y.milliseconds || 0, 0, 0);
32
+ }
33
+ else {
34
+ this.#value = new Temporal.Duration(y || 0, m || 0, w || 0, d || 0, h || 0, i || 0, s || 0, ms || 0, 0, 0);
35
+ }
36
+ const realUnit = unitsCorrespondence[unit || ''] || unit;
37
+ this.#unit = realUnit || 'ms';
38
+ const row = getRow(units, (a) => a[0] === realUnit);
39
+ if (!row) {
40
+ //throw new Error('Invalid unit for duration: ' + realUnit);
41
+ }
42
+ Object.defineProperty(this, 'isValid', {
43
+ value: false,
44
+ writable: false,
45
+ configurable: true
46
+ });
47
+ }
48
+ setValid(isValid) {
49
+ Object.defineProperty(this, 'isValid', {
50
+ value: isValid,
51
+ writable: false,
52
+ configurable: false
53
+ });
54
+ }
55
+ get value() {
56
+ return this.#value;
57
+ }
58
+ /**
59
+ * Internal helper for remaining or total whole units, using Temporal.Duration.
60
+ *
61
+ * - remaining = false → total number of those units (floored),
62
+ * using Duration.total() with a fixed relativeTo.
63
+ * - remaining = true → returns the "component" for that unit from #value
64
+ * (years, months, weeks, days, hours, minutes, seconds).
65
+ */
66
+ #getUnitValue(name, remaining) {
67
+ const d = this.#value; // Temporal.Duration
68
+ if (remaining) {
69
+ switch (name) {
70
+ case 'year': return d.years;
71
+ case 'month': return d.months;
72
+ case 'week': return d.weeks;
73
+ case 'day': return d.days;
74
+ case 'hour': return d.hours;
75
+ case 'minute': return d.minutes;
76
+ case 'second':
77
+ // seconds component only; sub-second parts go to milliseconds in toJSON()
78
+ return d.seconds;
79
+ }
80
+ }
81
+ // Total units: use Duration.total()
82
+ const total = d.total({
83
+ unit: name,
84
+ relativeTo: DURATION_RELATIVE_TO
85
+ });
86
+ // Keep same semantics as old code (Math.floor on totals)
87
+ return Math.floor(total);
88
+ }
89
+ // -----------------------
90
+ // Public getters
91
+ // -----------------------
92
+ years(remaining = false) { return this.#getUnitValue('year', remaining); }
93
+ months(remaining = false) { return this.#getUnitValue('month', remaining); }
94
+ weeks(remaining = false) { return this.#getUnitValue('week', remaining); }
95
+ days(remaining = false) { return this.#getUnitValue('day', remaining); }
96
+ hours(remaining = false) { return this.#getUnitValue('hour', remaining); }
97
+ minutes(remaining = false) { return this.#getUnitValue('minute', remaining); }
98
+ seconds(remaining = false) { return this.#getUnitValue('second', remaining); }
99
+ // -----------------------
100
+ // Day.js style
101
+ // "asX" conversions
102
+ // -----------------------
103
+ toJSON() {
104
+ return this.value.toJSON();
105
+ }
106
+ /**
107
+ * Returns the full duration expressed as X (float), like Day.js.
108
+ */
109
+ asYears() {
110
+ return this.#value.total({
111
+ unit: 'year',
112
+ relativeTo: DURATION_RELATIVE_TO
113
+ });
114
+ }
115
+ asMonths() {
116
+ return this.#value.total({
117
+ unit: 'month',
118
+ relativeTo: DURATION_RELATIVE_TO
119
+ });
120
+ }
121
+ asWeeks() {
122
+ return this.#value.total({
123
+ unit: 'week',
124
+ relativeTo: DURATION_RELATIVE_TO
125
+ });
126
+ }
127
+ asDays() {
128
+ return this.#value.total({
129
+ unit: 'day',
130
+ relativeTo: DURATION_RELATIVE_TO
131
+ });
132
+ }
133
+ asHours() {
134
+ return this.#value.total({
135
+ unit: 'hour',
136
+ relativeTo: DURATION_RELATIVE_TO
137
+ });
138
+ }
139
+ asMinutes() {
140
+ return this.#value.total({
141
+ unit: 'minute',
142
+ relativeTo: DURATION_RELATIVE_TO
143
+ });
144
+ }
145
+ asSeconds() {
146
+ return this.#value.total({
147
+ unit: 'second',
148
+ relativeTo: DURATION_RELATIVE_TO
149
+ });
150
+ }
151
+ /**
152
+ * Add any unit (or instance default).
153
+ */
154
+ add(value, unit) {
155
+ let targetUnit = this.#unit;
156
+ if (unit) {
157
+ if (unitsCorrespondence[unit]) {
158
+ const realUnit = getRow(units, (a) => a[0] === unitsCorrespondence[unit]);
159
+ if (realUnit) {
160
+ targetUnit = realUnit[1];
161
+ }
162
+ }
163
+ else {
164
+ targetUnit = unit;
165
+ }
166
+ }
167
+ // Map to Temporal.DurationLike field name, e.g. 'year' → 'years'
168
+ const field = (targetUnit + 's');
169
+ if (!['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'].includes(field)) {
170
+ throw new Error('Invalid unit for duration: ' + (unit ?? targetUnit));
171
+ }
172
+ const delta = { [field]: value };
173
+ const newDuration = this.#value.add(delta);
174
+ // Adapt this constructor call to however you now construct your duration:
175
+ return new bbnDtDuration(newDuration, undefined, undefined, undefined, undefined, undefined, undefined, undefined, this.#unit);
176
+ }
177
+ subtract(value, unit) {
178
+ return this.add(-value, unit);
179
+ }
180
+ toMilliseconds() {
181
+ const d = this.#value;
182
+ // If there are no calendar units, we can let Temporal do it directly:
183
+ if (!d.years && !d.months && !d.weeks && !d.days) {
184
+ return d.total({ unit: 'millisecond' });
185
+ }
186
+ // Otherwise we must supply a relativeTo (same as in asX)
187
+ return d.total({
188
+ unit: 'millisecond',
189
+ relativeTo: DURATION_RELATIVE_TO
190
+ });
191
+ }
192
+ }
193
+ ;
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
- import bbnDt from './dt.js';
2
+ import bbnDt from './Dt.js';
3
3
  export default class bbnDtMonthDay extends bbnDt<Temporal.PlainMonthDay> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(m?: any, d?: number);
@@ -1,6 +1,7 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
- import bbnDt from './dt.js';
2
+ import bbnDt from './Dt.js';
3
3
  export default class bbnDtMonthDay extends bbnDt {
4
+ kind = 'monthDay';
4
5
  constructor(m, d) {
5
6
  let value;
6
7
  if (!m) {
@@ -26,7 +27,6 @@ export default class bbnDtMonthDay extends bbnDt {
26
27
  value = new Temporal.PlainMonthDay(m, d);
27
28
  }
28
29
  super(value);
29
- this.kind = 'monthDay';
30
30
  }
31
31
  fdate(long = false, withTime = false, weekday = false) {
32
32
  if (!this.value) {
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
- import bbnDt from './dt.js';
2
+ import bbnDt from './Dt.js';
3
3
  export default class bbnDtTime extends bbnDt<Temporal.PlainTime> {
4
4
  readonly kind: 'time';
5
5
  constructor(h?: any, i?: number, s?: number, ms?: number);
@@ -1,6 +1,7 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
- import bbnDt from './dt.js';
2
+ import bbnDt from './Dt.js';
3
3
  export default class bbnDtTime extends bbnDt {
4
+ kind = 'time';
4
5
  constructor(h, i, s, ms) {
5
6
  let value;
6
7
  if (!h) {
@@ -31,7 +32,6 @@ export default class bbnDtTime extends bbnDt {
31
32
  value = new Temporal.PlainTime(h, i || 0, s || 0, ms || 0);
32
33
  }
33
34
  super(value);
34
- this.kind = 'time';
35
35
  }
36
36
  ftime(withSeconds = false) {
37
37
  if (!this.value) {
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
- import bbnDt from './dt.js';
2
+ import bbnDt from './Dt.js';
3
3
  export default class bbnDtYearMonth extends bbnDt<Temporal.PlainYearMonth> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(y?: any, m?: number);
@@ -1,7 +1,8 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
- import bbnDt from './dt.js';
2
+ import bbnDt from './Dt.js';
3
3
  import getRow from '../../fn/object/getRow.js';
4
4
  export default class bbnDtYearMonth extends bbnDt {
5
+ kind = 'yearMonth';
5
6
  constructor(y, m) {
6
7
  let value;
7
8
  if (!y) {
@@ -27,7 +28,6 @@ export default class bbnDtYearMonth extends bbnDt {
27
28
  value = new Temporal.PlainYearMonth(y, m);
28
29
  }
29
30
  super(value);
30
- this.kind = 'yearMonth';
31
31
  }
32
32
  format(format) {
33
33
  // long
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
- import bbnDt from './dt.js';
2
+ import bbnDt from './Dt.js';
3
3
  export default class bbnDtZoned extends bbnDt<Temporal.ZonedDateTime> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(z?: any, y?: any, m?: number, d?: number, h?: number, i?: number, s?: number, ms?: number);
@@ -1,7 +1,8 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import fromJsDate from '../functions/fromJsDate.js';
3
- import bbnDt from './dt.js';
3
+ import bbnDt from './Dt.js';
4
4
  export default class bbnDtZoned extends bbnDt {
5
+ kind = 'zoned';
5
6
  constructor(z, y, m, d, h, i, s, ms) {
6
7
  let value;
7
8
  if (!z) {
@@ -27,14 +28,19 @@ export default class bbnDtZoned extends bbnDt {
27
28
  value = dt.toZonedDateTime(z || Temporal.Now.timeZoneId());
28
29
  }
29
30
  super(value);
30
- this.kind = 'zoned';
31
31
  }
32
32
  fdate(long = false, withTime = false, weekday = false) {
33
33
  if (!this.value) {
34
34
  return '';
35
35
  }
36
36
  const date = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second());
37
- const opt = Object.assign(Object.assign({ year: 'numeric', month: long ? 'long' : 'numeric', day: 'numeric' }, (weekday ? { weekday: (long ? 'long' : 'short') } : {})), (withTime ? { hour: (long ? '2-digit' : 'numeric'), minute: '2-digit' } : {}));
37
+ const opt = {
38
+ year: 'numeric',
39
+ month: long ? 'long' : 'numeric',
40
+ day: 'numeric',
41
+ ...(weekday ? { weekday: (long ? 'long' : 'short') } : {}),
42
+ ...(withTime ? { hour: (long ? '2-digit' : 'numeric'), minute: '2-digit' } : {})
43
+ };
38
44
  const d = new Intl.DateTimeFormat([bbn.env.lang, ...navigator.languages], opt);
39
45
  return d.format(date);
40
46
  }
@@ -207,7 +207,7 @@ const getCommonFormatsForLocale = (lng) => {
207
207
  // ---- 3) DATETIME: only full dates (Y-M-D ± weekday) × time
208
208
  for (const dOpts of fullDateOptions) {
209
209
  for (const tOpts of timeOptionsList) {
210
- const opts = Object.assign(Object.assign({}, dOpts), tOpts);
210
+ const opts = { ...dOpts, ...tOpts };
211
211
  const fmt = new Intl.DateTimeFormat(lng, opts);
212
212
  const parts = fmt.formatToParts(sample);
213
213
  const resolved = fmt.resolvedOptions();
@@ -48,7 +48,7 @@ export default function guessFormat(input, formats, lng) {
48
48
  parse(str, fmt);
49
49
  return fmt;
50
50
  }
51
- catch (_a) {
51
+ catch {
52
52
  // ignore, we'll maybe try a relaxed version
53
53
  }
54
54
  }
@@ -11,7 +11,7 @@
11
11
  /* Helpers */
12
12
  /* -------------------------------------------------------------------------- */
13
13
  function parseLocaleTag(tag) {
14
- const str = String(tag !== null && tag !== void 0 ? tag : '');
14
+ const str = String(tag ?? '');
15
15
  const parts = str.split('-').filter(Boolean);
16
16
  if (!parts.length) {
17
17
  return { language: 'und' };
@@ -32,8 +32,9 @@ function parseLocaleTag(tag) {
32
32
  }
33
33
  const REGION_WEEK_INFO = globalThis.document ? import('../data/weekinfo-overrides.js') : {};
34
34
  function computeWeekInfo(localeInstance) {
35
- var _a, _b, _c;
36
- const tag = (_c = (_a = localeInstance.baseName) !== null && _a !== void 0 ? _a : (_b = localeInstance.toString) === null || _b === void 0 ? void 0 : _b.call(localeInstance)) !== null && _c !== void 0 ? _c : 'und';
35
+ const tag = localeInstance.baseName ??
36
+ localeInstance.toString?.() ??
37
+ 'und';
37
38
  const { region } = parseLocaleTag(tag);
38
39
  const info = (region && REGION_WEEK_INFO[region]) || {
39
40
  firstDay: 1,
@@ -56,9 +57,15 @@ function ensureIntlLocalePolyfill() {
56
57
  const hasNativeLocale = typeof Intl.Locale === 'function';
57
58
  if (!hasNativeLocale) {
58
59
  class PolyfilledLocale {
60
+ _tag;
61
+ _language;
62
+ _script;
63
+ _region;
64
+ minimize;
65
+ maximize;
59
66
  constructor(tag) {
60
67
  const t = Array.isArray(tag) ? tag[0] : tag;
61
- const str = String(t !== null && t !== void 0 ? t : 'und');
68
+ const str = String(t ?? 'und');
62
69
  const parsed = parseLocaleTag(str);
63
70
  this._tag = str;
64
71
  this._language = parsed.language;
@@ -1,21 +1,20 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import buildLocaleFromIntl from './buildLocaleFromIntl.js';
3
- import bbnDtZoned from '../classes/zoned.js';
4
- import bbnDtDateTime from '../classes/dateTime.js';
5
- import bbnDtDate from '../classes/date.js';
6
- import bbnDtTime from '../classes/time.js';
7
- import bbnDtYearMonth from '../classes/yearMonth.js';
8
- import bbnDtMonthDay from '../classes/monthDay.js';
3
+ import bbnDtZoned from '../classes/Zoned.js';
4
+ import bbnDtDateTime from '../classes/DateTime.js';
5
+ import bbnDtDate from '../classes/Date.js';
6
+ import bbnDtTime from '../classes/Time.js';
7
+ import bbnDtYearMonth from '../classes/YearMonth.js';
8
+ import bbnDtMonthDay from '../classes/MonthDay.js';
9
9
  const lc = function (str, localeCode) {
10
10
  try {
11
11
  return localeCode ? str.toLocaleLowerCase(localeCode) : str.toLowerCase();
12
12
  }
13
- catch (_a) {
13
+ catch {
14
14
  return str.toLowerCase();
15
15
  }
16
16
  };
17
17
  export default function parse(input, format, cls = 'auto', force, locale) {
18
- var _a, _b, _c, _d, _e, _f, _g;
19
18
  buildLocaleFromIntl();
20
19
  const T = Temporal;
21
20
  if (!T) {
@@ -23,16 +22,16 @@ export default function parse(input, format, cls = 'auto', force, locale) {
23
22
  }
24
23
  let isValid = true;
25
24
  if (!locale) {
26
- locale = ((_a = bbn === null || bbn === void 0 ? void 0 : bbn.dt) === null || _a === void 0 ? void 0 : _a.locales) || {};
25
+ locale = bbn?.dt?.locales || {};
27
26
  }
28
27
  const loc = {
29
- monthsLong: (_b = locale === null || locale === void 0 ? void 0 : locale.monthsLong) !== null && _b !== void 0 ? _b : bbn.dt.locales.monthsLong,
30
- monthsShort: (_c = locale === null || locale === void 0 ? void 0 : locale.monthsShort) !== null && _c !== void 0 ? _c : bbn.dt.locales.monthsShort,
31
- weekdaysLong: (_d = locale === null || locale === void 0 ? void 0 : locale.weekdaysLong) !== null && _d !== void 0 ? _d : bbn.dt.locales.weekdaysLong,
32
- weekdaysShort: (_e = locale === null || locale === void 0 ? void 0 : locale.weekdaysShort) !== null && _e !== void 0 ? _e : bbn.dt.locales.weekdaysShort
28
+ monthsLong: locale?.monthsLong ?? bbn.dt.locales.monthsLong,
29
+ monthsShort: locale?.monthsShort ?? bbn.dt.locales.monthsShort,
30
+ weekdaysLong: locale?.weekdaysLong ?? bbn.dt.locales.weekdaysLong,
31
+ weekdaysShort: locale?.weekdaysShort ?? bbn.dt.locales.weekdaysShort
33
32
  };
34
- const localeCode = ((bbn === null || bbn === void 0 ? void 0 : bbn.env) && ((_f = bbn.env) === null || _f === void 0 ? void 0 : _f.lang)) ||
35
- ((bbn === null || bbn === void 0 ? void 0 : bbn.dt) && ((_g = bbn.dt) === null || _g === void 0 ? void 0 : _g.locale)) ||
33
+ const localeCode = (bbn?.env && bbn.env?.lang) ||
34
+ (bbn?.dt && bbn.dt?.locale) ||
36
35
  Intl.DateTimeFormat().resolvedOptions().locale;
37
36
  const escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
38
37
  const makeTokenSpecs = () => [
@@ -476,7 +475,6 @@ export default function parse(input, format, cls = 'auto', force, locale) {
476
475
  }
477
476
  ];
478
477
  function parseWithFormat(fmt, cls = 'auto') {
479
- var _a;
480
478
  const currentDate = new bbnDtDateTime();
481
479
  const ctx = {
482
480
  year: currentDate.year(),
@@ -603,9 +601,9 @@ export default function parse(input, format, cls = 'auto', force, locale) {
603
601
  if (isClsZoned || (hasZone && isClsAuto)) {
604
602
  let pdt;
605
603
  try {
606
- pdt = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
604
+ pdt = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1_000_000);
607
605
  }
608
- catch (_b) {
606
+ catch {
609
607
  throw new Error('Invalid date/time components');
610
608
  }
611
609
  if (ctx.timeZone) {
@@ -615,7 +613,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
615
613
  }
616
614
  else {
617
615
  const utcMs = Date.UTC(ctx.year, ctx.month - 1, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms);
618
- const epochMs = utcMs - ((_a = ctx.offsetMinutes) !== null && _a !== void 0 ? _a : 0) * 60000;
616
+ const epochMs = utcMs - (ctx.offsetMinutes ?? 0) * 60_000;
619
617
  dtObj = new bbnDtZoned(T.Instant.fromEpochMilliseconds(epochMs).toZonedDateTimeISO(T.Now.timeZoneId()));
620
618
  }
621
619
  }
@@ -624,7 +622,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
624
622
  if (!hasFullDate && !isValid) {
625
623
  throw new Error('PlainDateTime requires year, month and day');
626
624
  }
627
- const d = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
625
+ const d = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1_000_000);
628
626
  dtObj = new bbnDtDateTime(d);
629
627
  }
630
628
  else if (isClsDate || isClsYearMonth || isClsMonthDay || (isClsAuto && hasDate && !hasTime)) {
@@ -649,7 +647,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
649
647
  }
650
648
  }
651
649
  else if (isClsTime || (isClsAuto && !hasDate && hasTime)) {
652
- const d = new T.PlainTime(ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
650
+ const d = new T.PlainTime(ctx.hour, ctx.minute, ctx.second, ctx.ms * 1_000_000);
653
651
  dtObj = new bbnDtTime(d);
654
652
  }
655
653
  else {
@@ -668,7 +666,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
668
666
  lastError = e;
669
667
  }
670
668
  }
671
- throw lastError !== null && lastError !== void 0 ? lastError : new Error('No format matched');
669
+ throw lastError ?? new Error('No format matched');
672
670
  }
673
671
  return parseWithFormat(format, cls);
674
672
  }