@finnair/v-validation-luxon 1.1.0-alpha.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 +11 -0
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/Vluxon.d.ts +27 -0
- package/dist/Vluxon.js +157 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -0
- package/dist/luxon.d.ts +57 -0
- package/dist/luxon.js +144 -0
- package/dist/test-luxon.d.ts +1 -0
- package/dist/test-luxon.js +4 -0
- package/package.json +36 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [1.1.0-alpha.0](https://github.com/finnair/v-validation/compare/v1.0.1...v1.1.0-alpha.0) (2022-08-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Support for Luxon ([6f982df](https://github.com/finnair/v-validation/commit/6f982df9b55395e953069914c93fef677dec171e))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Finnair Open Source
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[](https://badge.fury.io/js/%40finnair%2Fv-validation-luxon)
|
|
2
|
+
|
|
3
|
+
# v-validation-luxon
|
|
4
|
+
|
|
5
|
+
`@finnair/v-validation-luxon` is an extension to `@finnair/v-validation`.
|
|
6
|
+
|
|
7
|
+
`Vluxon` extension uses custom wrapper types for Luxon DateTime to support full JSON roundtrip with strict validation.
|
|
8
|
+
|
|
9
|
+
[Documentation for `v-validation`](https://github.com/finnair/v-validation).
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
Install v-validation using [`yarn`](https://yarnpkg.com/en/package/jest):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @finnair/v-validation-luxon
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or [`npm`](https://www.npmjs.com/):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @finnair/v-validation-luxon
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Vluxon
|
|
26
|
+
|
|
27
|
+
`validateLuxon` functions can be used to build custom DateTime validators/converters
|
|
28
|
+
by supplying a RegExp pattern and a wrapper class (subclass of LuxonDateTime).
|
|
29
|
+
The wrapper class should guarantee proper `toJSON()` and other required properties
|
|
30
|
+
for the type (e.g. timezone handling).
|
|
31
|
+
|
|
32
|
+
Time zone 00:00 is serialized as `Z`.
|
|
33
|
+
|
|
34
|
+
| Vluxon . | Format | Description |
|
|
35
|
+
| ----------------- | -------------------------- | ------------------------------------------------------ |
|
|
36
|
+
| date | `YYYY-MM-DD` | Local date. |
|
|
37
|
+
| dateUtc | `YYYY-MM-DD` | Date in UTC time zone. |
|
|
38
|
+
| dateTime | `YYYY-MM-DDTHH:mm:ssZ` | Date and time in local (parsed) time zone. |
|
|
39
|
+
| dateTimeUtc | `YYYY-MM-DDTHH:mm:ssZ` | Date and time in UTC time zone. |
|
|
40
|
+
| dateTimeMillis | `YYYY-MM-DDTHH:mm:ss.SSSZ` | Date and time with millis in local (parsed) time zone. |
|
|
41
|
+
| dateTimeMillisUtc | `YYYY-MM-DDTHH:mm:ss.SSSZ` | Date and time with millis in UTC time zone. |
|
|
42
|
+
| time | `HH:mm:ss` | Local time. |
|
|
43
|
+
| duration | ISO 8601 Duration | Luxon `Duration` with pattern validation. |
|
package/dist/Vluxon.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ValidationContext, Validator, ValidationResult } from '@finnair/v-validation';
|
|
2
|
+
import { Path } from '@finnair/path';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
4
|
+
import { LuxonDateTime } from './luxon';
|
|
5
|
+
export declare type LuxonInput = string | DateTime | LuxonDateTime;
|
|
6
|
+
export interface ValidateLuxonParams {
|
|
7
|
+
value: any;
|
|
8
|
+
path: Path;
|
|
9
|
+
ctx: ValidationContext;
|
|
10
|
+
type: string;
|
|
11
|
+
proto: any;
|
|
12
|
+
pattern: RegExp;
|
|
13
|
+
}
|
|
14
|
+
export declare function validateLuxon({ value, path, ctx, type, proto, pattern }: ValidateLuxonParams): ValidationResult;
|
|
15
|
+
export declare class DurationValidator extends Validator {
|
|
16
|
+
validatePath(value: any, path: Path, ctx: ValidationContext): Promise<ValidationResult>;
|
|
17
|
+
}
|
|
18
|
+
export declare const Vluxon: {
|
|
19
|
+
date: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
20
|
+
dateUtc: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
21
|
+
dateTime: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
22
|
+
dateTimeUtc: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
23
|
+
dateTimeMillis: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
24
|
+
dateTimeMillisUtc: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
25
|
+
time: () => import("@finnair/v-validation").ValidatorFnWrapper;
|
|
26
|
+
duration: () => DurationValidator;
|
|
27
|
+
};
|
package/dist/Vluxon.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
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.DurationValidator = exports.validateLuxon = void 0;
|
|
13
|
+
const v_validation_1 = require("@finnair/v-validation");
|
|
14
|
+
const luxon_1 = require("luxon");
|
|
15
|
+
const luxon_2 = require("./luxon");
|
|
16
|
+
function validateLuxon({ value, path, ctx, type, proto, pattern }) {
|
|
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));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if ((0, v_validation_1.isString)(value)) {
|
|
29
|
+
if (pattern.test(value)) {
|
|
30
|
+
const dateTime = luxon_1.DateTime.fromISO(value, { setZone: true });
|
|
31
|
+
if (dateTime.isValid) {
|
|
32
|
+
return ctx.success(new proto(dateTime));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return ctx.failure(v_validation_1.defaultViolations.date(value, path, type), value);
|
|
37
|
+
}
|
|
38
|
+
exports.validateLuxon = validateLuxon;
|
|
39
|
+
const datePattern = /^\d{4}-\d{2}-\d{2}$/;
|
|
40
|
+
function dateValidator(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.DateLuxon,
|
|
48
|
+
pattern: datePattern
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function dateUtcValidator(value, path, ctx) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return validateLuxon({
|
|
55
|
+
value,
|
|
56
|
+
path,
|
|
57
|
+
ctx,
|
|
58
|
+
type: 'Date',
|
|
59
|
+
proto: luxon_2.DateUtcLuxon,
|
|
60
|
+
pattern: datePattern
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const dateTimePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
|
|
65
|
+
function dateTimeValidator(value, path, ctx) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
return validateLuxon({
|
|
68
|
+
value,
|
|
69
|
+
path,
|
|
70
|
+
ctx,
|
|
71
|
+
type: 'DateTime',
|
|
72
|
+
proto: luxon_2.DateTimeLuxon,
|
|
73
|
+
pattern: dateTimePattern
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function dateTimeUtcValidator(value, path, ctx) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
return validateLuxon({
|
|
80
|
+
value,
|
|
81
|
+
path,
|
|
82
|
+
ctx,
|
|
83
|
+
type: 'DateTime',
|
|
84
|
+
proto: luxon_2.DateTimeUtcLuxon,
|
|
85
|
+
pattern: dateTimePattern
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const dateTimeMillisPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
|
|
90
|
+
function dateTimeMillisValidator(value, path, ctx) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
return validateLuxon({
|
|
93
|
+
value,
|
|
94
|
+
path,
|
|
95
|
+
ctx,
|
|
96
|
+
type: 'DateTimeMillis',
|
|
97
|
+
proto: luxon_2.DateTimeMillisLuxon,
|
|
98
|
+
pattern: dateTimeMillisPattern
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function dateTimeMillisUtcValidator(value, path, ctx) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
return validateLuxon({
|
|
105
|
+
value,
|
|
106
|
+
path,
|
|
107
|
+
ctx,
|
|
108
|
+
type: 'DateTimeMillis',
|
|
109
|
+
proto: luxon_2.DateTimeMillisUtcLuxon,
|
|
110
|
+
pattern: dateTimeMillisPattern
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const timePattern = /^\d{2}:\d{2}:\d{2}$/;
|
|
115
|
+
function timeValidator(value, path, ctx) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return validateLuxon({
|
|
118
|
+
value,
|
|
119
|
+
path,
|
|
120
|
+
ctx,
|
|
121
|
+
type: 'Time',
|
|
122
|
+
proto: luxon_2.TimeLuxon,
|
|
123
|
+
pattern: timePattern
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
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)?)?$/;
|
|
128
|
+
class DurationValidator extends v_validation_1.Validator {
|
|
129
|
+
validatePath(value, path, ctx) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
if ((0, v_validation_1.isNullOrUndefined)(value)) {
|
|
132
|
+
return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
|
|
133
|
+
}
|
|
134
|
+
else if (luxon_1.Duration.isDuration(value)) {
|
|
135
|
+
return ctx.success(value);
|
|
136
|
+
}
|
|
137
|
+
else if ((0, v_validation_1.isString)(value) && durationPattern.test(value)) {
|
|
138
|
+
const duration = luxon_1.Duration.fromISO(value);
|
|
139
|
+
if (duration.isValid) {
|
|
140
|
+
return ctx.success(duration);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return ctx.failure(new v_validation_1.TypeMismatch(path, 'Duration', value), value);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.DurationValidator = DurationValidator;
|
|
148
|
+
exports.Vluxon = {
|
|
149
|
+
date: () => v_validation_1.V.fn(dateValidator),
|
|
150
|
+
dateUtc: () => v_validation_1.V.fn(dateUtcValidator),
|
|
151
|
+
dateTime: () => v_validation_1.V.fn(dateTimeValidator),
|
|
152
|
+
dateTimeUtc: () => v_validation_1.V.fn(dateTimeUtcValidator),
|
|
153
|
+
dateTimeMillis: () => v_validation_1.V.fn(dateTimeMillisValidator),
|
|
154
|
+
dateTimeMillisUtc: () => v_validation_1.V.fn(dateTimeMillisUtcValidator),
|
|
155
|
+
time: () => v_validation_1.V.fn(timeValidator),
|
|
156
|
+
duration: () => new DurationValidator(),
|
|
157
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./Vluxon"), exports);
|
|
14
|
+
__exportStar(require("luxon"), exports);
|
package/dist/luxon.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
export declare type LuxonDateTimeInput = DateTime | LuxonDateTime;
|
|
3
|
+
export declare abstract class LuxonDateTime {
|
|
4
|
+
readonly dateTime: DateTime;
|
|
5
|
+
constructor(input: LuxonDateTimeInput);
|
|
6
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
7
|
+
apply<R>(fn: (dateTime: DateTime) => R): R;
|
|
8
|
+
valueOf(): number;
|
|
9
|
+
equals(other: any): boolean;
|
|
10
|
+
abstract wrap(fn: (dateTime: DateTime) => DateTime): LuxonDateTime;
|
|
11
|
+
abstract toJSON(): string;
|
|
12
|
+
}
|
|
13
|
+
export declare class DateLuxon extends LuxonDateTime {
|
|
14
|
+
static readonly format = "yyyy-MM-dd";
|
|
15
|
+
constructor(input: LuxonDateTimeInput);
|
|
16
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
17
|
+
wrap(fn: (dateTime: DateTime) => DateTime): DateLuxon;
|
|
18
|
+
toJSON(): string;
|
|
19
|
+
}
|
|
20
|
+
export declare class DateUtcLuxon extends LuxonDateTime {
|
|
21
|
+
constructor(input: LuxonDateTimeInput);
|
|
22
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
23
|
+
wrap(fn: (dateTime: DateTime) => DateTime): DateUtcLuxon;
|
|
24
|
+
toJSON(): string;
|
|
25
|
+
}
|
|
26
|
+
export declare class DateTimeLuxon extends LuxonDateTime {
|
|
27
|
+
static readonly format = "yyyy-MM-dd'T'HH:mm:ss";
|
|
28
|
+
static readonly formatTz: string;
|
|
29
|
+
constructor(input: LuxonDateTimeInput);
|
|
30
|
+
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeLuxon;
|
|
31
|
+
toJSON(): string;
|
|
32
|
+
}
|
|
33
|
+
export declare class DateTimeUtcLuxon extends LuxonDateTime {
|
|
34
|
+
constructor(input: LuxonDateTimeInput);
|
|
35
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
36
|
+
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeUtcLuxon;
|
|
37
|
+
toJSON(): string;
|
|
38
|
+
}
|
|
39
|
+
export declare class DateTimeMillisLuxon extends LuxonDateTime {
|
|
40
|
+
static readonly format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
|
41
|
+
static readonly formatTz: string;
|
|
42
|
+
constructor(input: LuxonDateTimeInput);
|
|
43
|
+
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisLuxon;
|
|
44
|
+
toJSON(): string;
|
|
45
|
+
}
|
|
46
|
+
export declare class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
47
|
+
constructor(input: LuxonDateTimeInput);
|
|
48
|
+
protected normalize(dateTime: DateTime): DateTime;
|
|
49
|
+
wrap(fn: (dateTime: DateTime) => DateTime): DateTimeMillisUtcLuxon;
|
|
50
|
+
toJSON(): string;
|
|
51
|
+
}
|
|
52
|
+
export declare class TimeLuxon extends LuxonDateTime {
|
|
53
|
+
static readonly format = "HH:mm:ss";
|
|
54
|
+
constructor(input: LuxonDateTimeInput);
|
|
55
|
+
wrap(fn: (dateTime: DateTime) => DateTime): TimeLuxon;
|
|
56
|
+
toJSON(): string;
|
|
57
|
+
}
|
package/dist/luxon.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TimeLuxon = exports.DateTimeMillisUtcLuxon = exports.DateTimeMillisLuxon = exports.DateTimeUtcLuxon = exports.DateTimeLuxon = exports.DateUtcLuxon = exports.DateLuxon = exports.LuxonDateTime = void 0;
|
|
5
|
+
const luxon_1 = require("luxon");
|
|
6
|
+
class LuxonDateTime {
|
|
7
|
+
constructor(input) {
|
|
8
|
+
if (input instanceof LuxonDateTime) {
|
|
9
|
+
this.dateTime = this.normalize(input.dateTime);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
if (!input.isValid) {
|
|
13
|
+
throw new Error('Invalid DateTime: ' + input.invalidExplanation);
|
|
14
|
+
}
|
|
15
|
+
this.dateTime = this.normalize(input);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
normalize(dateTime) {
|
|
19
|
+
return dateTime;
|
|
20
|
+
}
|
|
21
|
+
apply(fn) {
|
|
22
|
+
return fn(this.dateTime);
|
|
23
|
+
}
|
|
24
|
+
valueOf() {
|
|
25
|
+
return this.dateTime.valueOf();
|
|
26
|
+
}
|
|
27
|
+
equals(other) {
|
|
28
|
+
if (this.constructor === other.constructor) {
|
|
29
|
+
return this.dateTime.equals(other.dateTime);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.LuxonDateTime = LuxonDateTime;
|
|
35
|
+
class DateLuxon extends LuxonDateTime {
|
|
36
|
+
constructor(input) {
|
|
37
|
+
super(input);
|
|
38
|
+
}
|
|
39
|
+
normalize(dateTime) {
|
|
40
|
+
return dateTime.startOf('day');
|
|
41
|
+
}
|
|
42
|
+
wrap(fn) {
|
|
43
|
+
return new DateLuxon(fn(this.dateTime));
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return this.dateTime.toFormat(DateLuxon.format);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.DateLuxon = DateLuxon;
|
|
50
|
+
DateLuxon.format = 'yyyy-MM-dd';
|
|
51
|
+
class DateUtcLuxon extends LuxonDateTime {
|
|
52
|
+
constructor(input) {
|
|
53
|
+
super(input);
|
|
54
|
+
}
|
|
55
|
+
normalize(dateTime) {
|
|
56
|
+
return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day, 0, 0, 0);
|
|
57
|
+
}
|
|
58
|
+
wrap(fn) {
|
|
59
|
+
return new DateUtcLuxon(fn(this.dateTime));
|
|
60
|
+
}
|
|
61
|
+
toJSON() {
|
|
62
|
+
return this.dateTime.toFormat(DateLuxon.format);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.DateUtcLuxon = DateUtcLuxon;
|
|
66
|
+
class DateTimeLuxon extends LuxonDateTime {
|
|
67
|
+
constructor(input) {
|
|
68
|
+
super(input);
|
|
69
|
+
}
|
|
70
|
+
wrap(fn) {
|
|
71
|
+
return new DateTimeLuxon(fn(this.dateTime));
|
|
72
|
+
}
|
|
73
|
+
toJSON() {
|
|
74
|
+
if (this.dateTime.offset === 0) {
|
|
75
|
+
return this.dateTime.toFormat(DateTimeLuxon.format) + 'Z';
|
|
76
|
+
}
|
|
77
|
+
return this.dateTime.toFormat(DateTimeLuxon.formatTz);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.DateTimeLuxon = DateTimeLuxon;
|
|
81
|
+
_a = DateTimeLuxon;
|
|
82
|
+
DateTimeLuxon.format = "yyyy-MM-dd'T'HH:mm:ss";
|
|
83
|
+
DateTimeLuxon.formatTz = `${_a.format}ZZ`;
|
|
84
|
+
class DateTimeUtcLuxon extends LuxonDateTime {
|
|
85
|
+
constructor(input) {
|
|
86
|
+
super(input);
|
|
87
|
+
}
|
|
88
|
+
normalize(dateTime) {
|
|
89
|
+
return dateTime.toUTC();
|
|
90
|
+
}
|
|
91
|
+
wrap(fn) {
|
|
92
|
+
return new DateTimeUtcLuxon(fn(this.dateTime));
|
|
93
|
+
}
|
|
94
|
+
toJSON() {
|
|
95
|
+
return this.dateTime.toFormat(DateTimeLuxon.format) + 'Z';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.DateTimeUtcLuxon = DateTimeUtcLuxon;
|
|
99
|
+
class DateTimeMillisLuxon extends LuxonDateTime {
|
|
100
|
+
constructor(input) {
|
|
101
|
+
super(input);
|
|
102
|
+
}
|
|
103
|
+
wrap(fn) {
|
|
104
|
+
return new DateTimeMillisLuxon(fn(this.dateTime));
|
|
105
|
+
}
|
|
106
|
+
toJSON() {
|
|
107
|
+
if (this.dateTime.offset === 0) {
|
|
108
|
+
return this.dateTime.toFormat(DateTimeMillisLuxon.format) + 'Z';
|
|
109
|
+
}
|
|
110
|
+
return this.dateTime.toFormat(DateTimeMillisLuxon.formatTz);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.DateTimeMillisLuxon = DateTimeMillisLuxon;
|
|
114
|
+
_b = DateTimeMillisLuxon;
|
|
115
|
+
DateTimeMillisLuxon.format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
|
116
|
+
DateTimeMillisLuxon.formatTz = `${_b.format}ZZ`;
|
|
117
|
+
class DateTimeMillisUtcLuxon extends LuxonDateTime {
|
|
118
|
+
constructor(input) {
|
|
119
|
+
super(input);
|
|
120
|
+
}
|
|
121
|
+
normalize(dateTime) {
|
|
122
|
+
return dateTime.toUTC();
|
|
123
|
+
}
|
|
124
|
+
wrap(fn) {
|
|
125
|
+
return new DateTimeMillisUtcLuxon(fn(this.dateTime));
|
|
126
|
+
}
|
|
127
|
+
toJSON() {
|
|
128
|
+
return this.dateTime.toFormat(DateTimeMillisLuxon.format) + 'Z';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.DateTimeMillisUtcLuxon = DateTimeMillisUtcLuxon;
|
|
132
|
+
class TimeLuxon extends LuxonDateTime {
|
|
133
|
+
constructor(input) {
|
|
134
|
+
super(input);
|
|
135
|
+
}
|
|
136
|
+
wrap(fn) {
|
|
137
|
+
return new TimeLuxon(fn(this.dateTime));
|
|
138
|
+
}
|
|
139
|
+
toJSON() {
|
|
140
|
+
return this.dateTime.toFormat(TimeLuxon.format);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.TimeLuxon = TimeLuxon;
|
|
144
|
+
TimeLuxon.format = 'HH:mm:ss';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@finnair/v-validation-luxon",
|
|
3
|
+
"version": "1.1.0-alpha.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Luxon validators",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"homepage": "https://github.com/finnair/v-validation/tree/master/packages/luxon#readme",
|
|
10
|
+
"bugs": "https://github.com/finnair/v-validation/issues",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/finnair/v-validation.git",
|
|
14
|
+
"directory": "packages/luxon"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"validation",
|
|
18
|
+
"validate",
|
|
19
|
+
"convert",
|
|
20
|
+
"normalize",
|
|
21
|
+
"typescript",
|
|
22
|
+
"luxon"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -b ."
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@finnair/path": "^1.1.0-alpha.0",
|
|
29
|
+
"@finnair/v-validation": "^1.1.0-alpha.0",
|
|
30
|
+
"luxon": "3.0.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/luxon": "3.0.0"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "980da25d0eb031a0ed89691c97459b23efcdc8a5"
|
|
36
|
+
}
|