Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@finnair/v-validation-moment

Package Overview
Dependencies
Maintainers
3
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@finnair/v-validation-moment - npm Package Compare versions

Comparing version 0.4.0 to 0.6.0

17

CHANGELOG.md

@@ -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. |
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc