@bbn/bbn 2.0.46 → 2.0.47

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.
@@ -15,6 +15,39 @@ const makeRelaxedNumericFormat = (fmt) => {
15
15
  // Relax DD -> D and MM -> M, but don't touch other tokens
16
16
  return fmt.replace(/DD/g, 'D').replace(/MM/g, 'M');
17
17
  };
18
+ /**
19
+ * If the format is a pure numeric date like D/M/YYYY or DD/MM/YYYY,
20
+ * and the input clearly uses 2-digit day and 2-digit month (22/11/2022),
21
+ * upgrade to DD/MM/YYYY.
22
+ */
23
+ const normalizeNumericDM = (fmt, input) => {
24
+ // Only touch "pure numeric date" patterns: D/M/YYYY, DD-MM-YY, etc.
25
+ // No time tokens, no text months, no weekdays.
26
+ if (/[HhI SAzM]{2,}|[A-Za-z]/.test(fmt.replace(/[DMY]/g, ''))) {
27
+ // If there are other letters than D/M/Y (like MMM, ddd), don't touch.
28
+ // (We only want simple numeric dates)
29
+ return fmt;
30
+ }
31
+ // Quick check: must contain D and M and Y
32
+ if (!fmt.includes('D') || !fmt.includes('M') || !fmt.includes('Y')) {
33
+ return fmt;
34
+ }
35
+ // Extract numeric chunks from the input: ["22", "11", "2022"] for "22/11/2022"
36
+ const nums = input.split(/\D+/).filter(Boolean);
37
+ if (nums.length < 3) {
38
+ return fmt;
39
+ }
40
+ const [dayStr, monthStr] = nums;
41
+ // Only upgrade if both day and month are exactly 2-digit
42
+ if (dayStr.length === 2 && monthStr.length === 2) {
43
+ // Upgrade first D-group to DD and first M-group to MM
44
+ let out = fmt;
45
+ out = out.replace(/D+/, 'DD');
46
+ out = out.replace(/M+/, 'MM');
47
+ return out;
48
+ }
49
+ return fmt;
50
+ };
18
51
  export default function guessFormat(input, formats, lng) {
19
52
  const str = input.trim();
20
53
  if (!str) {
@@ -25,7 +58,7 @@ export default function guessFormat(input, formats, lng) {
25
58
  // 1) Try strict format first
26
59
  try {
27
60
  parse(str, fmt);
28
- return fmt;
61
+ return normalizeNumericDM(fmt, str);
29
62
  }
30
63
  catch (_a) {
31
64
  // ignore, we'll maybe try a relaxed version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.46",
3
+ "version": "2.0.47",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",