@bbn/bbn 2.0.42 → 2.0.44

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.
@@ -9,14 +9,17 @@ function partsToPattern(parts, resolved, requestedOpts) {
9
9
  const hourCycle = resolved.hourCycle;
10
10
  const hasDayPeriod = parts.some(p => p.type === 'dayPeriod');
11
11
  const is12h = hasDayPeriod || hourCycle === 'h12' || hourCycle === 'h11';
12
- // ALL NUMERIC (not 2-digit): year, month and day resolved as "numeric"
13
- const allNumericNonPadded = resolved.year === 'numeric' &&
14
- resolved.month === 'numeric' &&
15
- resolved.day === 'numeric';
12
+ const hasYear = !!requestedOpts.year;
13
+ const hasMonth = !!requestedOpts.month;
14
+ const hasDay = !!requestedOpts.day;
15
+ const hasWeekday = !!requestedOpts.weekday;
16
+ const hasTextMonth = requestedOpts.month === 'short' || requestedOpts.month === 'long';
17
+ // "Whole numeric date" = year+month+day, all numeric, no weekday, no text month
18
+ const isWholeNumericDate = hasYear && hasMonth && hasDay && !hasWeekday && !hasTextMonth;
16
19
  for (const p of parts) {
17
20
  switch (p.type) {
18
21
  case 'year': {
19
- // Use YY only if locale actually resolved 2-digit
22
+ // Keep YY when the locale actually resolved to 2-digit
20
23
  if (resolved.year === '2-digit') {
21
24
  pattern += 'YY';
22
25
  }
@@ -31,24 +34,23 @@ function partsToPattern(parts, resolved, requestedOpts) {
31
34
  pattern += requestedOpts.month === 'long' ? 'MMMM' : 'MMM';
32
35
  break;
33
36
  }
34
- // ALL NUMERIC and non-padded → always use M
35
- if (allNumericNonPadded) {
37
+ if (isWholeNumericDate) {
38
+ // whole numeric date → always use M (accepts 1–2 digits)
36
39
  pattern += 'M';
37
40
  break;
38
41
  }
39
- // numeric / 2-digit generic case
42
+ // other numeric month cases (e.g. year–month or month–day)
40
43
  if (/^\d+$/.test(p.value)) {
41
44
  pattern += p.value.length === 2 ? 'MM' : 'M';
42
45
  }
43
46
  else {
44
- // fallback (shouldn't really happen without text month)
45
47
  pattern += p.value.length > 3 ? 'MMMM' : 'MMM';
46
48
  }
47
49
  break;
48
50
  }
49
51
  case 'day': {
50
- // ALL NUMERIC and non-padded → always use D
51
- if (allNumericNonPadded) {
52
+ if (isWholeNumericDate) {
53
+ // whole numeric date → always use D (accepts 1–2 digits)
52
54
  pattern += 'D';
53
55
  break;
54
56
  }
@@ -89,15 +91,9 @@ function partsToPattern(parts, resolved, requestedOpts) {
89
91
  pattern += 'z';
90
92
  break;
91
93
  case 'literal': {
92
- // Wrap literals in [ ... ] so your parser won't confuse them with tokens
93
94
  if (p.value.length) {
94
- if (![' ', ',', '/', '-', ':', '.'].includes(p.value)) {
95
- const v = p.value.replace(/]/g, '\\]');
96
- pattern += `[${v}]`;
97
- }
98
- else {
99
- pattern += p.value;
100
- }
95
+ const v = p.value.replace(/]/g, '\\]');
96
+ pattern += `[${v}]`;
101
97
  }
102
98
  break;
103
99
  }
@@ -1,6 +1,14 @@
1
1
  import buildLocaleFromIntl from './buildLocaleFromIntl.js';
2
+ const lc = function (str, localeCode) {
3
+ try {
4
+ return localeCode ? str.toLocaleLowerCase(localeCode) : str.toLowerCase();
5
+ }
6
+ catch (_a) {
7
+ return str.toLowerCase();
8
+ }
9
+ };
2
10
  export default function parse(input, format, locale) {
3
- var _a, _b, _c, _d;
11
+ var _a, _b, _c, _d, _e, _f;
4
12
  buildLocaleFromIntl();
5
13
  const TemporalAny = globalThis.Temporal;
6
14
  if (!TemporalAny) {
@@ -13,6 +21,9 @@ export default function parse(input, format, locale) {
13
21
  weekdaysLong: (_c = locale === null || locale === void 0 ? void 0 : locale.weekdaysLong) !== null && _c !== void 0 ? _c : bbn.dt.locales.weekdaysLong,
14
22
  weekdaysShort: (_d = locale === null || locale === void 0 ? void 0 : locale.weekdaysShort) !== null && _d !== void 0 ? _d : bbn.dt.locales.weekdaysShort
15
23
  };
24
+ const localeCode = ((bbn === null || bbn === void 0 ? void 0 : bbn.env) && ((_e = bbn.env) === null || _e === void 0 ? void 0 : _e.lang)) ||
25
+ ((bbn === null || bbn === void 0 ? void 0 : bbn.dt) && ((_f = bbn.dt) === null || _f === void 0 ? void 0 : _f.locale)) ||
26
+ Intl.DateTimeFormat().resolvedOptions().locale;
16
27
  const escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
17
28
  const makeTokenSpecs = () => [
18
29
  // Years
@@ -46,8 +57,9 @@ export default function parse(input, format, locale) {
46
57
  token: 'MMMM',
47
58
  regex: '[^\\d\\s]+',
48
59
  apply: (v, ctx) => {
60
+ const val = lc(v, localeCode);
49
61
  const idx = loc.monthsLong
50
- .findIndex((m) => m.toLowerCase() === v.toLowerCase());
62
+ .findIndex((m) => lc(m, localeCode) === val);
51
63
  if (idx === -1) {
52
64
  throw new Error('Invalid month name: ' + v);
53
65
  }
@@ -59,8 +71,9 @@ export default function parse(input, format, locale) {
59
71
  token: 'MMM',
60
72
  regex: '[^\\d\\s]+',
61
73
  apply: (v, ctx) => {
74
+ const val = lc(v, localeCode);
62
75
  const idx = loc.monthsShort
63
- .findIndex((m) => m.toLowerCase() === v.toLowerCase());
76
+ .findIndex((m) => lc(m, localeCode) === val);
64
77
  if (idx === -1) {
65
78
  throw new Error('Invalid short month name: ' + v);
66
79
  }
@@ -159,8 +172,9 @@ export default function parse(input, format, locale) {
159
172
  token: 'dddd',
160
173
  regex: '[^\\d\\s]+',
161
174
  apply: (v, ctx) => {
175
+ const val = lc(v, localeCode);
162
176
  const idx = loc.weekdaysLong
163
- .findIndex((w) => w.toLowerCase() === v.toLowerCase());
177
+ .findIndex((w) => lc(w, localeCode) === val);
164
178
  if (idx === -1) {
165
179
  throw new Error('Invalid weekday name: ' + v);
166
180
  }
@@ -171,8 +185,9 @@ export default function parse(input, format, locale) {
171
185
  token: 'ddd',
172
186
  regex: '[^\\d\\s]+',
173
187
  apply: (v, ctx) => {
188
+ const val = lc(v, localeCode);
174
189
  const idx = loc.weekdaysShort
175
- .findIndex((w) => w.toLowerCase() === v.toLowerCase());
190
+ .findIndex((w) => lc(w, localeCode) === val);
176
191
  if (idx === -1) {
177
192
  throw new Error('Invalid short weekday name: ' + v);
178
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.42",
3
+ "version": "2.0.44",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",