@naturalcycles/js-lib 14.139.2 → 14.139.3

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.
@@ -51,7 +51,7 @@ class LocalDate {
51
51
  if (d instanceof LocalDate)
52
52
  return d;
53
53
  // const [year, month, day] = d.slice(0, 10).split('-').map(Number)
54
- const matches = DATE_REGEX.exec(d.slice(0, 10));
54
+ const matches = typeof d === 'string' && DATE_REGEX.exec(d.slice(0, 10));
55
55
  if (!matches)
56
56
  return null;
57
57
  const year = Number(matches[1]);
@@ -60,6 +60,10 @@ class LocalTime {
60
60
  else if (typeof d === 'number') {
61
61
  date = new Date(d * 1000);
62
62
  }
63
+ else if (typeof d !== 'string') {
64
+ // unexpected type, e.g Function or something
65
+ return null;
66
+ }
63
67
  else {
64
68
  date = new Date(d.slice(0, 19));
65
69
  }
@@ -48,7 +48,7 @@ export class LocalDate {
48
48
  if (d instanceof LocalDate)
49
49
  return d;
50
50
  // const [year, month, day] = d.slice(0, 10).split('-').map(Number)
51
- const matches = DATE_REGEX.exec(d.slice(0, 10));
51
+ const matches = typeof d === 'string' && DATE_REGEX.exec(d.slice(0, 10));
52
52
  if (!matches)
53
53
  return null;
54
54
  const year = Number(matches[1]);
@@ -57,6 +57,10 @@ export class LocalTime {
57
57
  else if (typeof d === 'number') {
58
58
  date = new Date(d * 1000);
59
59
  }
60
+ else if (typeof d !== 'string') {
61
+ // unexpected type, e.g Function or something
62
+ return null;
63
+ }
60
64
  else {
61
65
  date = new Date(d.slice(0, 19));
62
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.139.2",
3
+ "version": "14.139.3",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -69,7 +69,7 @@ export class LocalDate {
69
69
  if (d instanceof LocalDate) return d
70
70
 
71
71
  // const [year, month, day] = d.slice(0, 10).split('-').map(Number)
72
- const matches = DATE_REGEX.exec(d.slice(0, 10))
72
+ const matches = typeof (d as any) === 'string' && DATE_REGEX.exec(d.slice(0, 10))
73
73
  if (!matches) return null
74
74
 
75
75
  const year = Number(matches[1])
@@ -82,6 +82,9 @@ export class LocalTime {
82
82
  date = d
83
83
  } else if (typeof d === 'number') {
84
84
  date = new Date(d * 1000)
85
+ } else if (typeof (d as any) !== 'string') {
86
+ // unexpected type, e.g Function or something
87
+ return null
85
88
  } else {
86
89
  date = new Date(d.slice(0, 19))
87
90
  }