@finnair/v-validation-luxon 1.1.0-alpha.7 → 1.1.0-alpha.8

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.1.0-alpha.8](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.7...v1.1.0-alpha.8) (2022-08-19)
7
+
8
+ **Note:** Version bump only for package @finnair/v-validation-luxon
9
+
10
+
11
+
12
+
13
+
6
14
  # [1.1.0-alpha.7](https://github.com/finnair/v-validation/compare/v1.1.0-alpha.6...v1.1.0-alpha.7) (2022-08-18)
7
15
 
8
16
  **Note:** Version bump only for package @finnair/v-validation-luxon
package/dist/Vluxon.d.ts CHANGED
@@ -12,7 +12,7 @@ export interface ValidateLuxonParams {
12
12
  pattern: RegExp;
13
13
  parser: (value: string) => DateTime;
14
14
  }
15
- export declare function validateLuxon({ value, path, ctx, type, proto, pattern, parser }: ValidateLuxonParams): ValidationResult;
15
+ export declare function validateLuxon({ value, path, ctx, type, proto, pattern, parser }: ValidateLuxonParams): Promise<ValidationResult>;
16
16
  export declare class DurationValidator extends Validator {
17
17
  validatePath(value: any, path: Path, ctx: ValidationContext): Promise<ValidationResult>;
18
18
  }
package/dist/Vluxon.js CHANGED
@@ -14,108 +14,98 @@ const v_validation_1 = require("@finnair/v-validation");
14
14
  const luxon_1 = require("luxon");
15
15
  const luxon_2 = require("./luxon");
16
16
  function validateLuxon({ value, path, ctx, type, proto, pattern, parser }) {
17
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
18
- return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
19
- }
20
- if (value instanceof proto) {
21
- return ctx.success(value);
22
- }
23
- else if (luxon_1.DateTime.isDateTime(value)) {
24
- if (value.isValid) {
25
- return ctx.success(new proto(value));
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if ((0, v_validation_1.isNullOrUndefined)(value)) {
19
+ return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
26
20
  }
27
- }
28
- else if ((0, v_validation_1.isString)(value)) {
29
- if (pattern.test(value)) {
30
- const dateTime = parser(value);
31
- if (dateTime.isValid) {
32
- return ctx.success(new proto(dateTime));
21
+ if (value instanceof proto) {
22
+ return ctx.success(value);
23
+ }
24
+ else if (luxon_1.DateTime.isDateTime(value)) {
25
+ if (value.isValid) {
26
+ return ctx.success(new proto(value));
33
27
  }
34
28
  }
35
- }
36
- return ctx.failure(v_validation_1.defaultViolations.date(value, path, type), value);
29
+ else if ((0, v_validation_1.isString)(value)) {
30
+ if (pattern.test(value)) {
31
+ const dateTime = parser(value);
32
+ if (dateTime.isValid) {
33
+ return ctx.success(new proto(dateTime));
34
+ }
35
+ }
36
+ }
37
+ return ctx.failure(v_validation_1.defaultViolations.date(value, path, type), value);
38
+ });
37
39
  }
38
40
  exports.validateLuxon = validateLuxon;
39
41
  const datePattern = /^\d{4}-\d{2}-\d{2}$/;
40
42
  function localDateValidator(value, path, ctx) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- return validateLuxon({
43
- value,
44
- path,
45
- ctx,
46
- type: 'Date',
47
- proto: luxon_2.LocalDateLuxon,
48
- pattern: datePattern,
49
- parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
50
- });
43
+ return validateLuxon({
44
+ value,
45
+ path,
46
+ ctx,
47
+ type: 'Date',
48
+ proto: luxon_2.LocalDateLuxon,
49
+ pattern: datePattern,
50
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
51
51
  });
52
52
  }
53
53
  const timePattern = /^\d{2}:\d{2}:\d{2}$/;
54
54
  function localTimeValidator(value, path, ctx) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- return validateLuxon({
57
- value,
58
- path,
59
- ctx,
60
- type: 'Time',
61
- proto: luxon_2.LocalTimeLuxon,
62
- pattern: timePattern,
63
- parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
64
- });
55
+ return validateLuxon({
56
+ value,
57
+ path,
58
+ ctx,
59
+ type: 'Time',
60
+ proto: luxon_2.LocalTimeLuxon,
61
+ pattern: timePattern,
62
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
65
63
  });
66
64
  }
67
65
  const dateTimePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
