@finnair/v-validation-moment 4.3.0 → 5.0.1
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 +42 -0
- package/dist/Vmoment.js +59 -85
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -17
- package/package.json +13 -6
- package/dist/test-moment.d.ts +0 -1
- package/dist/test-moment.js +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,48 @@
|
|
|
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.1](https://github.com/finnair/v-validation/compare/v5.0.0...v5.0.1) (2023-10-13)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* npm ignore node_modules for published packages ([9690faf](https://github.com/finnair/v-validation/commit/9690fafb8289e6448dbbeb6274054a8f2b01907a))
|
|
12
|
+
* revert npm ignore node_modules for published packages ([53acd31](https://github.com/finnair/v-validation/commit/53acd312441e823d507152f371ecca0367412c18))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @finnair/v-validation-moment
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# [5.0.0](https://github.com/finnair/v-validation/compare/v4.3.0...v5.0.0) (2023-10-13)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* 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))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# [5.0.0](https://github.com/finnair/v-validation/compare/v4.3.0...v5.0.0) (2023-10-13)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
* 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))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
6
48
|
# [4.3.0](https://github.com/finnair/v-validation/compare/v4.2.0...v4.3.0) (2023-10-03)
|
|
7
49
|
|
|
8
50
|
**Note:** Version bump only for package @finnair/v-validation-moment
|
package/dist/Vmoment.js
CHANGED
|
@@ -1,83 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Vmoment = exports.timeMoment = exports.dateTimeMillisUtcMoment = exports.dateTimeMillisMoment = exports.dateTimeUtcMoment = exports.dateTimeMoment = exports.dateUtcMoment = exports.dateMoment = exports.DurationValidator = exports.MomentValidator = void 0;
|
|
16
|
-
const v_validation_1 = require("@finnair/v-validation");
|
|
17
|
-
const moment_1 = __importDefault(require("moment"));
|
|
18
|
-
class MomentValidator extends v_validation_1.Validator {
|
|
1
|
+
import { Validator, isNullOrUndefined, defaultViolations, isString, TypeMismatch } from '@finnair/v-validation';
|
|
2
|
+
import moment from 'moment';
|
|
3
|
+
export class MomentValidator extends Validator {
|
|
4
|
+
type;
|
|
5
|
+
parse;
|
|
19
6
|
constructor(type, parse) {
|
|
20
7
|
super();
|
|
21
8
|
this.type = type;
|
|
22
9
|
this.parse = parse;
|
|
23
10
|
Object.freeze(this);
|
|
24
11
|
}
|
|
25
|
-
validatePath(value, path, ctx) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
async validatePath(value, path, ctx) {
|
|
13
|
+
if (isNullOrUndefined(value)) {
|
|
14
|
+
return ctx.failure(defaultViolations.notNull(path), value);
|
|
15
|
+
}
|
|
16
|
+
if (isString(value) || moment.isMoment(value)) {
|
|
17
|
+
const convertedValue = this.parse(value);
|
|
18
|
+
if (convertedValue.isValid()) {
|
|
19
|
+
return ctx.success(convertedValue);
|
|
29
20
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (convertedValue.isValid()) {
|
|
33
|
-
return ctx.success(convertedValue);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return ctx.failure(v_validation_1.defaultViolations.date(value, path, this.type), value);
|
|
37
|
-
});
|
|
21
|
+
}
|
|
22
|
+
return ctx.failure(defaultViolations.date(value, path, this.type), value);
|
|
38
23
|
}
|
|
39
24
|
}
|
|
40
|
-
exports.MomentValidator = MomentValidator;
|
|
41
25
|
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)?)?$/;
|
|
42
|
-
class DurationValidator extends
|
|
43
|
-
validatePath(value, path, ctx) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return ctx.success(convertedValue);
|
|
52
|
-
}
|
|
26
|
+
export class DurationValidator extends Validator {
|
|
27
|
+
async validatePath(value, path, ctx) {
|
|
28
|
+
if (isNullOrUndefined(value)) {
|
|
29
|
+
return ctx.failure(defaultViolations.notNull(path), value);
|
|
30
|
+
}
|
|
31
|
+
if ((isString(value) && durationPattern.test(value)) || moment.isDuration(value)) {
|
|
32
|
+
const convertedValue = moment.duration(value);
|
|
33
|
+
if (convertedValue.isValid()) {
|
|
34
|
+
return ctx.success(convertedValue);
|
|
53
35
|
}
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
}
|
|
37
|
+
return ctx.failure(new TypeMismatch(path, 'Duration', value), value);
|
|
56
38
|
}
|
|
57
39
|
}
|
|
58
|
-
exports.DurationValidator = DurationValidator;
|
|
59
40
|
function maybeDateFormat(value, dateFormat) {
|
|
60
|
-
return
|
|
41
|
+
return isString(value) ? dateFormat : undefined;
|
|
61
42
|
}
|
|
62
43
|
const dateFormat = 'YYYY-MM-DD';
|
|
63
|
-
function dateMoment(value) {
|
|
64
|
-
return Object.setPrototypeOf((
|
|
44
|
+
export function dateMoment(value) {
|
|
45
|
+
return Object.setPrototypeOf(moment(value, maybeDateFormat(value, dateFormat), true), dateMoment.prototype);
|
|
65
46
|
}
|
|
66
|
-
|
|
67
|
-
Object.setPrototypeOf(dateMoment
|
|
68
|
-
Object.setPrototypeOf(dateMoment, moment_1.default);
|
|
47
|
+
Object.setPrototypeOf(dateMoment.prototype, moment.prototype);
|
|
48
|
+
Object.setPrototypeOf(dateMoment, moment);
|
|
69
49
|
dateMoment.prototype.toJSON = function toJSON() {
|
|
70
50
|
return this.format(dateFormat);
|
|
71
51
|
};
|
|
72
52
|
dateMoment.prototype.clone = function clone() {
|
|
73
53
|
return dateMoment(this);
|
|
74
54
|
};
|
|
75
|
-
function dateUtcMoment(value) {
|
|
76
|
-
return Object.setPrototypeOf(
|
|
55
|
+
export function dateUtcMoment(value) {
|
|
56
|
+
return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateFormat), true), dateUtcMoment.prototype);
|
|
77
57
|
}
|
|
78
|
-
|
|
79
|
-
Object.setPrototypeOf(dateUtcMoment
|
|
80
|
-
Object.setPrototypeOf(dateUtcMoment, moment_1.default);
|
|
58
|
+
Object.setPrototypeOf(dateUtcMoment.prototype, moment.prototype);
|
|
59
|
+
Object.setPrototypeOf(dateUtcMoment, moment);
|
|
81
60
|
dateUtcMoment.prototype.toJSON = function toJSON() {
|
|
82
61
|
return this.format(dateFormat);
|
|
83
62
|
};
|
|
@@ -86,12 +65,11 @@ dateUtcMoment.prototype.clone = function clone() {
|
|
|
86
65
|
};
|
|
87
66
|
const dateTimeFormat = 'YYYY-MM-DDTHH:mm:ss';
|
|
88
67
|
const dateTimeFormatTz = dateTimeFormat + 'Z';
|
|
89
|
-
function dateTimeMoment(value) {
|
|
90
|
-
return Object.setPrototypeOf(
|
|
68
|
+
export function dateTimeMoment(value) {
|
|
69
|
+
return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeMoment.prototype);
|
|
91
70
|
}
|
|
92
|
-
|
|
93
|
-
Object.setPrototypeOf(dateTimeMoment
|
|
94
|
-
Object.setPrototypeOf(dateTimeMoment, moment_1.default);
|
|
71
|
+
Object.setPrototypeOf(dateTimeMoment.prototype, moment.prototype);
|
|
72
|
+
Object.setPrototypeOf(dateTimeMoment, moment);
|
|
95
73
|
dateTimeMoment.prototype.toJSON = function toJSON() {
|
|
96
74
|
if (this.utcOffset() === 0) {
|
|
97
75
|
return this.format(dateTimeFormat) + 'Z';
|
|
@@ -101,12 +79,11 @@ dateTimeMoment.prototype.toJSON = function toJSON() {
|
|
|
101
79
|
dateTimeMoment.prototype.clone = function clone() {
|
|
102
80
|
return dateTimeMoment(this);
|
|
103
81
|
};
|
|
104
|
-
function dateTimeUtcMoment(value) {
|
|
105
|
-
return Object.setPrototypeOf(
|
|
82
|
+
export function dateTimeUtcMoment(value) {
|
|
83
|
+
return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeUtcMoment.prototype);
|
|
106
84
|
}
|
|
107
|
-
|
|
108
|
-
Object.setPrototypeOf(dateTimeUtcMoment
|
|
109
|
-
Object.setPrototypeOf(dateTimeUtcMoment, moment_1.default);
|
|
85
|
+
Object.setPrototypeOf(dateTimeUtcMoment.prototype, moment.prototype);
|
|
86
|
+
Object.setPrototypeOf(dateTimeUtcMoment, moment);
|
|
110
87
|
dateTimeUtcMoment.prototype.toJSON = function toJSON() {
|
|
111
88
|
return this.format(dateTimeFormat) + 'Z';
|
|
112
89
|
};
|
|
@@ -115,7 +92,7 @@ dateTimeUtcMoment.prototype.clone = function clone() {
|
|
|
115
92
|
};
|
|
116
93
|
dateTimeUtcMoment.prototype.utcOffset = function utcOffset(offset) {
|
|
117
94
|
if (offset === undefined) {
|
|
118
|
-
return
|
|
95
|
+
return moment.prototype.utcOffset.call(this);
|
|
119
96
|
}
|
|
120
97
|
const copy = dateTimeMoment(this);
|
|
121
98
|
copy.utcOffset(offset);
|
|
@@ -123,12 +100,11 @@ dateTimeUtcMoment.prototype.utcOffset = function utcOffset(offset) {
|
|
|
123
100
|
};
|
|
124
101
|
const dateTimeMillisFormat = 'YYYY-MM-DDTHH:mm:ss.SSS';
|
|
125
102
|
const dateTimeMillisFormatTz = dateTimeMillisFormat + 'Z';
|
|
126
|
-
function dateTimeMillisMoment(value) {
|
|
127
|
-
return Object.setPrototypeOf(
|
|
103
|
+
export function dateTimeMillisMoment(value) {
|
|
104
|
+
return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisMoment.prototype);
|
|
128
105
|
}
|
|
129
|
-
|
|
130
|
-
Object.setPrototypeOf(dateTimeMillisMoment
|
|
131
|
-
Object.setPrototypeOf(dateTimeMillisMoment, moment_1.default);
|
|
106
|
+
Object.setPrototypeOf(dateTimeMillisMoment.prototype, moment.prototype);
|
|
107
|
+
Object.setPrototypeOf(dateTimeMillisMoment, moment);
|
|
132
108
|
dateTimeMillisMoment.prototype.toJSON = function toJSON() {
|
|
133
109
|
if (this.utcOffset() === 0) {
|
|
134
110
|
return this.format(dateTimeMillisFormat) + 'Z';
|
|
@@ -138,12 +114,11 @@ dateTimeMillisMoment.prototype.toJSON = function toJSON() {
|
|
|
138
114
|
dateTimeMillisMoment.prototype.clone = function clone() {
|
|
139
115
|
return dateTimeMillisMoment(this);
|
|
140
116
|
};
|
|
141
|
-
function dateTimeMillisUtcMoment(value) {
|
|
142
|
-
return Object.setPrototypeOf(
|
|
117
|
+
export function dateTimeMillisUtcMoment(value) {
|
|
118
|
+
return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisUtcMoment.prototype);
|
|
143
119
|
}
|
|
144
|
-
|
|
145
|
-
Object.setPrototypeOf(dateTimeMillisUtcMoment
|
|
146
|
-
Object.setPrototypeOf(dateTimeMillisUtcMoment, moment_1.default);
|
|
120
|
+
Object.setPrototypeOf(dateTimeMillisUtcMoment.prototype, moment.prototype);
|
|
121
|
+
Object.setPrototypeOf(dateTimeMillisUtcMoment, moment);
|
|
147
122
|
dateTimeMillisUtcMoment.prototype.toJSON = function toJSON() {
|
|
148
123
|
return this.format(dateTimeMillisFormat) + 'Z';
|
|
149
124
|
};
|
|
@@ -152,19 +127,18 @@ dateTimeMillisUtcMoment.prototype.clone = function clone() {
|
|
|
152
127
|
};
|
|
153
128
|
dateTimeMillisUtcMoment.prototype.utcOffset = function utcOffset(offset) {
|
|
154
129
|
if (offset === undefined) {
|
|
155
|
-
return
|
|
130
|
+
return moment.prototype.utcOffset.call(this);
|
|
156
131
|
}
|
|
157
132
|
const copy = dateTimeMillisMoment(this);
|
|
158
133
|
copy.utcOffset(offset);
|
|
159
134
|
return copy;
|
|
160
135
|
};
|
|
161
136
|
const timeFormat = 'HH:mm:ss';
|
|
162
|
-
function timeMoment(value) {
|
|
163
|
-
return Object.setPrototypeOf(
|
|
137
|
+
export function timeMoment(value) {
|
|
138
|
+
return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, timeFormat), true), timeMoment.prototype);
|
|
164
139
|
}
|
|
165
|
-
|
|
166
|
-
Object.setPrototypeOf(timeMoment
|
|
167
|
-
Object.setPrototypeOf(timeMoment, moment_1.default);
|
|
140
|
+
Object.setPrototypeOf(timeMoment.prototype, moment.prototype);
|
|
141
|
+
Object.setPrototypeOf(timeMoment, moment);
|
|
168
142
|
timeMoment.prototype.toJSON = function toJSON() {
|
|
169
143
|
return this.format(timeFormat);
|
|
170
144
|
};
|
|
@@ -172,7 +146,7 @@ timeMoment.prototype.clone = function clone() {
|
|
|
172
146
|
return timeMoment(this);
|
|
173
147
|
};
|
|
174
148
|
const dateValidator = new MomentValidator('Date', dateMoment), dateUtcValidator = new MomentValidator('Date', dateUtcMoment), dateTimeValidator = new MomentValidator('DateTime', dateTimeMoment), dateTimeUtcValidator = new MomentValidator('DateTime', dateTimeUtcMoment), dateTimeMillisValidator = new MomentValidator('DateTimeMillis', dateTimeMillisMoment), dateTimeMillisUtcValidator = new MomentValidator('DateTimeMillis', dateTimeMillisUtcMoment), timeValidator = new MomentValidator('Time', timeMoment), durationValidator = new DurationValidator();
|
|
175
|
-
|
|
149
|
+
export const Vmoment = {
|
|
176
150
|
date: () => dateValidator,
|
|
177
151
|
dateUtc: () => dateUtcValidator,
|
|
178
152
|
dateTime: () => dateTimeValidator,
|
|
@@ -182,4 +156,4 @@ exports.Vmoment = {
|
|
|
182
156
|
time: () => timeValidator,
|
|
183
157
|
duration: () => durationValidator,
|
|
184
158
|
};
|
|
185
|
-
Object.freeze(
|
|
159
|
+
Object.freeze(Vmoment);
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './Vmoment';
|
|
1
|
+
export * from './Vmoment.js';
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
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("./Vmoment"), exports);
|
|
1
|
+
export * from './Vmoment.js';
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finnair/v-validation-moment",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Moment validators",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
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/moment#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": "^
|
|
29
|
-
"@finnair/v-validation": "^
|
|
35
|
+
"@finnair/path": "^5.0.1",
|
|
36
|
+
"@finnair/v-validation": "^5.0.1"
|
|
30
37
|
},
|
|
31
38
|
"peerDependencies": {
|
|
32
39
|
"moment": "^2.29.1"
|
|
33
40
|
},
|
|
34
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "002badde317763fb6ec6a0350b0043d04cc07163"
|
|
35
42
|
}
|
package/dist/test-moment.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test-moment.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const moment_1 = __importDefault(require("moment"));
|
|
7
|
-
console.log(moment_1.default.utc('2022-10-03', 'YYYY-MM-DD').toISOString());
|