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

tscron

v1.0.0

Published

TS-CRON is a library for cron, supports finding the next time a cron will run along with its description.

Downloads

1

Readme

ts-cron

APIs

TS-CRON is a library for cron. It provides a class named SpecSchedule that has two methods:

  • next(cronSyntax:string, date:Date):Date This method returns a new Date on which the cron is supposed to run after the provided date. For example, if the current date is: 2020 December 5, and the cron syntax is * * 1 * * then the output will be 1/1/2021, 12:00:00 AM.

  • describe(cronSyntax:string):string This method provides a description of the cron syntax. For example, the description for the cron syntax * * 1 * * is Every minute On Day-Of-Month 1.

Example

This project comes with a command line cli that can used to test with these two methods:

$npm run compile

> [email protected] compile .\typescript-project
> tsc

$node dist/src/cli.js help
ts-cron help:

commands:
next: To print the next date on which the cron is supposed to run
   Option:
       --cron or -c : For the cron Syntax, like, * 12-18/3 * 2 5
describe: To print the cron description
   Option:
       --cron or -c : For the cron Syntax
help: To print help docs
$node dist/src/cli.js next --cron="* * 1 * *"
1/1/2021, 12:00:00 AM
$node dist/src/cli.js next -c="* * 1 * *"
1/1/2021, 12:00:00 AM
$node dist/src/cli.js describe -c="* * 1 * *"
Every minute On Day-Of-Month 1
$node dist/src/cli.js describe -cron="* * 1 * *"
Every minute On Day-Of-Month 1

Testing

The test cases are created using the mocha framework, and it can be executed using the following command:

$npm test

> [email protected] test .\typescript-project
> env TS_NODE_COMPILER_OPTIONS='{"module": "commonjs" }' mocha -r ts-node/register test/errors.ts test/**/*.ts



  Error Initialization
    √ invalidBitError
    √ ParseError
    √ InvalidPositionError

  setBits
    √ check bit status for spec 1-5/1
    √ check bit status for spec 1-5/2
    √ check bit status for spec 1-5/3
    √ check bit status for spec 1-5/10
    √ check bit status for spec 0-59/1
    √ check bit status for spec 0-59/5
    √ check bit status for spec 0-59/15

  getRange
    √ * for minute spec
    √ ?/2 for minute spec
    √ 1-30/2 for minute spec
    √ 5/5 must convert to 5-59/5 for minute spec
    √ spec = 1-15 without any step for minute spec
    √ single digit spec = 18 without any step for minute spec
    √ too many hyphens in the spec
    √ too many slashes or steps in the spec
    √ 0 as spec for day of month section
    √ 32 as spec for day of month section
    √ 1-0 as spec for day of month section
    √ Step = 0 for the spec 1-15/0 for day of month section

  mustParseInt
    √ 1 Digit Positive Number
    √ 2 Digit Positive Number
    √ 1 Digit Negative Number
    √ 2 Digit Negative Number

  parse
    √ check the bits for the cron 1 2 3 4 5
    √ check the bits for the cron 1 2 3 4 5
    √ blank string for cron expression
    √ cron expression with invalid number of fields

  Range
    √ constructor

  Describe
    √ test all the cron test cases

  Next
    √ test all the cron test cases


  33 passing (17ms)