68
66
  function dateTimeValidator(value, path, ctx) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- return validateLuxon({
71
- value,
72
- path,
73
- ctx,
74
- type: 'DateTime',
75
- proto: luxon_2.DateTimeLuxon,
76
- pattern: dateTimePattern,
77
- parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
78
- });
67
+ return validateLuxon({
68
+ value,
69
+ path,
70
+ ctx,
71
+ type: 'DateTime',
72
+ proto: luxon_2.DateTimeLuxon,
73
+ pattern: dateTimePattern,
74
+ parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
79
75
  });
80
76
  }
81
77
  function dateTimeUtcValidator(value, path, ctx) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- return validateLuxon({
84
- value,
85
- path,
86
- ctx,
87
- type: 'DateTime',
88
- proto: luxon_2.DateTimeUtcLuxon,
89
- pattern: dateTimePattern,
90
- parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
91
- });
78
+ return validateLuxon({
79
+ value,
80
+ path,
81
+ ctx,
82
+ type: 'DateTime',
83
+ proto: luxon_2.DateTimeUtcLuxon,
84
+ pattern: dateTimePattern,
85
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
92
86
  });
93
87
  }
94
88
  const dateTimeMillisPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
95
89
  function dateTimeMillisValidator(value, path, ctx) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- return validateLuxon({
98
- value,
99
- path,
100
- ctx,
101
- type: 'DateTimeMillis',
102
- proto: luxon_2.DateTimeMillisLuxon,
103
- pattern: dateTimeMillisPattern,
104
- parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
105
- });
90
+ return validateLuxon({
91
+ value,
92
+ path,
93
+ ctx,
94
+ type: 'DateTimeMillis',
95
+ proto: luxon_2.DateTimeMillisLuxon,
96
+ pattern: dateTimeMillisPattern,
97
+ parser: (value) => luxon_1.DateTime.fromISO(value, { setZone: true }),
106
98
  });
107
99
  }
108
100
  function dateTimeMillisUtcValidator(value, path, ctx) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- return validateLuxon({
111
- value,
112
- path,
113
- ctx,
114
- type: 'DateTimeMillis',
115
- proto: luxon_2.DateTimeMillisUtcLuxon,
116
- pattern: dateTimeMillisPattern,
117
- parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
118
- });
101
+ return validateLuxon({
102
+ value,
103
+ path,
104
+ ctx,
105
+ type: 'DateTimeMillis',
106
+ proto: luxon_2.DateTimeMillisUtcLuxon,
107
+ pattern: dateTimeMillisPattern,
108
+ parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
119
109
  });
120
110
  }
121
111
  const durationPattern = /^P(?!$)(\d+(?:\.\d+)?Y)?(\d+(?:\.\d+)?M)?(\d+(?:\.\d+)?W)?(\d+(?:\.\d+)?D)?(T(?=\d)(\d+(?:\.\d+)?H)?(\d+(?:\.\d+)?M)?(\d+(?:\.\d+)?S)?)?$/;
package/dist/luxon.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DateTime, DateTimeJSOptions, DateTimeOptions } from 'luxon';
1
+ import { DateTime, DateTimeJSOptions, DateTimeOptions, Zone } from 'luxon';
2
2
  export declare type LuxonDateTimeInput = DateTime | LuxonDateTime;
