@finnair/v-validation-moment
Advanced tools
Comparing version 0.4.0 to 0.6.0
@@ -6,28 +6,31 @@ # Change Log | ||
# [0.4.0](https://github.com/finnair/v-validation/compare/v0.3.0...v0.4.0) (2020-04-21) | ||
# [0.6.0](https://github.com/finnair/v-validation/compare/v0.5.0...v0.6.0) (2020-05-19) | ||
**Note:** Version bump only for package @finnair/v-validation-moment | ||
### Bug Fixes | ||
* Changelog + try fixing publish failing because of private package(?) ([589a896](https://github.com/finnair/v-validation/commit/589a89674b17e48148341878492f57a57f69c966)) | ||
# [0.3.0](https://github.com/finnair/v-validation/compare/v0.2.0...v0.3.0) (2020-04-16) | ||
**Note:** Version bump only for package @finnair/v-validation-moment | ||
# [0.5.0](https://github.com/finnair/v-validation/compare/v0.4.0...v0.5.0) (2020-05-19) | ||
- Update Moment.js | ||
# [0.4.0](https://github.com/finnair/v-validation/compare/v0.3.0...v0.4.0) (2020-04-21) | ||
**Note:** Version bump only for package @finnair/v-validation-moment | ||
# [0.2.0](https://github.com/finnair/v-validation/compare/v0.1.4...v0.2.0) (2020-04-15) | ||
# [0.3.0](https://github.com/finnair/v-validation/compare/v0.2.0...v0.3.0) (2020-04-16) | ||
**Note:** Version bump only for package @finnair/v-validation-moment | ||
# [0.2.0](https://github.com/finnair/v-validation/compare/v0.1.4...v0.2.0) (2020-04-15) | ||
**Note:** Version bump only for package @finnair/v-validation-moment | ||
## [0.1.4](https://github.com/finnair/v-validation/compare/v0.1.3...v0.1.4) (2020-04-01) | ||
**Note:** Version bump only for package @finnair/v-validation-moment |
@@ -1,7 +0,8 @@ | ||
import { Validator, Path, ValidationContext, ValidationResult } from '@finnair/v-validation-core'; | ||
import { Validator, ValidationContext, ValidationResult } from '@finnair/v-validation'; | ||
import { Path } from '@finnair/path'; | ||
import { Moment, MomentInput } from 'moment'; | ||
export declare class MomentValidator extends Validator { | ||
readonly type: string; | ||
readonly parse: (value: MomentInput) => Moment; | ||
constructor(type: string, parse: (value: MomentInput) => Moment); | ||
readonly parse: (value?: MomentInput | Moment) => Moment; | ||
constructor(type: string, parse: (value?: MomentInput | Moment) => Moment); | ||
validatePath(value: any, path: Path, ctx: ValidationContext): Promise<ValidationResult>; | ||
@@ -12,9 +13,9 @@ } | ||
} | ||
export declare function dateMoment(value: MomentInput): any; | ||
export declare function dateUtcMoment(value: MomentInput): any; | ||
export declare function dateTimeMoment(value: MomentInput): any; | ||
export declare function dateTimeUtcMoment(value: MomentInput): any; | ||
export declare function dateTimeMillisMoment(value: MomentInput): any; | ||
export declare function dateTimeMillisUtcMoment(value: MomentInput): any; | ||
export declare function timeMoment(value: MomentInput): any; | ||
export declare function dateMoment(value?: MomentInput | Moment): any; | ||
export declare function dateUtcMoment(value?: MomentInput | Moment): any; | ||
export declare function dateTimeMoment(value?: MomentInput | Moment): any; | ||
export declare function dateTimeUtcMoment(value?: MomentInput | Moment): any; | ||
export declare function dateTimeMillisMoment(value?: MomentInput | Moment): any; | ||
export declare function dateTimeMillisUtcMoment(value?: MomentInput | Moment): any; | ||
export declare function timeMoment(value?: MomentInput | Moment): any; | ||
export declare const Vmoment: { | ||
@@ -21,0 +22,0 @@ date: () => MomentValidator; |
@@ -6,5 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const v_validation_core_1 = require("@finnair/v-validation-core"); | ||
const v_validation_1 = require("@finnair/v-validation"); | ||
const moment_1 = __importDefault(require("moment")); | ||
class MomentValidator extends v_validation_core_1.Validator { | ||
class MomentValidator extends v_validation_1.Validator { | ||
constructor(type, parse) { | ||
@@ -16,6 +16,6 @@ super(); | ||
async validatePath(value, path, ctx) { | ||
if (v_validation_core_1.isNullOrUndefined(value)) { | ||
return ctx.failure(v_validation_core_1.defaultViolations.notNull(path), value); | ||
if (v_validation_1.isNullOrUndefined(value)) { | ||
return ctx.failure(v_validation_1.defaultViolations.notNull(path), value); | ||
} | ||
if (v_validation_core_1.isString(value) || moment_1.default.isMoment(value)) { | ||
if (v_validation_1.isString(value) || moment_1.default.isMoment(value)) { | ||
const convertedValue = this.parse(value); | ||
@@ -26,3 +26,3 @@ if (convertedValue.isValid()) { | ||
} | ||
return ctx.failure(v_validation_core_1.defaultViolations.date(value, path, this.type), value); | ||
return ctx.failure(v_validation_1.defaultViolations.date(value, path, this.type), value); | ||
} | ||
@@ -32,8 +32,8 @@ } | ||
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)?)?$/; | ||
class DurationValidator extends v_validation_core_1.Validator { | ||
class DurationValidator extends v_validation_1.Validator { | ||
async validatePath(value, path, ctx) { | ||
if (v_validation_core_1.isNullOrUndefined(value)) { | ||
return ctx.failure(v_validation_core_1.defaultViolations.notNull(path), value); | ||
if (v_validation_1.isNullOrUndefined(value)) { | ||
return ctx.failure(v_validation_1.defaultViolations.notNull(path), value); | ||
} | ||
if ((v_validation_core_1.isString(value) && durationPattern.test(value)) || moment_1.default.isDuration(value)) { | ||
if ((v_validation_1.isString(value) && durationPattern.test(value)) || moment_1.default.isDuration(value)) { | ||
value = moment_1.default.duration(value); | ||
@@ -44,3 +44,3 @@ if (value.isValid()) { | ||
} | ||
return ctx.failure(new v_validation_core_1.TypeMismatch(path, 'Duration', value), value); | ||
return ctx.failure(new v_validation_1.TypeMismatch(path, 'Duration', value), value); | ||
} | ||
@@ -50,3 +50,3 @@ } | ||
function maybeDateFormat(value, dateFormat) { | ||
return v_validation_core_1.isString(value) ? dateFormat : undefined; | ||
return v_validation_1.isString(value) ? dateFormat : undefined; | ||
} | ||
@@ -53,0 +53,0 @@ const dateFormat = 'YYYY-MM-DD'; |
{ | ||
"name": "@finnair/v-validation-moment", | ||
"version": "0.4.0", | ||
"version": "0.6.0", | ||
"private": false, | ||
"description": "Moment validators", | ||
@@ -27,9 +28,7 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@finnair/v-validation-core": "^0.4.0", | ||
"@types/moment": "^2.13.0", | ||
"@types/moment-timezone": "^0.5.12", | ||
"moment": "^2.24.0", | ||
"moment-timezone": "^0.5.28" | ||
"@finnair/path": "^0.6.0", | ||
"@finnair/v-validation": "^0.6.0", | ||
"moment": "^2.25.3" | ||
}, | ||
"gitHead": "f3ef8c67d63dbe704a3c857d219ef6bfd56a6375" | ||
"gitHead": "62b25a748646454b1c56dfec9c9d33eee7451b13" | ||
} |
@@ -0,7 +1,7 @@ | ||
[![npm version](https://badge.fury.io/js/%40finnair%2Fv-validation-moment.svg)](https://badge.fury.io/js/%40finnair%2Fv-validation-moment) | ||
# v-validation-moment | ||
[![npm version](https://badge.fury.io/js/%40finnair%2Fv-validation-moment.svg)](https://badge.fury.io/js/%40finnair%2Fv-validation-moment) | ||
`@finnair/v-validation-moment` is an extension to `@finnair/v-validation`. | ||
`@finnair/v-validation-moment` is an extension to `@finnair/v-validation-core`. | ||
`Vmoment` extension uses custom Moment extensions to support full JSON roundtrip with strict validation. | ||
@@ -24,1 +24,19 @@ | ||
``` | ||
## Vmoment | ||
`MomentValidator` can be used to build custom Moment validators/converters by supplying a parse function. However, Moment instances always serialize to JSON | ||
in full date-time format. `V` supports Moment extensions that requires an exact input format and also serialize to JSON using that same format. | ||
Time zone 00:00 is serialized as `Z`. | ||
| Vmoment. | Format | Description | | ||
| ----------------- | -------------------------- | ------------------------------------------------------- | | ||
| date | `YYYY-MM-DD` | Local date. | | ||
| dateUtc | `YYYY-MM-DD` | Date in UTC time zone. | | ||
| dateTime | `YYYY-MM-DDTHH:mm:ssZ` | Date and time in local (parsed) time zone. | | ||
| dateTimeUtc | `YYYY-MM-DDTHH:mm:ssZ` | Date and time in UTC time zone. | | ||
| dateTimeMillis | `YYYY-MM-DDTHH:mm:ss.SSSZ` | Date and time with millis in local (parsed) time zone. | | ||
| dateTimeMillisUtc | `YYYY-MM-DDTHH:mm:ss.SSSZ` | Date and time with millis in UTC time zone. | | ||
| time | `HH:mm:ss` | Local time. | | ||
| duration | ISO 8601 Duration | `moment.duration` with pattern validation. | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14725
3
206
42
+ Added@finnair/path@^0.6.0
+ Added@finnair/v-validation@^0.6.0
+ Added@finnair/path@0.6.2(transitive)
+ Added@finnair/v-validation@0.6.2(transitive)
+ Added@types/deep-equal@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.4(transitive)
+ Addeddata-view-buffer@1.0.2(transitive)
+ Addeddata-view-byte-length@1.0.2(transitive)
+ Addeddata-view-byte-offset@1.0.1(transitive)
+ Addeddeep-equal@2.0.1(transitive)
+ Addedes-abstract@1.23.9(transitive)
+ Addedes-set-tostringtag@2.1.0(transitive)
+ Addedes-to-primitive@1.3.0(transitive)
+ Addedfunction.prototype.name@1.1.8(transitive)
+ Addedget-symbol-description@1.1.0(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedhas-proto@1.2.0(transitive)
+ Addedis-async-function@2.1.0(transitive)
+ Addedis-data-view@1.0.2(transitive)
+ Addedis-finalizationregistry@1.1.1(transitive)
+ Addedis-generator-function@1.1.0(transitive)
+ Addedis-typed-array@1.1.15(transitive)
+ Addedis-weakref@1.1.0(transitive)
+ Addedown-keys@1.0.1(transitive)
+ Addedreflect.getprototypeof@1.0.10(transitive)
+ Addedsafe-array-concat@1.1.3(transitive)
+ Addedsafe-push-apply@1.0.0(transitive)
+ Addedset-proto@1.0.0(transitive)
+ Addedstring.prototype.trim@1.2.10(transitive)
+ Addedstring.prototype.trimend@1.0.9(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtyped-array-buffer@1.0.3(transitive)
+ Addedtyped-array-byte-length@1.0.3(transitive)
+ Addedtyped-array-byte-offset@1.0.4(transitive)
+ Addedtyped-array-length@1.0.7(transitive)
+ Addedunbox-primitive@1.1.0(transitive)
+ Addedwhich-builtin-type@1.2.1(transitive)
- Removed@finnair/v-validation-core@^0.4.0
- Removed@types/moment@^2.13.0
- Removed@types/moment-timezone@^0.5.12
- Removedmoment-timezone@^0.5.28
- Removed@finnair/v-validation-core@0.4.0(transitive)
- Removed@types/deep-equal@1.0.4(transitive)
- Removed@types/moment@2.13.0(transitive)
- Removed@types/moment-timezone@0.5.30(transitive)
- Removeddeep-equal@2.2.3(transitive)
- Removedmoment-timezone@0.5.46(transitive)
Updatedmoment@^2.25.3