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

@helloclub/joi-luxon

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helloclub/joi-luxon

A Joi extension to automatically convert ISO date strings to Luxon DateTime objects

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@helloclub/joi-luxon

npm version github issues

A Joi extension to automatically convert ISO date strings to Luxon DateTime objects

Hello Club

Features

  • Validates incoming date values as ISO date strings
  • Automatically converts date strings to Luxon DateTime objects
  • Able to set timezone and use modifiers like startOf or endOf
  • Able to validate against other dates or Joi references using functions like gt, lt, gte or lte

Installation

#npm
npm install @helloclub/joi-luxon

#yarn
yarn add @helloclub/joi-luxon

Usage

import Joi from 'joi'
import JoiLuxon from '@helloclub/joi-luxon'

export default Joi.extend(JoiLuxon)

Examples

Validate a start and end date, setting the date to start and end of day respectively and validating that the end date is after the start date:

const schema = Joi.object({
  startDate: Joi
    .luxon()
    .setZone(timezone)
    .startOf('day'),
  endDate: Joi
    .luxon()
    .setZone(timezone)
    .endOf('day')
    .gt(Joi.ref('startDate')),
})

Set the value to a given minimum date if it’s less than that:

const schema = Joi.object({
  date: Joi
    .luxon()
    .required()
    .min(Joi.ref('$minDate'))
})

const schema = Joi.object({
  date: Joi
    .luxon()
    .required()
    .min(new Date())
})

All available rules and helpers:

Joi

  //Base validation and conversion to Luxon DateTime object
  .luxon()

  //Sets the timezone on the object
  .setZone(timezone)

  //Modified the DateTime instance to the start/end of the given period
  .startOf(period)
  .endOf(period)

  //Validates silently against a minimum / maximum date
  .min(date)
  .max(date)

  //Validate and throw errors if the date is less than or greater than a reference date
  .lt(date)
  .gt(date)
  .lte(date)
  .gte(date)

Issues & feature requests

Please report any bugs, issues, suggestions and feature requests in the joi-luxon issue tracker.

Sponsor

This package is sponsored by Hello Club, an all-in-one club and membership management solution complete with booking system, automated membership renewals, online payments and integrated access and light control.

If you belong to any kind of club or membership based organisation, or if you know someone who helps run a club, please check us out!

License

(MIT License)

Copyright 2022-2023, Hello Club

Keywords

FAQs

Package last updated on 15 May 2023

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