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

@finnair/v-validation-luxon

Package Overview
Dependencies
Maintainers
0
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@finnair/v-validation-luxon

Luxon validators

  • 6.0.0
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
228
decreased by-62.44%
Maintainers
0
Weekly downloads
 
Created
Source

npm version

v-validation-luxon

@finnair/v-validation-luxon is an extension to @finnair/v-validation.

Vluxon extension provides custom wrapper types for Luxon DateTime to support full JSON roundtrip with strict validation. Also plain DateTime validators are provided and custom formats are easy to define (see the code for examples).

Documentation for v-validation.

Getting Started

Install v-validation using yarn:

yarn add @finnair/v-validation-luxon

Or npm:

npm install @finnair/v-validation-luxon

Vluxon

Vluxon contains both plain DateTime validators and also validators that return DateTime wrappers that guarantee some normalizations (zone, date and/or time) and especially JSON serialization in the given format. The wrappers are immutable and they allow easy access to the DateTime instance for further processing. validateLuxon function can be used to build custom DateTime validators/converters by supplying a RegExp pattern and a parser function.

Supported DateTime Wrapper Types

ClassDescription
LuxonDateTimeAbstract base class for the wrappers.
LocalDateLuxonInput and JSON output in yyyy-MM-dd format. Time normalized to midnight UTC.
LocalTimeLuxonInput and JSON output in HH:mm:ss format. Date normalized to 1970-01-01 UTC (Unix Epoch).
DateTimeLuxonInput and JSON output in yyyy-MM-ddTHH:mm:ssZ format in local/given/parsed zone with milliseconds zeroed.
DateTimeUtcLuxonInput and JSON output in yyyy-MM-ddTHH:mm:ssZ format in UTC zone with milliseconds zeroed.
DateTimeMillisLuxonInput and JSON output in yyyy-MM-ddTHH:mm:ss.SSSZ format in local/given/parsed zone.
DateTimeMillisUtcLuxonInput and JSON output in yyyy-MM-ddTHH:mm:ss.SSSZ format in UTC zone.

Constructors

Wrapper types may be constructed with new from DateTime instance, but there are also shortcuts:

Static MethodDescription
now()Current time in DateTime* types.
nowUtc()Current UTC time in Local* types.
nowLocal(options?: DateTimeJSOptions)Current local time in Local* types (defaults to system zone).
fromISO(value: string, options?: DateTimeOptions)Parse from ISO format (see Luxon DateTime.fromISO).
fromFormat(value: string, format: string, options?: DateTimeOptions)Parse from custom format (see Luxon DateTime.fromFormat).
fromJSDate(date: Date, options?: { zone?: string | Zone })From JavaScript Date object (see Luxon DateTime.fromJSDate).
fromMillis(millis: number, options?: DateTimeJSOptions)From Unix millis timestamp (see Luxon DateTime.fromMillis).

Instance Methods

Wrappers are meant to be as thin as possible with most of the DateTime functionality accessed directly from the wrapped DateTime instance which is public readonly fiedl. However there are a few convenience methods for working with the wrapper types:

MethodDescription
as(type)Conversion to the given type that extends LuxonDateTime. Note that the conversion is not guaranted to be lossless.
wrap(fn: (dateTime: DateTime) => DateTime)Executes the given function on the wrapped DateTime and rewraps the result.
apply<R>(fn: (dateTime: DateTime) => R): RExecutes the given function on the wrapped DateTime and returns the result as it is.
valueOf()Conversion to millis. This allows comparing wrapper types directly using ==, <, >, <= or >=.
equals(other: any)Type-aware equality.
toJSON()Type-specific serialization (string).

Build-in Validators

Vluxon.FormatDescription
localDateyyyy-MM-ddLocal date (time normalized to midninght UTC).
localTimeHH:mm:ssLocal time (date normalized to 1970-01-01).
dateTimeyyyy-MM-ddTHH:mm:ssZDate and time in local (parsed) time zone.
dateTimeUtcyyyy-MM-ddTHH:mm:ssZDate and time in UTC time zone.
dateTimeMillisyyyy-MM-ddTHH:mm:ss.SSSZDate and time with millis in local (parsed) time zone.
dateTimeMillisUtcyyyy-MM-ddTHH:mm:ss.SSSZDate and time with millis in UTC time zone.
dateTimeFromISOAny ISOPlain Luxon DateTime from ISO format.
dateTimeFromRFC2822RFC2822Plain Luxon DateTime from RFC2822 format.
dateTimeFromHTTPHTTP date-timePlain Luxon DateTime from HTTP format.
dateTimeFromSQLSQL date-timePlain Luxon DateTime from SQL format.
dateTimeFromSecondsUnix timestamp (number)Plain Luxon DateTime from Unix timestamp in seconds.
dateTimeFromMillisUnix timestamp (number)Plain Luxon DateTime from Unix timestamp in milliseconds.
durationISO 8601 DurationLuxon Duration.fromISO with pattern validation.
timeDurationISO 8601 time string as DurationLuxon Duration.fromISOTime.

Keywords

FAQs

Package last updated on 16 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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