@finnair/v-validation-luxon
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [4.2.0](https://github.com/finnair/v-validation/compare/v4.1.0...v4.2.0) (2023-01-24) | ||
### Features | ||
* Support ISO 8601 time string as Duration ([#89](https://github.com/finnair/v-validation/issues/89)) ([75fb154](https://github.com/finnair/v-validation/commit/75fb154fa5283e7a51d3301097c7ed759beeabd8)) | ||
# [4.1.0](https://github.com/finnair/v-validation/compare/v4.0.0...v4.1.0) (2022-11-22) | ||
@@ -8,0 +19,0 @@ |
@@ -7,1 +7,2 @@ "use strict"; | ||
console.log(dt.setZone(luxon_1.FixedOffsetZone.utcInstance)); | ||
console.log(luxon_1.Duration.fromISOTime('000900').toJSON()); |
@@ -41,2 +41,5 @@ import { ValidationContext, Validator, ValidationResult } from '@finnair/v-validation'; | ||
} | ||
export declare class TimeDurationValidator extends Validator { | ||
validatePath(value: any, path: Path, ctx: ValidationContext): Promise<ValidationResult>; | ||
} | ||
export declare const Vluxon: { | ||
@@ -57,3 +60,4 @@ localDate: typeof localDate; | ||
duration: () => DurationValidator; | ||
timeDuration: () => TimeDurationValidator; | ||
}; | ||
export {}; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Vluxon = exports.DurationValidator = exports.validateLuxonNumber = exports.LuxonValidator = void 0; | ||
exports.Vluxon = exports.TimeDurationValidator = exports.DurationValidator = exports.validateLuxonNumber = exports.LuxonValidator = void 0; | ||
const v_validation_1 = require("@finnair/v-validation"); | ||
@@ -201,2 +201,22 @@ const luxon_1 = require("luxon"); | ||
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); | ||
} | ||
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); | ||
}); | ||
} | ||
} | ||
exports.TimeDurationValidator = TimeDurationValidator; | ||
exports.Vluxon = { | ||
@@ -219,3 +239,4 @@ // DateTime wrapper validators | ||
duration: () => new DurationValidator(), | ||
timeDuration: () => new TimeDurationValidator(), | ||
}; | ||
Object.freeze(exports.Vluxon); |
{ | ||
"name": "@finnair/v-validation-luxon", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"private": false, | ||
@@ -34,3 +34,3 @@ "description": "Luxon validators", | ||
}, | ||
"gitHead": "7fa7827e86f5c6da14d89bf80a6b58408a84bf4d" | ||
"gitHead": "1a9091a370951283c32bc5c6f3770399e7afb6df" | ||
} |
@@ -77,16 +77,17 @@ [![npm version](https://badge.fury.io/js/%40finnair%2Fv-validation-luxon.svg)](https://badge.fury.io/js/%40finnair%2Fv-validation-luxon) | ||
| Vluxon. | Format | Description | | ||
| ------------------- | -------------------------- | --------------------------------------------------------- | | ||
| localDate | `yyyy-MM-dd` | Local date (time normalized to midninght UTC). | | ||
| localTime | `HH:mm:ss` | Local time (date normalized to 1970-01-01). | | ||
| 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. | | ||
| dateTimeFromISO | Any ISO | Plain Luxon DateTime from ISO format. | | ||
| dateTimeFromRFC2822 | RFC2822 | Plain Luxon DateTime from RFC2822 format. | | ||
| dateTimeFromHTTP | HTTP date-time | Plain Luxon DateTime from HTTP format. | | ||
| dateTimeFromSQL | SQL date-time | Plain Luxon DateTime from SQL format. | | ||
| dateTimeFromSeconds | Unix timestamp (number) | Plain Luxon DateTime from Unix timestamp in seconds. | | ||
| dateTimeFromMillis | Unix timestamp (number) | Plain Luxon DateTime from Unix timestamp in milliseconds. | | ||
| duration | ISO 8601 Duration | Luxon `Duration` with pattern validation. | | ||
| Vluxon. | Format | Description | | ||
| ------------------- | -------------------------------- | --------------------------------------------------------- | | ||
| localDate | `yyyy-MM-dd` | Local date (time normalized to midninght UTC). | | ||
| localTime | `HH:mm:ss` | Local time (date normalized to 1970-01-01). | | ||
| 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. | | ||
| dateTimeFromISO | Any ISO | Plain Luxon DateTime from ISO format. | | ||
| dateTimeFromRFC2822 | RFC2822 | Plain Luxon DateTime from RFC2822 format. | | ||
| dateTimeFromHTTP | HTTP date-time | Plain Luxon DateTime from HTTP format. | | ||
| dateTimeFromSQL | SQL date-time | Plain Luxon DateTime from SQL format. | | ||
| dateTimeFromSeconds | Unix timestamp (number) | Plain Luxon DateTime from Unix timestamp in seconds. | | ||
| dateTimeFromMillis | Unix timestamp (number) | Plain Luxon DateTime from Unix timestamp in milliseconds. | | ||
| duration | ISO 8601 Duration | Luxon `Duration.fromISO` with pattern validation. | | ||
| timeDuration | ISO 8601 time string as Duration | Luxon `Duration.fromISOTime`. | |
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
46209
746
93