🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

ts-cron-validator

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-cron-validator

TypeScript type-level CRON expression validator

1.1.5
latest
Source
npm
Version published
Weekly downloads
448
-10.76%
Maintainers
1
Weekly downloads
 
Created
Source

ts-cron-validator

A TypeScript type level CRON expression validator!

VSCode screenshot!

Expressions supported are the one generated and describe on crontab.guru website. This means that you can use this library to check standard CRON expressions but also non standard one. Also, this type level validator works quite well in conjunction with cron engines such as node-cron.

For a live demo, you can try this codesandbox

Usage

To install this tiny library:

  
  npm install ts-cron-validator

Then you have the choice between two helper functions:

  • validStandardCronExpression() if you use a scheduler that understands only standard CRON expressions.
  • validCronExpression() if you use a scheduler that also understands non standard expressions.

Below some examples that show how to use those two helpers:

import { validCronExpression, validStandardCronExpression } from 'ts-cron-validator';

validStandardCronExpression('0 3 * * * ');      // OK padding accepted
validStandardCronExpression('42 * * *   ');     // KO missing day of week part
validStandardCronExpression('59 4 * * *');      // OK
validStandardCronExpression('60 4 * * *');      // KO incorrect minutes part 

validCronExpression('20 59 4 * dec mon');       // OK non standard CRON expression are accepted
                                                // by validCronExpression()

FAQs

Package last updated on 16 Dec 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