@finnair/v-validation-moment 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-moment
package/dist/Vmoment.js CHANGED
@@ -1,83 +1,62 @@
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
- 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
- return __awaiter(this, void 0, void 0, function* () {
27
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
28
- return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
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
- if ((0, v_validation_1.isString)(value) || moment_1.default.isMoment(value)) {
31
- const convertedValue = this.parse(value);
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 v_validation_1.Validator {
43
- validatePath(value, path, ctx) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- if ((0, v_validation_1.isNullOrUndefined)(value)) {
46
- return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
47
- }
48
- if (((0, v_validation_1.isString)(value) && durationPattern.test(value)) || moment_1.default.isDuration(value)) {
49
- const convertedValue = moment_1.default.duration(value);
50
- if (convertedValue.isValid()) {
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
- return ctx.failure(new v_validation_1.TypeMismatch(path, 'Duration', value), value);
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 (0, v_validation_1.isString)(value) ? dateFormat : undefined;
41
+ return isString(value) ? dateFormat : undefined;
61
42
  }
62
43
  const dateFormat = 'YYYY-MM-DD';
63
- function dateMoment(value) {
64
- return Object.setPrototypeOf((0, moment_1.default)(value, maybeDateFormat(value, dateFormat), true), dateMoment.prototype);
44
+ export function dateMoment(value) {
45
+ return Object.setPrototypeOf(moment(value, maybeDateFormat(value, dateFormat), true), dateMoment.prototype);
65
46
  }
66
- exports.dateMoment = dateMoment;
67
- Object.setPrototypeOf(dateMoment.prototype, moment_1.default.prototype);
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(moment_1.default.utc(value, maybeDateFormat(value, dateFormat), true), dateUtcMoment.prototype);
55
+ export function dateUtcMoment(value) {
56
+ return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateFormat), true), dateUtcMoment.prototype);
77
57
  }
78
- exports.dateUtcMoment = dateUtcMoment;
79
- Object.setPrototypeOf(dateUtcMoment.prototype, moment_1.default.prototype);
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(moment_1.default.parseZone(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeMoment.prototype);
68
+ export function dateTimeMoment(value) {
69
+ return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeMoment.prototype);
91
70
  }
92
- exports.dateTimeMoment = dateTimeMoment;
93
- Object.setPrototypeOf(dateTimeMoment.prototype, moment_1.default.prototype);
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(moment_1.default.utc(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeUtcMoment.prototype);
82
+ export function dateTimeUtcMoment(value) {
83
+ return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeUtcMoment.prototype);
106
84
  }
107
- exports.dateTimeUtcMoment = dateTimeUtcMoment;
108
- Object.setPrototypeOf(dateTimeUtcMoment.prototype, moment_1.default.prototype);
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 moment_1.default.prototype.utcOffset.call(this);
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(moment_1.default.parseZone(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisMoment.prototype);
103
+ export function dateTimeMillisMoment(value) {
104
+ return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisMoment.prototype);
128
105
  }
129
- exports.dateTimeMillisMoment = dateTimeMillisMoment;
130
- Object.setPrototypeOf(dateTimeMillisMoment.prototype, moment_1.default.prototype);
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(moment_1.default.utc(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisUtcMoment.prototype);
117
+ export function dateTimeMillisUtcMoment(value) {
118
+ return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisUtcMoment.prototype);
143
119
  }
144
- exports.dateTimeMillisUtcMoment = dateTimeMillisUtcMoment;
145
- Object.setPrototypeOf(dateTimeMillisUtcMoment.prototype, moment_1.default.prototype);
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 moment_1.default.prototype.utcOffset.call(this);
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(moment_1.default.parseZone(value, maybeDateFormat(value, timeFormat), true), timeMoment.prototype);
137
+ export function timeMoment(value) {
138
+ return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, timeFormat), true), timeMoment.prototype);
164
139
  }
165
- exports.timeMoment = timeMoment;
166
- Object.setPrototypeOf(timeMoment.prototype, moment_1.default.prototype);
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
- exports.Vmoment = {
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(exports.Vmoment);
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
- "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("./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": "4.3.0",
3
+ "version": "5.0.0",
4
4
  "private": false,
5
5
  "description": "Moment 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/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": "^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
  "moment": "^2.29.1"
33
40
  },
34
- "gitHead": "2ba982bbf4e3457e2b2a1433d319e2fde89a413c"
41
+ "gitHead": "b20762715a79e2a336f9c8ceb5107a4d84104a14"
35
42
  }
@@ -1 +0,0 @@
1
- export {};
@@ -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());