@finnair/v-validation-luxon
Advanced tools
Comparing version 4.3.0 to 5.0.0
@@ -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 @@ |
@@ -1,2 +0,2 @@ | ||
export * from './Vluxon'; | ||
export * from './luxon'; | ||
export * from './Vluxon.js'; | ||
export * from './luxon.js'; |
@@ -1,18 +0,2 @@ | ||
"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("./Vluxon"), exports); | ||
__exportStar(require("./luxon"), exports); | ||
export * from './Vluxon.js'; | ||
export * from './luxon.js'; |
import { DateTime, DateTimeJSOptions, DateTimeOptions, Zone } from 'luxon'; | ||
export declare type LuxonDateTimeInput = DateTime | LuxonDateTime; | ||
export type LuxonDateTimeInput = DateTime | LuxonDateTime; | ||
export declare abstract class LuxonDateTime { | ||
@@ -4,0 +4,0 @@ readonly dateTime: DateTime; |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
var _a, _b; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DateTimeMillisUtcLuxon = exports.DateTimeMillisLuxon = exports.DateTimeUtcLuxon = exports.DateTimeLuxon = exports.LocalDateTimeLuxon = exports.LocalTimeLuxon = exports.LocalDateLuxon = exports.LuxonDateTime = void 0; | ||
const luxon_1 = require("luxon"); | ||
class LuxonDateTime { | ||
import { DateTime, FixedOffsetZone } from 'luxon'; | ||
export class LuxonDateTime { | ||
dateTime; | ||
constructor(input) { | ||
@@ -14,3 +11,3 @@ if (input === null || input === undefined) { | ||
} | ||
else if (input instanceof luxon_1.DateTime) { | ||
else if (input instanceof DateTime) { | ||
if (!input.isValid) { | ||
@@ -48,4 +45,4 @@ throw new Error('Invalid DateTime: ' + input.invalidExplanation); | ||
} | ||
exports.LuxonDateTime = LuxonDateTime; | ||
class LocalDateLuxon extends LuxonDateTime { | ||
export class LocalDateLuxon extends LuxonDateTime { | ||
static format = 'yyyy-MM-dd'; | ||
constructor(input) { | ||
@@ -55,21 +52,33 @@ super(input); | ||
static nowLocal(options) { | ||
return new LocalDateLuxon(luxon_1.DateTime.local(options)); | ||
return new LocalDateLuxon(DateTime.local(options)); | ||
} | ||
static nowUtc() { | ||
return new LocalDateLuxon(luxon_1.DateTime.utc()); | ||
return new LocalDateLuxon(DateTime.utc()); | ||
} | ||
static fromISO(value, options) { | ||
return new LocalDateLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateLuxon(DateTime.fromISO(value, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromFormat(value, format, options) { | ||
return new LocalDateLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateLuxon(DateTime.fromFormat(value, format, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromJSDate(date, options) { | ||
return new LocalDateLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateLuxon(DateTime.fromJSDate(date, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromMillis(millis, options) { | ||
return new LocalDateLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateLuxon(DateTime.fromMillis(millis, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
normalize(dateTime) { | ||
return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day); | ||
return DateTime.utc(dateTime.year, dateTime.month, dateTime.day); | ||
} | ||
@@ -83,5 +92,4 @@ wrap(fn) { | ||
} | ||
exports.LocalDateLuxon = LocalDateLuxon; | ||
LocalDateLuxon.format = 'yyyy-MM-dd'; | ||
class LocalTimeLuxon extends LuxonDateTime { | ||
export class LocalTimeLuxon extends LuxonDateTime { | ||
static format = 'HH:mm:ss'; | ||
constructor(input) { | ||
@@ -91,21 +99,33 @@ super(input); | ||
static nowLocal(options) { | ||
return new LocalTimeLuxon(luxon_1.DateTime.local(options)); | ||
return new LocalTimeLuxon(DateTime.local(options)); | ||
} | ||
static nowUtc() { | ||
return new LocalTimeLuxon(luxon_1.DateTime.utc()); | ||
return new LocalTimeLuxon(DateTime.utc()); | ||
} | ||
static fromISO(value, options) { | ||
return new LocalTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalTimeLuxon(DateTime.fromISO(value, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromFormat(value, format, options) { | ||
return new LocalTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalTimeLuxon(DateTime.fromFormat(value, format, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromJSDate(date, options) { | ||
return new LocalTimeLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalTimeLuxon(DateTime.fromJSDate(date, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromMillis(millis, options) { | ||
return new LocalTimeLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalTimeLuxon(DateTime.fromMillis(millis, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
normalize(dateTime) { | ||
return luxon_1.DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second); | ||
return DateTime.utc(1970, 1, 1, dateTime.hour, dateTime.minute, dateTime.second); | ||
} | ||
@@ -119,5 +139,4 @@ wrap(fn) { | ||
} | ||
exports.LocalTimeLuxon = LocalTimeLuxon; | ||
LocalTimeLuxon.format = 'HH:mm:ss'; | ||
class LocalDateTimeLuxon extends LuxonDateTime { | ||
export class LocalDateTimeLuxon extends LuxonDateTime { | ||
static format = "yyyy-MM-dd'T'HH:mm:ss"; | ||
constructor(input) { | ||
@@ -130,21 +149,33 @@ super(input); | ||
static nowLocal(options) { | ||
return new LocalDateTimeLuxon(luxon_1.DateTime.local(options)); | ||
return new LocalDateTimeLuxon(DateTime.local(options)); | ||
} | ||
static nowUtc() { | ||
return new LocalDateTimeLuxon(luxon_1.DateTime.utc()); | ||
return new LocalDateTimeLuxon(DateTime.utc()); | ||
} | ||
static fromISO(value, options) { | ||
return new LocalDateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateTimeLuxon(DateTime.fromISO(value, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromFormat(value, format, options) { | ||
return new LocalDateTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateTimeLuxon(DateTime.fromFormat(value, format, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromJSDate(date, options) { | ||
return new LocalDateTimeLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateTimeLuxon(DateTime.fromJSDate(date, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromMillis(millis, options) { | ||
return new LocalDateTimeLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new LocalDateTimeLuxon(DateTime.fromMillis(millis, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
normalize(dateTime) { | ||
return luxon_1.DateTime.utc(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second); | ||
return DateTime.utc(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second); | ||
} | ||
@@ -158,5 +189,5 @@ wrap(fn) { | ||
} | ||
exports.LocalDateTimeLuxon = LocalDateTimeLuxon; | ||
LocalDateTimeLuxon.format = "yyyy-MM-dd'T'HH:mm:ss"; | ||
class DateTimeLuxon extends LuxonDateTime { | ||
export class DateTimeLuxon extends LuxonDateTime { | ||
static format = "yyyy-MM-dd'T'HH:mm:ss"; | ||
static formatTz = `${this.format}ZZ`; | ||
constructor(input) { | ||
@@ -169,15 +200,21 @@ super(input); | ||
static now(options) { | ||
return new DateTimeLuxon(luxon_1.DateTime.local(options)); | ||
return new DateTimeLuxon(DateTime.local(options)); | ||
} | ||
static fromISO(value, options) { | ||
return new DateTimeLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options))); | ||
return new DateTimeLuxon(DateTime.fromISO(value, { | ||
setZone: true, | ||
...options, | ||
})); | ||
} | ||
static fromFormat(value, format, options) { | ||
return new DateTimeLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ setZone: true }, options))); | ||
return new DateTimeLuxon(DateTime.fromFormat(value, format, { | ||
setZone: true, | ||
...options, | ||
})); | ||
} | ||
static fromJSDate(date, options) { | ||
return new DateTimeLuxon(luxon_1.DateTime.fromJSDate(date, options)); | ||
return new DateTimeLuxon(DateTime.fromJSDate(date, options)); | ||
} | ||
static fromMillis(millis, options) { | ||
return new DateTimeLuxon(luxon_1.DateTime.fromMillis(millis, options)); | ||
return new DateTimeLuxon(DateTime.fromMillis(millis, options)); | ||
} | ||
@@ -197,7 +234,3 @@ normalize(dateTime) { | ||
} | ||
exports.DateTimeLuxon = DateTimeLuxon; | ||
_a = DateTimeLuxon; | ||
DateTimeLuxon.format = "yyyy-MM-dd'T'HH:mm:ss"; | ||
DateTimeLuxon.formatTz = `${_a.format}ZZ`; | ||
class DateTimeUtcLuxon extends LuxonDateTime { | ||
export class DateTimeUtcLuxon extends LuxonDateTime { | ||
constructor(input) { | ||
@@ -210,15 +243,27 @@ super(input); | ||
static now() { | ||
return new DateTimeUtcLuxon(luxon_1.DateTime.utc()); | ||
return new DateTimeUtcLuxon(DateTime.utc()); | ||
} | ||
static fromISO(value, options) { | ||
return new DateTimeUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeUtcLuxon(DateTime.fromISO(value, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromFormat(value, format, options) { | ||
return new DateTimeUtcLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeUtcLuxon(DateTime.fromFormat(value, format, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromJSDate(date, options) { | ||
return new DateTimeUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeUtcLuxon(DateTime.fromJSDate(date, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromMillis(millis, options) { | ||
return new DateTimeUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeUtcLuxon(DateTime.fromMillis(millis, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
@@ -235,4 +280,5 @@ normalize(dateTime) { | ||
} | ||
exports.DateTimeUtcLuxon = DateTimeUtcLuxon; | ||
class DateTimeMillisLuxon extends LuxonDateTime { | ||
export class DateTimeMillisLuxon extends LuxonDateTime { | ||
static format = "yyyy-MM-dd'T'HH:mm:ss.SSS"; | ||
static formatTz = `${this.format}ZZ`; | ||
constructor(input) { | ||
@@ -245,15 +291,21 @@ super(input); | ||
static now(options) { | ||
return new DateTimeMillisLuxon(luxon_1.DateTime.local(options)); | ||
return new DateTimeMillisLuxon(DateTime.local(options)); | ||
} | ||
static fromISO(value, options) { | ||
return new DateTimeMillisLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ setZone: true }, options))); | ||
return new DateTimeMillisLuxon(DateTime.fromISO(value, { | ||
setZone: true, | ||
...options, | ||
})); | ||
} | ||
static fromFormat(value, format, options) { | ||
return new DateTimeMillisLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ setZone: true }, options))); | ||
return new DateTimeMillisLuxon(DateTime.fromFormat(value, format, { | ||
setZone: true, | ||
...options, | ||
})); | ||
} | ||
static fromJSDate(date, options) { | ||
return new DateTimeMillisLuxon(luxon_1.DateTime.fromJSDate(date, options)); | ||
return new DateTimeMillisLuxon(DateTime.fromJSDate(date, options)); | ||
} | ||
static fromMillis(millis, options) { | ||
return new DateTimeMillisLuxon(luxon_1.DateTime.fromMillis(millis, options)); | ||
return new DateTimeMillisLuxon(DateTime.fromMillis(millis, options)); | ||
} | ||
@@ -273,7 +325,3 @@ normalize(dateTime) { | ||
} | ||
exports.DateTimeMillisLuxon = DateTimeMillisLuxon; | ||
_b = DateTimeMillisLuxon; | ||
DateTimeMillisLuxon.format = "yyyy-MM-dd'T'HH:mm:ss.SSS"; | ||
DateTimeMillisLuxon.formatTz = `${_b.format}ZZ`; | ||
class DateTimeMillisUtcLuxon extends LuxonDateTime { | ||
export class DateTimeMillisUtcLuxon extends LuxonDateTime { | ||
constructor(input) { | ||
@@ -286,15 +334,27 @@ super(input); | ||
static now() { | ||
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.utc()); | ||
return new DateTimeMillisUtcLuxon(DateTime.utc()); | ||
} | ||
static fromISO(value, options) { | ||
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromISO(value, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeMillisUtcLuxon(DateTime.fromISO(value, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromFormat(value, format, options) { | ||
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromFormat(value, format, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeMillisUtcLuxon(DateTime.fromFormat(value, format, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromJSDate(date, options) { | ||
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromJSDate(date, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeMillisUtcLuxon(DateTime.fromJSDate(date, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
static fromMillis(millis, options) { | ||
return new DateTimeMillisUtcLuxon(luxon_1.DateTime.fromMillis(millis, Object.assign({ zone: luxon_1.FixedOffsetZone.utcInstance }, options))); | ||
return new DateTimeMillisUtcLuxon(DateTime.fromMillis(millis, { | ||
zone: FixedOffsetZone.utcInstance, | ||
...options, | ||
})); | ||
} | ||
@@ -311,2 +371,1 @@ normalize(dateTime) { | ||
} | ||
exports.DateTimeMillisUtcLuxon = DateTimeMillisUtcLuxon; |
import { ValidationContext, Validator, ValidationResult } from '@finnair/v-validation'; | ||
import { Path } from '@finnair/path'; | ||
import { DateTime, DateTimeJSOptions, DateTimeOptions } from 'luxon'; | ||
import { LuxonDateTime } from './luxon'; | ||
export declare type LuxonInput = string | DateTime | LuxonDateTime; | ||
import { LuxonDateTime } from './luxon.js'; | ||
export type LuxonInput = string | DateTime | LuxonDateTime; | ||
export interface ValidateLuxonParams { | ||
@@ -7,0 +7,0 @@ type: string; |
@@ -1,17 +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()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Vluxon = exports.TimeDurationValidator = exports.DurationValidator = exports.validateLuxonNumber = exports.LuxonValidator = void 0; | ||
const v_validation_1 = require("@finnair/v-validation"); | ||
const luxon_1 = require("luxon"); | ||
const luxon_2 = require("./luxon"); | ||
class LuxonValidator extends v_validation_1.Validator { | ||
import { isNullOrUndefined, defaultViolations, isString, V, Validator, TypeMismatch } from '@finnair/v-validation'; | ||
import { DateTime, Duration, FixedOffsetZone } from 'luxon'; | ||
import { LocalDateLuxon, DateTimeLuxon, DateTimeMillisLuxon, DateTimeMillisUtcLuxon, DateTimeUtcLuxon, LocalTimeLuxon, LocalDateTimeLuxon, } from './luxon.js'; | ||
export class LuxonValidator extends Validator { | ||
params; | ||
constructor(params) { | ||
@@ -25,4 +14,4 @@ super(); | ||
const params = this.params; | ||
if ((0, v_validation_1.isNullOrUndefined)(value)) { | ||
return ctx.failurePromise(v_validation_1.defaultViolations.notNull(path), value); | ||
if (isNullOrUndefined(value)) { | ||
return ctx.failurePromise(defaultViolations.notNull(path), value); | ||
} | ||
@@ -32,3 +21,3 @@ if (params.proto && value instanceof params.proto) { | ||
} | ||
else if (luxon_1.DateTime.isDateTime(value)) { | ||
else if (DateTime.isDateTime(value)) { | ||
if (value.isValid) { | ||
@@ -38,3 +27,3 @@ return success(value); | ||
} | ||
else if ((0, v_validation_1.isString)(value)) { | ||
else if (isString(value)) { | ||
const match = params.pattern.exec(value); | ||
@@ -48,3 +37,3 @@ if (match) { | ||
} | ||
return ctx.failurePromise(v_validation_1.defaultViolations.date(value, path, params.type), value); | ||
return ctx.failurePromise(defaultViolations.date(value, path, params.type), value); | ||
function success(dateTime) { | ||
@@ -55,3 +44,2 @@ return ctx.successPromise(params.proto ? new params.proto(dateTime) : dateTime); | ||
} | ||
exports.LuxonValidator = LuxonValidator; | ||
const datePattern = /^\d{4}-\d{2}-\d{2}$/; | ||
@@ -61,23 +49,23 @@ function localDate(options = { setZone: true }) { | ||
type: 'Date', | ||
proto: luxon_2.LocalDateLuxon, | ||
proto: LocalDateLuxon, | ||
pattern: datePattern, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, { zone: luxon_1.FixedOffsetZone.utcInstance }), | ||
parser: (value) => DateTime.fromISO(value, { zone: FixedOffsetZone.utcInstance }), | ||
}); | ||
} | ||
const timePattern = /^\d{2}:\d{2}:\d{2}$/; | ||
function localTime(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) { | ||
function localTime(options = { zone: FixedOffsetZone.utcInstance }) { | ||
return new LuxonValidator({ | ||
type: 'Time', | ||
proto: luxon_2.LocalTimeLuxon, | ||
proto: LocalTimeLuxon, | ||
pattern: timePattern, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, options), | ||
parser: (value) => DateTime.fromISO(value, options), | ||
}); | ||
} | ||
const localDateTimePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/; | ||
function localDateTime(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) { | ||
function localDateTime(options = { zone: FixedOffsetZone.utcInstance }) { | ||
return new LuxonValidator({ | ||
type: 'DateTime', | ||
proto: luxon_2.LocalDateTimeLuxon, | ||
proto: LocalDateTimeLuxon, | ||
pattern: localDateTimePattern, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, options), | ||
parser: (value) => DateTime.fromISO(value, options), | ||
}); | ||
@@ -89,13 +77,13 @@ } | ||
type: 'DateTime', | ||
proto: luxon_2.DateTimeLuxon, | ||
proto: DateTimeLuxon, | ||
pattern: dateTimeTzPattern, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, options), | ||
parser: (value) => DateTime.fromISO(value, options), | ||
}); | ||
} | ||
function dateTimeUtc(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) { | ||
function dateTimeUtc(options = { zone: FixedOffsetZone.utcInstance }) { | ||
return new LuxonValidator({ | ||
type: 'DateTime', | ||
proto: luxon_2.DateTimeUtcLuxon, | ||
proto: DateTimeUtcLuxon, | ||
pattern: dateTimeTzPattern, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, options), | ||
parser: (value) => DateTime.fromISO(value, options), | ||
}); | ||
@@ -107,13 +95,13 @@ } | ||
type: 'DateTimeMillis', | ||
proto: luxon_2.DateTimeMillisLuxon, | ||
proto: DateTimeMillisLuxon, | ||
pattern: dateTimeMillisPattern, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, options), | ||
parser: (value) => DateTime.fromISO(value, options), | ||
}); | ||
} | ||
function dateTimeMillisUtc(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) { | ||
function dateTimeMillisUtc(options = { zone: FixedOffsetZone.utcInstance }) { | ||
return new LuxonValidator({ | ||
type: 'DateTimeMillis', | ||
proto: luxon_2.DateTimeMillisUtcLuxon, | ||
proto: DateTimeMillisUtcLuxon, | ||
pattern: dateTimeMillisPattern, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, options), | ||
parser: (value) => DateTime.fromISO(value, options), | ||
}); | ||
@@ -125,3 +113,3 @@ } | ||
pattern: /./, | ||
parser: (value) => luxon_1.DateTime.fromISO(value, options), | ||
parser: (value) => DateTime.fromISO(value, options), | ||
}); | ||
@@ -133,3 +121,3 @@ } | ||
pattern: /./, | ||
parser: (value) => luxon_1.DateTime.fromRFC2822(value, options), | ||
parser: (value) => DateTime.fromRFC2822(value, options), | ||
}); | ||
@@ -141,34 +129,31 @@ } | ||
pattern: /./, | ||
parser: (value) => luxon_1.DateTime.fromHTTP(value, options), | ||
parser: (value) => DateTime.fromHTTP(value, options), | ||
}); | ||
} | ||
function dateTimeFromSQL(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) { | ||
function dateTimeFromSQL(options = { zone: FixedOffsetZone.utcInstance }) { | ||
return new LuxonValidator({ | ||
type: 'SQLDateTime', | ||
pattern: /./, | ||
parser: (value) => luxon_1.DateTime.fromSQL(value, options), | ||
parser: (value) => DateTime.fromSQL(value, options), | ||
}); | ||
} | ||
function validateLuxonNumber({ value, path, ctx, type, parser }) { | ||
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 async function validateLuxonNumber({ value, path, ctx, type, parser }) { | ||
if (isNullOrUndefined(value)) { | ||
return ctx.failure(defaultViolations.notNull(path), value); | ||
} | ||
else if (DateTime.isDateTime(value)) { | ||
if (value.isValid) { | ||
return ctx.success(value); | ||
} | ||
else if (luxon_1.DateTime.isDateTime(value)) { | ||
if (value.isValid) { | ||
return ctx.success(value); | ||
} | ||
} | ||
else if (typeof value === 'number' && !Number.isNaN(value)) { | ||
const dateTime = parser(value); | ||
if (dateTime.isValid) { | ||
return ctx.success(dateTime); | ||
} | ||
else if (typeof value === 'number' && !Number.isNaN(value)) { | ||
const dateTime = parser(value); | ||
if (dateTime.isValid) { | ||
return ctx.success(dateTime); | ||
} | ||
} | ||
return ctx.failure(v_validation_1.defaultViolations.date(value, path, type), value); | ||
}); | ||
} | ||
return ctx.failure(defaultViolations.date(value, path, type), value); | ||
} | ||
exports.validateLuxonNumber = validateLuxonNumber; | ||
function dateTimeFromMillis(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) { | ||
return v_validation_1.V.fn((value, path, ctx) => validateLuxonNumber({ | ||
function dateTimeFromMillis(options = { zone: FixedOffsetZone.utcInstance }) { | ||
return V.fn((value, path, ctx) => validateLuxonNumber({ | ||
value, | ||
@@ -178,7 +163,7 @@ path, | ||
type: 'MillisDateTime', | ||
parser: value => luxon_1.DateTime.fromMillis(value, options), | ||
parser: value => DateTime.fromMillis(value, options), | ||
})); | ||
} | ||
function dateTimeFromSeconds(options = { zone: luxon_1.FixedOffsetZone.utcInstance }) { | ||
return v_validation_1.V.fn((value, path, ctx) => validateLuxonNumber({ | ||
function dateTimeFromSeconds(options = { zone: FixedOffsetZone.utcInstance }) { | ||
return V.fn((value, path, ctx) => validateLuxonNumber({ | ||
value, | ||
@@ -188,47 +173,41 @@ path, | ||
type: 'SecondsDateTime', | ||
parser: value => luxon_1.DateTime.fromSeconds(value, options), | ||
parser: value => DateTime.fromSeconds(value, options), | ||
})); | ||
} | ||
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); | ||
} | ||
else if (Duration.isDuration(value)) { | ||
return ctx.success(value); | ||
} | ||
else if (isString(value) && durationPattern.test(value)) { | ||
const duration = Duration.fromISO(value); | ||
if (duration.isValid) { | ||
return ctx.success(duration); | ||
} | ||
else if (luxon_1.Duration.isDuration(value)) { | ||
return ctx.success(value); | ||
} | ||
else if ((0, v_validation_1.isString)(value) && durationPattern.test(value)) { | ||
const duration = luxon_1.Duration.fromISO(value); | ||
if (duration.isValid) { | ||
return ctx.success(duration); | ||
} | ||
} | ||
return ctx.failure(new v_validation_1.TypeMismatch(path, 'Duration', value), value); | ||
}); | ||
} | ||
return ctx.failure(new TypeMismatch(path, 'Duration', value), value); | ||
} | ||
} | ||
exports.DurationValidator = DurationValidator; | ||
class TimeDurationValidator 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 TimeDurationValidator extends Validator { | ||
async validatePath(value, path, ctx) { | ||
if (isNullOrUndefined(value)) { | ||
return ctx.failure(defaultViolations.notNull(path), value); | ||
} | ||
else if (Duration.isDuration(value)) { | ||
return ctx.success(value); | ||
} | ||
else if (isString(value)) { | ||
const duration = Duration.fromISOTime(value); | ||
if (duration.isValid) { | ||
return ctx.success(duration); | ||
} | ||
else if (luxon_1.Duration.isDuration(value)) { | ||
return ctx.success(value); | ||
} | ||
else if ((0, v_validation_1.isString)(value)) { | ||
const duration = luxon_1.Duration.fromISOTime(value); | ||
if (duration.isValid) { | ||
return ctx.success(duration); | ||
} | ||
} | ||
return ctx.failure(new v_validation_1.TypeMismatch(path, 'TimeDuration', value), value); | ||
}); | ||
} | ||
return ctx.failure(new TypeMismatch(path, 'TimeDuration', value), value); | ||
} | ||
} | ||
exports.TimeDurationValidator = TimeDurationValidator; | ||
exports.Vluxon = { | ||
export const Vluxon = { | ||
// DateTime wrapper validators | ||
@@ -252,2 +231,2 @@ localDate, | ||
}; | ||
Object.freeze(exports.Vluxon); | ||
Object.freeze(Vluxon); |
{ | ||
"name": "@finnair/v-validation-luxon", | ||
"version": "4.3.0", | ||
"version": "5.0.0", | ||
"private": false, | ||
"description": "Luxon 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/luxon#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" | ||
} |
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
760
Yes
43448
10
+ Added@finnair/path@5.4.0(transitive)
+ Added@finnair/v-validation@5.4.0(transitive)
- Removed@finnair/path@4.0.0(transitive)
- Removed@finnair/v-validation@4.3.0(transitive)
Updated@finnair/path@^5.0.0
Updated@finnair/v-validation@^5.0.0