@naturalcycles/nodejs-lib 15.122.1 → 15.122.2

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.
@@ -543,10 +543,15 @@ export class JString extends JBuilder {
543
543
  }
544
544
  pattern(pattern, opt) {
545
545
  const clone = this.cloneAndUpdateSchema({ pattern });
546
- if (opt?.name)
547
- clone.setErrorMessage('pattern', `is not a valid ${opt.name}`);
548
- if (opt?.msg)
546
+ if (opt?.msg) {
549
547
  clone.setErrorMessage('pattern', opt.msg);
548
+ }
549
+ else if (opt?.name) {
550
+ clone.setErrorMessage('pattern', `is not a valid ${opt.name}`);
551
+ }
552
+ else {
553
+ clone.setErrorMessage('pattern', 'is not matching the expected pattern');
554
+ }
550
555
  return clone;
551
556
  }
552
557
  minLength(minLength) {
@@ -60,8 +60,13 @@ const MAX_DOS_DATE = new Date(2107, 11, 31, 23, 59, 58);
60
60
  * timestamp is rendered in the local timezone. Out-of-range dates are clamped to 1980-2107.
61
61
  */
62
62
  export function unixToDosDateTime(ts) {
63
- const jsDate = new Date(ts * 1000);
64
- const d = jsDate < MIN_DOS_DATE ? MIN_DOS_DATE : jsDate > MAX_DOS_DATE ? MAX_DOS_DATE : jsDate;
63
+ let d = new Date(ts * 1000);
64
+ if (d < MIN_DOS_DATE) {
65
+ d = MIN_DOS_DATE;
66
+ }
67
+ else if (d > MAX_DOS_DATE) {
68
+ d = MAX_DOS_DATE;
69
+ }
65
70
  const date = (d.getDate() & 0x1f) | // 1-31
66
71
  (((d.getMonth() + 1) & 0x0f) << 5) | // 1-12
67
72
  (((d.getFullYear() - 1980) & 0x7f) << 9); // 1980-2107
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.122.1",
4
+ "version": "15.122.2",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
@@ -734,8 +734,14 @@ export class JString<
734
734
 
735
735
  pattern(pattern: string, opt?: JsonBuilderRuleOpt): this {
736
736
  const clone = this.cloneAndUpdateSchema({ pattern })
737
- if (opt?.name) clone.setErrorMessage('pattern', `is not a valid ${opt.name}`)
738
- if (opt?.msg) clone.setErrorMessage('pattern', opt.msg)
737
+ if (opt?.msg) {
738
+ clone.setErrorMessage('pattern', opt.msg)
739
+ } else if (opt?.name) {
740
+ clone.setErrorMessage('pattern', `is not a valid ${opt.name}`)
741
+ } else {
742
+ clone.setErrorMessage('pattern', 'is not matching the expected pattern')
743
+ }
744
+
739
745
  return clone
740
746
  }
741
747
 
@@ -76,8 +76,12 @@ const MAX_DOS_DATE = new Date(2107, 11, 31, 23, 59, 58)
76
76
  * timestamp is rendered in the local timezone. Out-of-range dates are clamped to 1980-2107.
77
77
  */
78
78
  export function unixToDosDateTime(ts: UnixTimestamp): { date: number; time: number } {
79
- const jsDate = new Date(ts * 1000)
80
- const d = jsDate < MIN_DOS_DATE ? MIN_DOS_DATE : jsDate > MAX_DOS_DATE ? MAX_DOS_DATE : jsDate
79
+ let d = new Date(ts * 1000)
80
+ if (d < MIN_DOS_DATE) {
81
+ d = MIN_DOS_DATE
82
+ } else if (d > MAX_DOS_DATE) {
83
+ d = MAX_DOS_DATE
84
+ }
81
85
 
82
86
  const date =
83
87
  (d.getDate() & 0x1f) | // 1-31