npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@finnair/v-validation-luxon

v7.0.0-alpha.8

Published

Luxon validators

Downloads

1,987

Readme

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

| Class | Description | | ---------------------- | ----------------------------------------------------------------------------------------------------------- | | LuxonDateTime | Abstract base class for the wrappers. | | LocalDateLuxon | Input and JSON output in yyyy-MM-dd format. Time normalized to midnight UTC. | | LocalTimeLuxon | Input and JSON output in HH:mm:ss format. Date normalized to 1970-01-01 UTC (Unix Epoch). | | DateTimeLuxon | Input and JSON output in yyyy-MM-ddTHH:mm:ssZ format in local/given/parsed zone with milliseconds zeroed. | | DateTimeUtcLuxon | Input and JSON output in yyyy-MM-ddTHH:mm:ssZ format in UTC zone with milliseconds zeroed. | | DateTimeMillisLuxon | Input and JSON output in yyyy-MM-ddTHH:mm:ss.SSSZ format in local/given/parsed zone. | | DateTimeMillisUtcLuxon | Input 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 Method | Description | | ---------------------------------------------------------------------- | --------------------------------------------------------------- | | 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:

| Method | Description | | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | | 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): R | Executes 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. | 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. |