3
3
  export declare abstract class LuxonDateTime {
4
4
  readonly dateTime: DateTime;
@@ -19,8 +19,11 @@ export declare class LocalDateLuxon extends LuxonDateTime {
19
19
  static nowLocal(options?: DateTimeJSOptions): LocalDateLuxon;
20
20
  static nowUtc(): LocalDateLuxon;
21
21
  static fromISO(value: string, options?: DateTimeOptions): LocalDateLuxon;
22
- static fromJSDate(date: Date, options?: DateTimeOptions): LocalDateLuxon;
23
- static fromMillis(millis: number, options?: DateTimeOptions): LocalDateLuxon;
22
+ static fromFormat(value: string, format: string, options?: DateTimeOptions): LocalDateLuxon;
23
+ static fromJSDate(date: Date, options?: {
24
+ zone?: string | Zone;
25
+ }): LocalDateLuxon;
26
+ static fromMillis(millis: number, options?: DateTimeJSOptions): LocalDateLuxon;
24
27
  protected normalize(dateTime: DateTime): DateTime;
25
28
  wrap(fn: (dateTime: DateTime) => DateTime): LocalDateLuxon;
26
29
  toJSON(): string;
@@ -31,8 +34,11 @@ export declare class LocalTimeLuxon extends LuxonDateTime {
31
34
  static nowLocal(options?: DateTimeJSOptions): LocalTimeLuxon;
32
35
  static nowUtc(): LocalTimeLuxon;
33
36
  static fromISO(value: string, options?: DateTimeOptions): LocalTimeLuxon;
34
- static fromJSDate(date: Date, options?: DateTimeOptions): LocalTimeLuxon;
35
- static fromMillis(millis: number, options?: DateTimeOptions): LocalTimeLuxon;
37
+ static fromFormat(value: string, format: string, options?: DateTimeOptions): LocalTimeLuxon;
38
+ static fromJSDate(date: Date, options?: {
39
+ zone?: string | Zone;
40
+ }): LocalTimeLuxon;
41
+ static fromMillis(millis: number, options?: DateTimeJSOptions): LocalTimeLuxon;
36
42
  protected normalize(dateTime: DateTime): DateTime;
37
43
  wrap(fn: (dateTime: DateTime) => DateTime): LocalTimeLuxon;
38
44
  toJSON(): string;
@@ -43,8 +49,11 @@ export declare class DateTimeLuxon extends LuxonDateTime {
43
49
  constructor(input: LuxonDateTimeInput);
44
50
  static now(options?: DateTimeJSOptions): DateTimeLuxon;
45
51
  static fromISO(value: string, options?: DateTimeOptions): DateTimeLuxon;
46
- static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeLuxon;
47
- static fromMillis(millis: number, options?: DateTimeOptions): DateTimeLuxon;
52
+ static fromFormat(value: string, format: string, options?: DateTimeOptions): DateTimeLuxon;
53
+ static fromJSDate(date: Date, options?: {
54
+ zone?: string | Zone;
55
+ }): DateTimeLuxon;
56
+ static fromMillis(millis: number, options?: DateTimeJSOptions): DateTimeLuxon;
48
57
  protected normalize(dateTime: DateTime): DateTime;
49
58
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeLuxon;
50
59
  toJSON(): string;
@@ -53,8 +62,11 @@ export declare class DateTimeUtcLuxon extends LuxonDateTime {
53
62
  constructor(input: LuxonDateTimeInput);
54
63
  static now(): DateTimeUtcLuxon;
55
64
  static fromISO(value: string, options?: DateTimeOptions): DateTimeUtcLuxon;
56
- static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeUtcLuxon;
57
- static fromMillis(millis: number, options?: DateTimeOptions): DateTimeUtcLuxon;
65
+ static fromFormat(value: string, format: string, options?: DateTimeOptions): DateTimeUtcLuxon;
66
+ static fromJSDate(date: Date, options?: {
67
+ zone?: string | Zone;
68
+ }): DateTimeUtcLuxon;
69
+ static fromMillis(millis: number, options?: DateTimeJSOptions): DateTimeUtcLuxon;
58
70
  protected normalize(dateTime: DateTime): DateTime;
59
71
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeUtcLuxon;
60
72
  toJSON(): string;
@@ -65,8 +77,11 @@ export declare class DateTimeMillisLuxon extends LuxonDateTime {
65
77
  constructor(input: LuxonDateTimeInput);
66
78
  static now(options?: DateTimeJSOptions): DateTimeMillisLuxon;
67
79
  static fromISO(value: string, options?: DateTimeOptions): DateTimeMillisLuxon;
68
- static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeMillisLuxon;
69
- static fromMillis(millis: number, options?: DateTimeOptions): DateTimeMillisLuxon;
80
+ static fromFormat(value: string, format: string, options?: DateTimeOptions): DateTimeMillisLuxon;
81
+ static fromJSDate(date: Date, options?: {
82
+ zone?: string | Zone;
83
+ }): DateTimeMillisLuxon;
84
+ static fromMillis(millis: number, options?: DateTimeJSOptions): DateTimeMillisLuxon;
70
85
  protected normalize(dateTime: DateTime): DateTime;
71
86
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisLuxon;
72
87
  toJSON(): string;
@@ -75,8 +90,11 @@ export declare class DateTimeMillisUtcLuxon extends LuxonDateTime {
75
90
  constructor(input: LuxonDateTimeInput);
76
91
  static now(): DateTimeMillisUtcLuxon;
77
92
  static fromISO(value: string, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
78
- static fromJSDate(date: Date, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
79
- static fromMillis(millis: number, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
93
+ static fromFormat(value: string, format: string, options?: DateTimeOptions): DateTimeMillisUtcLuxon;
94
+ static fromJSDate(date: Date, options?: {
95
+ zone?: string | Zone;
96
+ }): DateTimeMillisUtcLuxon;
97
+ static fromMillis(millis: number, options?: DateTimeJSOptions): DateTimeMillisUtcLuxon;
80
98
  protected normalize(dateTime: DateTime): DateTime;
81
99
  wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisUtcLuxon;
82
100
  toJSON(): string;
package/dist/luxon.js CHANGED
@@ -46,13 +46,16 @@ class LocalDateLuxon extends LuxonDateTime {
46
46
  return new LocalDateLuxon(luxon_1.DateTime.utc());
47
47
  }
48
48
  static fromISO(value, options) {
49
- return new LocalDateLuxon(luxon_1.DateTime.fromISO(value, options));
49
+ return new LocalDateLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
50
+ }
51
+ static fromFormat(value, format, options) {
52
+ return new LocalDateLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
50
53
  }
51
54
  static fromJSDate(date, options) {
52
- return new LocalDateLuxon(luxon_1.DateTime.fromJSDate(date, options));
55
+ return new LocalDateLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
53
56
  }
54
57
  static fromMillis(millis, options) {
55
- return new LocalDateLuxon(luxon_1.DateTime.fromMillis(millis, options));
58
+ return new LocalDateLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
56
59
  }
57
60
  normalize(dateTime) {
58
61
  return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day);
@@ -77,13 +80,16 @@ class LocalTimeLuxon extends LuxonDateTime {
77
80
  return new LocalTimeLuxon(luxon_1.DateTime.utc());
78
81
  }
79
82
  static fromISO(value, options) {
80
- return new LocalTimeLuxon(luxon_1.DateTime.fromISO(value, options));
83
+ return new LocalTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
84
+ }
85
+ static fromFormat(value, format, options) {
86
+ return new LocalTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
81
87
  }
82
88
  static fromJSDate(date, options) {
83
- return new LocalTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
89
+ return new LocalTimeLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
84
90
  }
85
91
  static fromMillis(millis, options) {
86
- return new LocalTimeLuxon(luxon_1.DateTime.fromMillis(millis, options));
92
+ return new LocalTimeLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
87
93
  }
88
94
  normalize(dateTime) {
89
95
  return luxon_1.DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second);
@@ -107,6 +113,9 @@ class DateTimeLuxon extends LuxonDateTime {
107
113
  static fromISO(value, options) {
108
114
  return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
109
115
  }
116
+ static fromFormat(value, format, options) {
117
+ return new DateTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ setZone: true }, options)));
118
+ }
110
119
  static fromJSDate(date, options) {
111
120
  return new DateTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
112
121
  }
@@ -140,6 +149,9 @@ class DateTimeUtcLuxon extends LuxonDateTime {
140
149
  static fromISO(value, options) {
141
150
  return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
142
151
  }
152
+ static fromFormat(value, format, options) {
153
+ return new DateTimeUtcLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
154
+ }
143
155
  static fromJSDate(date, options) {
144
156
  return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
145
157
  }
@@ -167,6 +179,9 @@ class DateTimeMillisLuxon extends LuxonDateTime {
167
179
  static fromISO(value, options) {
168
180
  return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
169
181
  }
182
+ static fromFormat(value, format, options) {
183
+ return new DateTimeMillisLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ setZone: true }, options)));
184
+ }
170
185
  static fromJSDate(date, options) {
171
186
  return new DateTimeMillisLuxon(luxon_1.DateTime.fromJSDate(date, options));
172
187
  }
@@ -200,6 +215,9 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
200
215
  static fromISO(value, options) {
201
216
  return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
202
217
  }
218
+ static fromFormat(value, format, options) {
219
+ return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
220
+ }
203
221
  static fromJSDate(date, options) {
204
222
  return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
205
223
  }
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const luxon_1 = require("luxon");
4
- console.log(luxon_1.DateTime.fromISO('2022-02-27').set({ day: 31 }).day);
4
+ console.log(luxon_1.DateTime.fromFormat('20220819095432+0', 'yyyyMMddHHmmssZ').toJSON());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finnair/v-validation-luxon",
3
- "version": "1.1.0-alpha.7",
3
+ "version": "1.1.0-alpha.8",
4
4
  "private": false,
5
5
  "description": "Luxon validators",
6
6
  "main": "dist/index.js",
@@ -32,5 +32,5 @@
32
32
  "devDependencies": {
33
33
  "@types/luxon": "3.0.0"
34
34
  },
35
- "gitHead": "b270437f1a403fbb012297653f05d7d6d732fa76"
35
+ "gitHead": "883052983f33664439c1baae629ed5f6d53cbdcb"
36
36
  }