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
4
Versions
51
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 4.3.0 to 5.0.0

22

CHANGELOG.md

@@ -6,2 +6,24 @@ # Change Log

# [5.0.0](https://github.com/finnair/v-validation/compare/v4.3.0...v5.0.0) (2023-10-13)
### Features
* 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))
# [5.0.0](https://github.com/finnair/v-validation/compare/v4.3.0...v5.0.0) (2023-10-13)
### Features
* 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))
# [4.3.0](https://github.com/finnair/v-validation/compare/v4.2.0...v4.3.0) (2023-10-03)

@@ -8,0 +30,0 @@

2

dist/index.d.ts

@@ -1,1 +0,1 @@

export * from './Vmoment';
export * from './Vmoment.js';

@@ -1,17 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./Vmoment"), exports);
export * from './Vmoment.js';

@@ -1,19 +0,6 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Vmoment = exports.timeMoment = exports.dateTimeMillisUtcMoment = exports.dateTimeMillisMoment = exports.dateTimeUtcMoment = exports.dateTimeMoment = exports.dateUtcMoment = exports.dateMoment = exports.DurationValidator = exports.MomentValidator = void 0;
const v_validation_1 = require("@finnair/v-validation");
const moment_1 = __importDefault(require("moment"));
class MomentValidator extends v_validation_1.Validator {
import { Validator, isNullOrUndefined, defaultViolations, isString, TypeMismatch } from '@finnair/v-validation';
import moment from 'moment';
export class MomentValidator extends Validator {
type;
parse;
constructor(type, parse) {

@@ -25,46 +12,39 @@ super();

}
validatePath(value, path, ctx) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, v_validation_1.isNullOrUndefined)(value)) {
return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
async validatePath(value, path, ctx) {
if (isNullOrUndefined(value)) {
return ctx.failure(defaultViolations.notNull(path), value);
}
if (isString(value) || moment.isMoment(value)) {
const convertedValue = this.parse(value);
if (convertedValue.isValid()) {
return ctx.success(convertedValue);
}
if ((0, v_validation_1.isString)(value) || moment_1.default.isMoment(value)) {
const convertedValue = this.parse(value);
if (convertedValue.isValid()) {
return ctx.success(convertedValue);
}
}
return ctx.failure(v_validation_1.defaultViolations.date(value, path, this.type), value);
});
}
return ctx.failure(defaultViolations.date(value, path, this.type), value);
}
}
exports.MomentValidator = MomentValidator;
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_1.Validator {
validatePath(value, path, ctx) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, v_validation_1.isNullOrUndefined)(value)) {
return ctx.failure(v_validation_1.defaultViolations.notNull(path), value);
export class DurationValidator extends Validator {
async validatePath(value, path, ctx) {
if (isNullOrUndefined(value)) {
return ctx.failure(defaultViolations.notNull(path), value);
}
if ((isString(value) && durationPattern.test(value)) || moment.isDuration(value)) {
const convertedValue = moment.duration(value);
if (convertedValue.isValid()) {
return ctx.success(convertedValue);
}
if (((0, v_validation_1.isString)(value) && durationPattern.test(value)) || moment_1.default.isDuration(value)) {
const convertedValue = moment_1.default.duration(value);
if (convertedValue.isValid()) {
return ctx.success(convertedValue);
}
}
return ctx.failure(new v_validation_1.TypeMismatch(path, 'Duration', value), value);
});
}
return ctx.failure(new TypeMismatch(path, 'Duration', value), value);
}
}
exports.DurationValidator = DurationValidator;
function maybeDateFormat(value, dateFormat) {
return (0, v_validation_1.isString)(value) ? dateFormat : undefined;
return isString(value) ? dateFormat : undefined;
}
const dateFormat = 'YYYY-MM-DD';
function dateMoment(value) {
return Object.setPrototypeOf((0, moment_1.default)(value, maybeDateFormat(value, dateFormat), true), dateMoment.prototype);
export function dateMoment(value) {
return Object.setPrototypeOf(moment(value, maybeDateFormat(value, dateFormat), true), dateMoment.prototype);
}
exports.dateMoment = dateMoment;
Object.setPrototypeOf(dateMoment.prototype, moment_1.default.prototype);
Object.setPrototypeOf(dateMoment, moment_1.default);
Object.setPrototypeOf(dateMoment.prototype, moment.prototype);
Object.setPrototypeOf(dateMoment, moment);
dateMoment.prototype.toJSON = function toJSON() {

@@ -76,8 +56,7 @@ return this.format(dateFormat);

};
function dateUtcMoment(value) {
return Object.setPrototypeOf(moment_1.default.utc(value, maybeDateFormat(value, dateFormat), true), dateUtcMoment.prototype);
export function dateUtcMoment(value) {
return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateFormat), true), dateUtcMoment.prototype);
}
exports.dateUtcMoment = dateUtcMoment;
Object.setPrototypeOf(dateUtcMoment.prototype, moment_1.default.prototype);
Object.setPrototypeOf(dateUtcMoment, moment_1.default);
Object.setPrototypeOf(dateUtcMoment.prototype, moment.prototype);
Object.setPrototypeOf(dateUtcMoment, moment);
dateUtcMoment.prototype.toJSON = function toJSON() {

@@ -91,8 +70,7 @@ return this.format(dateFormat);

const dateTimeFormatTz = dateTimeFormat + 'Z';
function dateTimeMoment(value) {
return Object.setPrototypeOf(moment_1.default.parseZone(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeMoment.prototype);
export function dateTimeMoment(value) {
return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeMoment.prototype);
}
exports.dateTimeMoment = dateTimeMoment;
Object.setPrototypeOf(dateTimeMoment.prototype, moment_1.default.prototype);
Object.setPrototypeOf(dateTimeMoment, moment_1.default);
Object.setPrototypeOf(dateTimeMoment.prototype, moment.prototype);
Object.setPrototypeOf(dateTimeMoment, moment);
dateTimeMoment.prototype.toJSON = function toJSON() {

@@ -107,8 +85,7 @@ if (this.utcOffset() === 0) {

};
function dateTimeUtcMoment(value) {
return Object.setPrototypeOf(moment_1.default.utc(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeUtcMoment.prototype);
export function dateTimeUtcMoment(value) {
return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateTimeFormatTz), true), dateTimeUtcMoment.prototype);
}
exports.dateTimeUtcMoment = dateTimeUtcMoment;
Object.setPrototypeOf(dateTimeUtcMoment.prototype, moment_1.default.prototype);
Object.setPrototypeOf(dateTimeUtcMoment, moment_1.default);
Object.setPrototypeOf(dateTimeUtcMoment.prototype, moment.prototype);
Object.setPrototypeOf(dateTimeUtcMoment, moment);
dateTimeUtcMoment.prototype.toJSON = function toJSON() {

@@ -122,3 +99,3 @@ return this.format(dateTimeFormat) + 'Z';

if (offset === undefined) {
return moment_1.default.prototype.utcOffset.call(this);
return moment.prototype.utcOffset.call(this);
}

@@ -131,8 +108,7 @@ const copy = dateTimeMoment(this);

const dateTimeMillisFormatTz = dateTimeMillisFormat + 'Z';
function dateTimeMillisMoment(value) {
return Object.setPrototypeOf(moment_1.default.parseZone(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisMoment.prototype);
export function dateTimeMillisMoment(value) {
return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisMoment.prototype);
}
exports.dateTimeMillisMoment = dateTimeMillisMoment;
Object.setPrototypeOf(dateTimeMillisMoment.prototype, moment_1.default.prototype);
Object.setPrototypeOf(dateTimeMillisMoment, moment_1.default);
Object.setPrototypeOf(dateTimeMillisMoment.prototype, moment.prototype);
Object.setPrototypeOf(dateTimeMillisMoment, moment);
dateTimeMillisMoment.prototype.toJSON = function toJSON() {

@@ -147,8 +123,7 @@ if (this.utcOffset() === 0) {

};
function dateTimeMillisUtcMoment(value) {
return Object.setPrototypeOf(moment_1.default.utc(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisUtcMoment.prototype);
export function dateTimeMillisUtcMoment(value) {
return Object.setPrototypeOf(moment.utc(value, maybeDateFormat(value, dateTimeMillisFormatTz), true), dateTimeMillisUtcMoment.prototype);
}
exports.dateTimeMillisUtcMoment = dateTimeMillisUtcMoment;
Object.setPrototypeOf(dateTimeMillisUtcMoment.prototype, moment_1.default.prototype);
Object.setPrototypeOf(dateTimeMillisUtcMoment, moment_1.default);
Object.setPrototypeOf(dateTimeMillisUtcMoment.prototype, moment.prototype);
Object.setPrototypeOf(dateTimeMillisUtcMoment, moment);
dateTimeMillisUtcMoment.prototype.toJSON = function toJSON() {

@@ -162,3 +137,3 @@ return this.format(dateTimeMillisFormat) + 'Z';

if (offset === undefined) {
return moment_1.default.prototype.utcOffset.call(this);
return moment.prototype.utcOffset.call(this);
}

@@ -170,8 +145,7 @@ const copy = dateTimeMillisMoment(this);

const timeFormat = 'HH:mm:ss';
function timeMoment(value) {
return Object.setPrototypeOf(moment_1.default.parseZone(value, maybeDateFormat(value, timeFormat), true), timeMoment.prototype);
export function timeMoment(value) {
return Object.setPrototypeOf(moment.parseZone(value, maybeDateFormat(value, timeFormat), true), timeMoment.prototype);
}
exports.timeMoment = timeMoment;
Object.setPrototypeOf(timeMoment.prototype, moment_1.default.prototype);
Object.setPrototypeOf(timeMoment, moment_1.default);
Object.setPrototypeOf(timeMoment.prototype, moment.prototype);
Object.setPrototypeOf(timeMoment, moment);
timeMoment.prototype.toJSON = function toJSON() {

@@ -184,3 +158,3 @@ return this.format(timeFormat);

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();
exports.Vmoment = {
export const Vmoment = {
date: () => dateValidator,

@@ -195,2 +169,2 @@ dateUtc: () => dateUtcValidator,

};
Object.freeze(exports.Vmoment);
Object.freeze(Vmoment);
{
"name": "@finnair/v-validation-moment",
"version": "4.3.0",
"version": "5.0.0",
"private": false,
"description": "Moment validators",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"license": "MIT",

@@ -28,4 +35,4 @@ "homepage": "https://github.com/finnair/v-validation/tree/master/packages/moment#readme",

"dependencies": {
"@finnair/path": "^4.0.0",
"@finnair/v-validation": "^4.3.0"
"@finnair/path": "^5.0.0",
"@finnair/v-validation": "^5.0.0"
},

@@ -35,3 +42,3 @@ "peerDependencies": {

},
"gitHead": "2ba982bbf4e3457e2b2a1433d319e2fde89a413c"
"gitHead": "b20762715a79e2a336f9c8ceb5107a4d84104a14"
}
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