@finnair/v-validation-luxon 4.3.0 → 5.0.0

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,28 @@
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
+ # [5.0.0](https://github.com/finnair/v-validation/compare/v4.3.0...v5.0.0) (2023-10-13)
7
+
8
+
9
+ ### Features
10
+
11
+ * use ECMAScript modules (ESM) instead of CommonJS ([#95](https://github.com/finnair/v-validation/issues/95)) ([92e9118](https://github.com/finnair/v-validation/commit/92e9118235957ec4bc2bcf2de73e195ea940378c))
12
+
13
+
14
+
15
+
16
+
17
+ # [5.0.0](https://github.com/finnair/v-validation/compare/v4.3.0...v5.0.0) (2023-10-13)
18
+
19
+
20
+ ### Features
21
+
22
+ * use ECMAScript modules (ESM) instead of CommonJS ([#95](https://github.com/finnair/v-validation/issues/95)) ([92e9118](https://github.com/finnair/v-validation/commit/92e9118235957ec4bc2bcf2de73e195ea940378c))
23
+
24
+
25
+
26
+
27
+
6
28
  # [4.3.0](https://github.com/finnair/v-validation/compare/v4.2.0...v4.3.0) (2023-10-03)
7
29
 
8
30
  **Note:** Version bump only for package @finnair/v-validation-luxon
package/dist/Vluxon.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ValidationContext, Validator, ValidationResult } from '@finnair/v-validation';
2
2
  import { Path } from '@finnair/path';
3
3
  import { DateTime, DateTimeJSOptions, DateTimeOptions } from 'luxon';
4
- import { LuxonDateTime } from './luxon';
5
- export declare type LuxonInput = string | DateTime | LuxonDateTime;
4
+ import { LuxonDateTime } from './luxon.js';
5
+ export type LuxonInput = string | DateTime | LuxonDateTime;
6
6
  export interface ValidateLuxonParams {
7
7
  type: string;
8
8
  pattern: RegExp;
package/dist/Vluxon.js CHANGED
@@ -1,19 +1,8 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Vluxon = exports.TimeDurationValidator = exports.DurationValidator = exports.validateLuxonNumber = exports.LuxonValidator = void 0;
13
- const v_validation_1 = require("@finnair/v-validation");
14
- const luxon_1 = require("luxon");
15
- const luxon_2 = require("./luxon");
16
- class LuxonValidator extends v_validation_1.Validator {
1
+ import { isNullOrUndefined, defaultViolations, isString, V, Validator, TypeMismatch } from '@finnair/v-validation';
2
+ import { DateTime, Duration, FixedOffsetZone } from 'luxon';
3
+ import { LocalDateLuxon, DateTimeLuxon, DateTimeMillisLuxon, DateTimeMillisUtcLuxon, DateTimeUtcLuxon, LocalTimeLuxon, LocalDateTimeLuxon, } from './luxon.js';
4
+ export class LuxonValidator extends Validator {
5
+ params;
17
6
  constructor(params) {
18
7
  super();
19
8
  this.params = params;
@@ -22,18 +11,18 @@ class LuxonValidator extends v_validation_1.Validator {
22
11
  }
23
12
  validatePath(value, path, ctx) {
24
13
  const params = this.params;
25
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
26
- return ctx.failurePromise(v_validation_1.defaultViolations.notNull(path), value);
14
+ if (isNullOrUndefined(value)) {
15
+ return ctx.failurePromise(defaultViolations.notNull(path), value);
27
16
  }
28
17
  if (params.proto && value instanceof params.proto) {
29
18
  return ctx.successPromise(value);
30
19
  }
31
- else if (luxon_1.DateTime.isDateTime(value)) {
20
+ else if (DateTime.isDateTime(value)) {
32
21
  if (value.isValid) {
33
22
  return success(value);
34
23
  }
35
24
  }
36
- else if ((0, v_validation_1.isString)(value)) {
25
+ else if (isString(value)) {
37
26
  const match = params.pattern.exec(value);
38
27
  if (match) {
39
28
  const dateTime = params.parser(value, match);
@@ -42,182 +31,172 @@ class LuxonValidator extends v_validation_1.Validator {
42
31
  }
43
32
  }
44
33
  }
45
- return ctx.failurePromise(v_validation_1.defaultViolations.date(value, path, params.type), value);
34
+ return ctx.failurePromise(defaultViolations.date(value, path, params.type), value);
46
35
  function success(dateTime) {
47
36
  return ctx.successPromise(params.proto ? new params.proto(dateTime) : dateTime);
48
37
  }
49
38
  }
50
39
  }
51
- exports.LuxonValidator = LuxonValidator;
52
40
  const datePattern = /^\d{4}-\d{2}-\d{2}$/;
53
41
  function localDate(options = { setZone: true }) {
54
42
  return new LuxonValidator({
55
43
  type: 'Date',
56
- proto: luxon_2.LocalDateLuxon,
44
+ proto: LocalDateLuxon,
57
45
  pattern: datePattern,
58
- parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }),
46
+ parser: (value) => DateTime.fromISO(value, { zone: FixedOffsetZone.utcInstance }),
59
47
  });
60
48
  }
61
49
  const timePattern = /^\d{2}:\d{2}:\d{2}$/;
62
- function localTime(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
50
+ function localTime(options = { zone: FixedOffsetZone.utcInstance }) {
63
51
  return new LuxonValidator({
64
52
  type: 'Time',
65
- proto: luxon_2.LocalTimeLuxon,
53
+ proto: LocalTimeLuxon,
66
54
  pattern: timePattern,
67
- parser: (value) => luxon_1.DateTime.fromISO(value, options),
55
+ parser: (value) => DateTime.fromISO(value, options),
68
56
  });
69
57
  }
70
58
  const localDateTimePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
71
- function localDateTime(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
59
+ function localDateTime(options = { zone: FixedOffsetZone.utcInstance }) {
72
60
  return new LuxonValidator({
73
61
  type: 'DateTime',
74
- proto: luxon_2.LocalDateTimeLuxon,
62
+ proto: LocalDateTimeLuxon,
75
63
  pattern: localDateTimePattern,
76
- parser: (value) => luxon_1.DateTime.fromISO(value, options),
64
+ parser: (value) => DateTime.fromISO(value, options),
77
65
  });
78
66
  }
79
67
  const dateTimeTzPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
80
68
  function dateTime(options = { setZone: true }) {
81
69
  return new LuxonValidator({
82
70
  type: 'DateTime',
83
- proto: luxon_2.DateTimeLuxon,
71
+ proto: DateTimeLuxon,
84
72
  pattern: dateTimeTzPattern,
85
- parser: (value) => luxon_1.DateTime.fromISO(value, options),
73
+ parser: (value) => DateTime.fromISO(value, options),
86
74
  });
87
75
  }
88
- function dateTimeUtc(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
76
+ function dateTimeUtc(options = { zone: FixedOffsetZone.utcInstance }) {
89
77
  return new LuxonValidator({
90
78
  type: 'DateTime',
91
- proto: luxon_2.DateTimeUtcLuxon,
79
+ proto: DateTimeUtcLuxon,
92
80
  pattern: dateTimeTzPattern,
93
- parser: (value) => luxon_1.DateTime.fromISO(value, options),
81
+ parser: (value) => DateTime.fromISO(value, options),
94
82
  });
95
83
  }
96
84
  const dateTimeMillisPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
97
85
  function dateTimeMillis(options = { setZone: true }) {
98
86
  return new LuxonValidator({
99
87
  type: 'DateTimeMillis',
100
- proto: luxon_2.DateTimeMillisLuxon,
88
+ proto: DateTimeMillisLuxon,
101
89
  pattern: dateTimeMillisPattern,
102
- parser: (value) => luxon_1.DateTime.fromISO(value, options),
90
+ parser: (value) => DateTime.fromISO(value, options),
103
91
  });
104
92
  }
105
- function dateTimeMillisUtc(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
93
+ function dateTimeMillisUtc(options = { zone: FixedOffsetZone.utcInstance }) {
106
94
  return new LuxonValidator({
107
95
  type: 'DateTimeMillis',
108
- proto: luxon_2.DateTimeMillisUtcLuxon,
96
+ proto: DateTimeMillisUtcLuxon,
109
97
  pattern: dateTimeMillisPattern,
110
- parser: (value) => luxon_1.DateTime.fromISO(value, options),
98
+ parser: (value) => DateTime.fromISO(value, options),
111
99
  });
112
100
  }
113
101
  function dateTimeFromISO(options = { setZone: true }) {
114
102
  return new LuxonValidator({
115
103
  type: 'ISODateTime',
116
104
  pattern: /./,
117
- parser: (value) => luxon_1.DateTime.fromISO(value, options),
105
+ parser: (value) => DateTime.fromISO(value, options),
118
106
  });
119
107
  }
120
108
  function dateTimeFromRFC2822(options = { setZone: true }) {
121
109
  return new LuxonValidator({
122
110
  type: 'RFC2822DateTime',
123
111
  pattern: /./,
124
- parser: (value) => luxon_1.DateTime.fromRFC2822(value, options),
112
+ parser: (value) => DateTime.fromRFC2822(value, options),
125
113
  });
126
114
  }
127
115
  function dateTimeFromHTTP(options = { setZone: true }) {
128
116
  return new LuxonValidator({
129
117
  type: 'HTTPDateTime',
130
118
  pattern: /./,
131
- parser: (value) => luxon_1.DateTime.fromHTTP(value, options),
119
+ parser: (value) => DateTime.fromHTTP(value, options),
132
120
  });
133
121
  }
134
- function dateTimeFromSQL(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
122
+ function dateTimeFromSQL(options = { zone: FixedOffsetZone.utcInstance }) {
135
123
  return new LuxonValidator({
136
124
  type: 'SQLDateTime',
137
125
  pattern: /./,
138
- parser: (value) => luxon_1.DateTime.fromSQL(value, options),
126
+ parser: (value) => DateTime.fromSQL(value, options),
139
127
  });
140
128
  }
141
- function validateLuxonNumber({ value, path, ctx, type, parser }) {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
144
- return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
145
- }
146
- else if (luxon_1.DateTime.isDateTime(value)) {
147
- if (value.isValid) {
148
- return ctx.success(value);
149
- }
129
+ export async function validateLuxonNumber({ value, path, ctx, type, parser }) {
130
+ if (isNullOrUndefined(value)) {
131
+ return ctx.failure(defaultViolations.notNull(path), value);
132
+ }
133
+ else if (DateTime.isDateTime(value)) {
134
+ if (value.isValid) {
135
+ return ctx.success(value);
150
136
  }
151
- else if (typeof value === 'number' && !Number.isNaN(value)) {
152
- const dateTime = parser(value);
153
- if (dateTime.isValid) {
154
- return ctx.success(dateTime);
155
- }
137
+ }
138
+ else if (typeof value === 'number' && !Number.isNaN(value)) {
139
+ const dateTime = parser(value);
140
+ if (dateTime.isValid) {
141
+ return ctx.success(dateTime);
156
142
  }
157
- return ctx.failure(v_validation_1.defaultViolations.date(value, path, type), value);
158
- });
143
+ }
144
+ return ctx.failure(defaultViolations.date(value, path, type), value);
159
145
  }
160
- exports.validateLuxonNumber = validateLuxonNumber;
161
- function dateTimeFromMillis(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
162
- return v_validation_1.V.fn((value, path, ctx) => validateLuxonNumber({
146
+ function dateTimeFromMillis(options = { zone: FixedOffsetZone.utcInstance }) {
147
+ return V.fn((value, path, ctx) => validateLuxonNumber({
163
148
  value,
164
149
  path,
165
150
  ctx,
166
151
  type: 'MillisDateTime',
167
- parser: value => luxon_1.DateTime.fromMillis(value, options),
152
+ parser: value => DateTime.fromMillis(value, options),
168
153
  }));
169
154
  }
170
- function dateTimeFromSeconds(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) {
171
- return v_validation_1.V.fn((value, path, ctx) => validateLuxonNumber({
155
+ function dateTimeFromSeconds(options = { zone: FixedOffsetZone.utcInstance }) {
156
+ return V.fn((value, path, ctx) => validateLuxonNumber({
172
157
  value,
173
158
  path,
174
159
  ctx,
175
160
  type: 'SecondsDateTime',
176
- parser: value => luxon_1.DateTime.fromSeconds(value, options),
161
+ parser: value => DateTime.fromSeconds(value, options),
177
162
  }));
178
163
  }
179
164
  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)?)?$/;
180
- class DurationValidator extends v_validation_1.Validator {
181
- validatePath(value, path, ctx) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
184
- return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
185
- }
186
- else if (luxon_1.Duration.isDuration(value)) {
187
- return ctx.success(value);
188
- }
189
- else if ((0, v_validation_1.isString)(value) && durationPattern.test(value)) {
190
- const duration = luxon_1.Duration.fromISO(value);
191
- if (duration.isValid) {
192
- return ctx.success(duration);
193
- }
165
+ export class DurationValidator extends Validator {
166
+ async validatePath(value, path, ctx) {
167
+ if (isNullOrUndefined(value)) {
168
+ return ctx.failure(defaultViolations.notNull(path), value);
169
+ }
170
+ else if (Duration.isDuration(value)) {
171
+ return ctx.success(value);
172
+ }
173
+ else if (isString(value) && durationPattern.test(value)) {
174
+ const duration = Duration.fromISO(value);
175
+ if (duration.isValid) {
176
+ return ctx.success(duration);
194
177
  }
195
- return ctx.failure(new v_validation_1.TypeMismatch(path, 'Duration', value), value);
196
- });
178
+ }
179
+ return ctx.failure(new TypeMismatch(path, 'Duration', value), value);
197
180
  }
198
181
  }
199
- exports.DurationValidator = DurationValidator;
200
- class TimeDurationValidator extends v_validation_1.Validator {
201
- validatePath(value, path, ctx) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
204
- return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
205
- }
206
- else if (luxon_1.Duration.isDuration(value)) {
207
- return ctx.success(value);
208
- }
209
- else if ((0, v_validation_1.isString)(value)) {
210
- const duration = luxon_1.Duration.fromISOTime(value);
211
- if (duration.isValid) {
212
- return ctx.success(duration);
213
- }
182
+ export class TimeDurationValidator extends Validator {
183
+ async validatePath(value, path, ctx) {
184
+ if (isNullOrUndefined(value)) {
185
+ return ctx.failure(defaultViolations.notNull(path), value);
186
+ }
187
+ else if (Duration.isDuration(value)) {
188
+ return ctx.success(value);
189
+ }
190
+ else if (isString(value)) {
191
+ const duration = Duration.fromISOTime(value);
192
+ if (duration.isValid) {
193
+ return ctx.success(duration);
214
194
  }
215
- return ctx.failure(new v_validation_1.TypeMismatch(path, 'TimeDuration', value), value);
216
- });
195
+ }
196
+ return ctx.failure(new TypeMismatch(path, 'TimeDuration', value), value);
217
197
  }
218
198
  }
219
- exports.TimeDurationValidator = TimeDurationValidator;
220
- exports.Vluxon = {
199
+ export const Vluxon = {
221
200
  // DateTime wrapper validators
222
201
  localDate,
223
202
  localTime,
@@ -236,4 +215,4 @@ exports.Vluxon = {
236
215
  duration: () => new DurationValidator(),
237
216
  timeDuration: () => new TimeDurationValidator(),
238
217
  };
239
- Object.freeze(exports.Vluxon);
218
+ Object.freeze(Vluxon);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './Vluxon';
2
- export * from './luxon';
1
+ export * from './Vluxon.js';
2
+ export * from './luxon.js';
package/dist/index.js CHANGED
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Vluxon"), exports);
18
- __exportStar(require("./luxon"), exports);
1
+ export * from './Vluxon.js';
2
+ export * from './luxon.js';
package/dist/luxon.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DateTime, DateTimeJSOptions, DateTimeOptions, Zone } from 'luxon';
2
- export declare type LuxonDateTimeInput = DateTime | LuxonDateTime;
2
+ export type LuxonDateTimeInput = DateTime | LuxonDateTime;
3
3
  export declare abstract class LuxonDateTime {
4
4
  readonly dateTime: DateTime;
5
5
  constructor(input: LuxonDateTimeInput);
package/dist/luxon.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- var _a, _b;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.DateTimeMillisUtcLuxon = exports.DateTimeMillisLuxon = exports.DateTimeUtcLuxon = exports.DateTimeLuxon = exports.LocalDateTimeLuxon = exports.LocalTimeLuxon = exports.LocalDateLuxon = exports.LuxonDateTime = void 0;
5
- const luxon_1 = require("luxon");
6
- class LuxonDateTime {
1
+ import { DateTime, FixedOffsetZone } from 'luxon';
2
+ export class LuxonDateTime {
3
+ dateTime;
7
4
  constructor(input) {
8
5
  if (input === null || input === undefined) {
9
6
  throw new Error('invalid input (null or undefined), expected DateTime or LuxonDateTime');
@@ -11,7 +8,7 @@ class LuxonDateTime {
11
8
  else if (input instanceof LuxonDateTime) {
12
9
  this.dateTime = this.normalize(input.dateTime);
13
10
  }
14
- else if (input instanceof luxon_1.DateTime) {
11
+ else if (input instanceof DateTime) {
15
12
  if (!input.isValid) {
16
13
  throw new Error('Invalid DateTime: ' + input.invalidExplanation);
17
14
  }
@@ -44,31 +41,43 @@ class LuxonDateTime {
44
41
  return this.toJSON();
45
42
  }
46
43
  }
47
- exports.LuxonDateTime = LuxonDateTime;
48
- class LocalDateLuxon extends LuxonDateTime {
44
+ export class LocalDateLuxon extends LuxonDateTime {
45
+ static format = 'yyyy-MM-dd';
49
46
  constructor(input) {
50
47
  super(input);
51
48
  }
52
49
  static nowLocal(options) {
53
- return new LocalDateLuxon(luxon_1.DateTime.local(options));
50
+ return new LocalDateLuxon(DateTime.local(options));
54
51
  }
55
52
  static nowUtc() {
56
- return new LocalDateLuxon(luxon_1.DateTime.utc());
53
+ return new LocalDateLuxon(DateTime.utc());
57
54
  }
58
55
  static fromISO(value, options) {
59
- return new LocalDateLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
56
+ return new LocalDateLuxon(DateTime.fromISO(value, {
57
+ zone: FixedOffsetZone.utcInstance,
58
+ ...options,
59
+ }));
60
60
  }
61
61
  static fromFormat(value, format, options) {
62
- return new LocalDateLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
62
+ return new LocalDateLuxon(DateTime.fromFormat(value, format, {
63
+ zone: FixedOffsetZone.utcInstance,
64
+ ...options,
65
+ }));
63
66
  }
64
67
  static fromJSDate(date, options) {
65
- return new LocalDateLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
68
+ return new LocalDateLuxon(DateTime.fromJSDate(date, {
69
+ zone: FixedOffsetZone.utcInstance,
70
+ ...options,
71
+ }));
66
72
  }
67
73
  static fromMillis(millis, options) {
68
- return new LocalDateLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
74
+ return new LocalDateLuxon(DateTime.fromMillis(millis, {
75
+ zone: FixedOffsetZone.utcInstance,
76
+ ...options,
77
+ }));
69
78
  }
70
79
  normalize(dateTime) {
71
- return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day);
80
+ return DateTime.utc(dateTime.year, dateTime.month, dateTime.day);
72
81
  }
73
82
  wrap(fn) {
74
83
  return new LocalDateLuxon(fn(this.dateTime));
@@ -77,32 +86,43 @@ class LocalDateLuxon extends LuxonDateTime {
77
86
  return this.dateTime.toFormat(LocalDateLuxon.format);
78
87
  }
79
88
  }
80
- exports.LocalDateLuxon = LocalDateLuxon;
81
- LocalDateLuxon.format = 'yyyy-MM-dd';
82
- class LocalTimeLuxon extends LuxonDateTime {
89
+ export class LocalTimeLuxon extends LuxonDateTime {
90
+ static format = 'HH:mm:ss';
83
91
  constructor(input) {
84
92
  super(input);
85
93
  }
86
94
  static nowLocal(options) {
87
- return new LocalTimeLuxon(luxon_1.DateTime.local(options));
95
+ return new LocalTimeLuxon(DateTime.local(options));
88
96
  }
89
97
  static nowUtc() {
90
- return new LocalTimeLuxon(luxon_1.DateTime.utc());
98
+ return new LocalTimeLuxon(DateTime.utc());
91
99
  }
92
100
  static fromISO(value, options) {
93
- return new LocalTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
101
+ return new LocalTimeLuxon(DateTime.fromISO(value, {
102
+ zone: FixedOffsetZone.utcInstance,
103
+ ...options,
104
+ }));
94
105
  }
95
106
  static fromFormat(value, format, options) {
96
- return new LocalTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
107
+ return new LocalTimeLuxon(DateTime.fromFormat(value, format, {
108
+ zone: FixedOffsetZone.utcInstance,
109
+ ...options,
110
+ }));
97
111
  }
98
112
  static fromJSDate(date, options) {
99
- return new LocalTimeLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
113
+ return new LocalTimeLuxon(DateTime.fromJSDate(date, {
114
+ zone: FixedOffsetZone.utcInstance,
115
+ ...options,
116
+ }));
100
117
  }
101
118
  static fromMillis(millis, options) {
102
- return new LocalTimeLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
119
+ return new LocalTimeLuxon(DateTime.fromMillis(millis, {
120
+ zone: FixedOffsetZone.utcInstance,
121
+ ...options,
122
+ }));
103
123
  }
104
124
  normalize(dateTime) {
105
- return luxon_1.DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second);
125
+ return DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second);
106
126
  }
107
127
  wrap(fn) {
108
128
  return new LocalTimeLuxon(fn(this.dateTime));
@@ -111,9 +131,8 @@ class LocalTimeLuxon extends LuxonDateTime {
111
131
  return this.dateTime.toFormat(LocalTimeLuxon.format);
112
132
  }
113
133
  }
114
- exports.LocalTimeLuxon = LocalTimeLuxon;
115
- LocalTimeLuxon.format = 'HH:mm:ss';
116
- class LocalDateTimeLuxon extends LuxonDateTime {
134
+ export class LocalDateTimeLuxon extends LuxonDateTime {
135
+ static format = "yyyy-MM-dd'T'HH:mm:ss";
117
136
  constructor(input) {
118
137
  super(input);
119
138
  }
@@ -121,25 +140,37 @@ class LocalDateTimeLuxon extends LuxonDateTime {
121
140
  return new DateTimeLuxon(this.dateTime.setZone(zone, { keepLocalTime: true }));
122
141
  }
123
142
  static nowLocal(options) {
124
- return new LocalDateTimeLuxon(luxon_1.DateTime.local(options));
143
+ return new LocalDateTimeLuxon(DateTime.local(options));
125
144
  }
126
145
  static nowUtc() {
127
- return new LocalDateTimeLuxon(luxon_1.DateTime.utc());
146
+ return new LocalDateTimeLuxon(DateTime.utc());
128
147
  }
129
148
  static fromISO(value, options) {
130
- return new LocalDateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
149
+ return new LocalDateTimeLuxon(DateTime.fromISO(value, {
150
+ zone: FixedOffsetZone.utcInstance,
151
+ ...options,
152
+ }));
131
153
  }
132
154
  static fromFormat(value, format, options) {
133
- return new LocalDateTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
155
+ return new LocalDateTimeLuxon(DateTime.fromFormat(value, format, {
156
+ zone: FixedOffsetZone.utcInstance,
157
+ ...options,
158
+ }));
134
159
  }
135
160
  static fromJSDate(date, options) {
136
- return new LocalDateTimeLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
161
+ return new LocalDateTimeLuxon(DateTime.fromJSDate(date, {
162
+ zone: FixedOffsetZone.utcInstance,
163
+ ...options,
164
+ }));
137
165
  }
138
166
  static fromMillis(millis, options) {
139
- return new LocalDateTimeLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
167
+ return new LocalDateTimeLuxon(DateTime.fromMillis(millis, {
168
+ zone: FixedOffsetZone.utcInstance,
169
+ ...options,
170
+ }));
140
171
  }
141
172
  normalize(dateTime) {
142
- return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second);
173
+ return DateTime.utc(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second);
143
174
  }
144
175
  wrap(fn) {
145
176
  return new LocalDateTimeLuxon(fn(this.dateTime));
@@ -148,9 +179,9 @@ class LocalDateTimeLuxon extends LuxonDateTime {
148
179
  return this.dateTime.toFormat(LocalDateTimeLuxon.format);
149
180
  }
150
181
  }
151
- exports.LocalDateTimeLuxon = LocalDateTimeLuxon;
152
- LocalDateTimeLuxon.format = "yyyy-MM-dd'T'HH:mm:ss";
153
- class DateTimeLuxon extends LuxonDateTime {
182
+ export class DateTimeLuxon extends LuxonDateTime {
183
+ static format = "yyyy-MM-dd'T'HH:mm:ss";
184
+ static formatTz = `${this.format}ZZ`;
154
185
  constructor(input) {
155
186
  super(input);
156
187
  }
@@ -158,19 +189,25 @@ class DateTimeLuxon extends LuxonDateTime {
158
189
  return new DateTimeLuxon(this.dateTime.setZone(zone, { keepLocalTime: false }));
159
190
  }
160
191
  static now(options) {
161
- return new DateTimeLuxon(luxon_1.DateTime.local(options));
192
+ return new DateTimeLuxon(DateTime.local(options));
162
193
  }
163
194
  static fromISO(value, options) {
164
- return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
195
+ return new DateTimeLuxon(DateTime.fromISO(value, {
196
+ setZone: true,
197
+ ...options,
198
+ }));
165
199
  }
166
200
  static fromFormat(value, format, options) {
167
- return new DateTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ setZone: true }, options)));
201
+ return new DateTimeLuxon(DateTime.fromFormat(value, format, {
202
+ setZone: true,
203
+ ...options,
204
+ }));
168
205
  }
169
206
  static fromJSDate(date, options) {
170
- return new DateTimeLuxon(luxon_1.DateTime.fromJSDate(date, options));
207
+ return new DateTimeLuxon(DateTime.fromJSDate(date, options));
171
208
  }
172
209
  static fromMillis(millis, options) {
173
- return new DateTimeLuxon(luxon_1.DateTime.fromMillis(millis, options));
210
+ return new DateTimeLuxon(DateTime.fromMillis(millis, options));
174
211
  }
175
212
  normalize(dateTime) {
176
213
  return dateTime.startOf('second');
@@ -185,11 +222,7 @@ class DateTimeLuxon extends LuxonDateTime {
185
222
  return this.dateTime.toFormat(DateTimeLuxon.formatTz);
186
223
  }
187
224
  }
188
- exports.DateTimeLuxon = DateTimeLuxon;
189
- _a = DateTimeLuxon;
190
- DateTimeLuxon.format = "yyyy-MM-dd'T'HH:mm:ss";
191
- DateTimeLuxon.formatTz = `${_a.format}ZZ`;
192
- class DateTimeUtcLuxon extends LuxonDateTime {
225
+ export class DateTimeUtcLuxon extends LuxonDateTime {
193
226
  constructor(input) {
194
227
  super(input);
195
228
  }
@@ -197,19 +230,31 @@ class DateTimeUtcLuxon extends LuxonDateTime {
197
230
  return new DateTimeLuxon(this.dateTime.setZone(zone, { keepLocalTime: false }));
198
231
  }
199
232
  static now() {
200
- return new DateTimeUtcLuxon(luxon_1.DateTime.utc());
233
+ return new DateTimeUtcLuxon(DateTime.utc());
201
234
  }
202
235
  static fromISO(value, options) {
203
- return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
236
+ return new DateTimeUtcLuxon(DateTime.fromISO(value, {
237
+ zone: FixedOffsetZone.utcInstance,
238
+ ...options,
239
+ }));
204
240
  }
205
241
  static fromFormat(value, format, options) {
206
- return new DateTimeUtcLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
242
+ return new DateTimeUtcLuxon(DateTime.fromFormat(value, format, {
243
+ zone: FixedOffsetZone.utcInstance,
244
+ ...options,
245
+ }));
207
246
  }
208
247
  static fromJSDate(date, options) {
209
- return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
248
+ return new DateTimeUtcLuxon(DateTime.fromJSDate(date, {
249
+ zone: FixedOffsetZone.utcInstance,
250
+ ...options,
251
+ }));
210
252
  }
211
253
  static fromMillis(millis, options) {
212
- return new DateTimeUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
254
+ return new DateTimeUtcLuxon(DateTime.fromMillis(millis, {
255
+ zone: FixedOffsetZone.utcInstance,
256
+ ...options,
257
+ }));
213
258
  }
214
259
  normalize(dateTime) {
215
260
  return dateTime.toUTC().startOf('second');
@@ -221,8 +266,9 @@ class DateTimeUtcLuxon extends LuxonDateTime {
221
266
  return this.dateTime.toFormat(DateTimeLuxon.format) + 'Z';
222
267
  }
223
268
  }
224
- exports.DateTimeUtcLuxon = DateTimeUtcLuxon;
225
- class DateTimeMillisLuxon extends LuxonDateTime {
269
+ export class DateTimeMillisLuxon extends LuxonDateTime {
270
+ static format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
271
+ static formatTz = `${this.format}ZZ`;
226
272
  constructor(input) {
227
273
  super(input);
228
274
  }
@@ -230,19 +276,25 @@ class DateTimeMillisLuxon extends LuxonDateTime {
230
276
  return new DateTimeMillisLuxon(this.dateTime.setZone(zone, { keepLocalTime: false }));
231
277
  }
232
278
  static now(options) {
233
- return new DateTimeMillisLuxon(luxon_1.DateTime.local(options));
279
+ return new DateTimeMillisLuxon(DateTime.local(options));
234
280
  }
235
281
  static fromISO(value, options) {
236
- return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options)));
282
+ return new DateTimeMillisLuxon(DateTime.fromISO(value, {
283
+ setZone: true,
284
+ ...options,
285
+ }));
237
286
  }
238
287
  static fromFormat(value, format, options) {
239
- return new DateTimeMillisLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ setZone: true }, options)));
288
+ return new DateTimeMillisLuxon(DateTime.fromFormat(value, format, {
289
+ setZone: true,
290
+ ...options,
291
+ }));
240
292
  }
241
293
  static fromJSDate(date, options) {
242
- return new DateTimeMillisLuxon(luxon_1.DateTime.fromJSDate(date, options));
294
+ return new DateTimeMillisLuxon(DateTime.fromJSDate(date, options));
243
295
  }
244
296
  static fromMillis(millis, options) {
245
- return new DateTimeMillisLuxon(luxon_1.DateTime.fromMillis(millis, options));
297
+ return new DateTimeMillisLuxon(DateTime.fromMillis(millis, options));
246
298
  }
247
299
  normalize(dateTime) {
248
300
  return dateTime;
@@ -257,11 +309,7 @@ class DateTimeMillisLuxon extends LuxonDateTime {
257
309
  return this.dateTime.toFormat(DateTimeMillisLuxon.formatTz);
258
310
  }
259
311
  }
260
- exports.DateTimeMillisLuxon = DateTimeMillisLuxon;
261
- _b = DateTimeMillisLuxon;
262
- DateTimeMillisLuxon.format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
263
- DateTimeMillisLuxon.formatTz = `${_b.format}ZZ`;
264
- class DateTimeMillisUtcLuxon extends LuxonDateTime {
312
+ export class DateTimeMillisUtcLuxon extends LuxonDateTime {
265
313
  constructor(input) {
266
314
  super(input);
267
315
  }
@@ -269,19 +317,31 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
269
317
  return new DateTimeMillisLuxon(this.dateTime.setZone(zone, { keepLocalTime: false }));
270
318
  }
271
319
  static now() {
272
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.utc());
320
+ return new DateTimeMillisUtcLuxon(DateTime.utc());
273
321
  }
274
322
  static fromISO(value, options) {
275
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
323
+ return new DateTimeMillisUtcLuxon(DateTime.fromISO(value, {
324
+ zone: FixedOffsetZone.utcInstance,
325
+ ...options,
326
+ }));
276
327
  }
277
328
  static fromFormat(value, format, options) {
278
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
329
+ return new DateTimeMillisUtcLuxon(DateTime.fromFormat(value, format, {
330
+ zone: FixedOffsetZone.utcInstance,
331
+ ...options,
332
+ }));
279
333
  }
280
334
  static fromJSDate(date, options) {
281
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
335
+ return new DateTimeMillisUtcLuxon(DateTime.fromJSDate(date, {
336
+ zone: FixedOffsetZone.utcInstance,
337
+ ...options,
338
+ }));
282
339
  }
283
340
  static fromMillis(millis, options) {
284
- return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options)));
341
+ return new DateTimeMillisUtcLuxon(DateTime.fromMillis(millis, {
342
+ zone: FixedOffsetZone.utcInstance,
343
+ ...options,
344
+ }));
285
345
  }
286
346
  normalize(dateTime) {
287
347
  return dateTime.toUTC();
@@ -293,4 +353,3 @@ class DateTimeMillisUtcLuxon extends LuxonDateTime {
293
353
  return this.dateTime.toFormat(DateTimeMillisLuxon.format) + 'Z';
294
354
  }
295
355
  }
296
- exports.DateTimeMillisUtcLuxon = DateTimeMillisUtcLuxon;
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "@finnair/v-validation-luxon",
3
- "version": "4.3.0",
3
+ "version": "5.0.0",
4
4
  "private": false,
5
5
  "description": "Luxon validators",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ }
14
+ },
8
15
  "license": "MIT",
9
16
  "homepage": "https://github.com/finnair/v-validation/tree/master/packages/luxon#readme",
10
17
  "bugs": "https://github.com/finnair/v-validation/issues",
@@ -25,11 +32,11 @@
25
32
  "build": "tsc -b ."
26
33
  },
27
34
  "dependencies": {
28
- "@finnair/path": "^4.0.0",
29
- "@finnair/v-validation": "^4.3.0"
35
+ "@finnair/path": "^5.0.0",
36
+ "@finnair/v-validation": "^5.0.0"
30
37
  },
31
38
  "peerDependencies": {
32
39
  "luxon": "^3.0.0"
33
40
  },
34
- "gitHead": "2ba982bbf4e3457e2b2a1433d319e2fde89a413c"
41
+ "gitHead": "b20762715a79e2a336f9c8ceb5107a4d84104a14"
35
42
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const luxon_1 = require("luxon");
4
- const dt = luxon_1.DateTime.fromISO('2022-10-29T23:30:00').setZone(luxon_1.FixedOffsetZone.instance(-60), { keepLocalTime: true });
5
- console.log(dt);
6
- console.log(dt.setZone(luxon_1.FixedOffsetZone.utcInstance));
7
- console.log(luxon_1.DateTime.fromISO('2019-10-18T00:00:05.0Z', { zone: luxon_1.FixedOffsetZone.utcInstance }));
8
- console.log(luxon_1.DateTime.fromISO('2023-02-22T08:10:00Z').diff(luxon_1.DateTime.fromISO('2023-02-22T08:25:00Z'), 'hours').hours);