Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pallavJha/tscron
tscron is a library for cron in Typescript.
https://github.com/pallavJha/tscron
cron cron-syntax crontab
Last synced: 11 days ago
JSON representation
tscron is a library for cron in Typescript.
- Host: GitHub
- URL: https://github.com/pallavJha/tscron
- Owner: pallavJha
- License: cc0-1.0
- Created: 2020-11-28T14:07:32.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-31T14:04:53.000Z (over 3 years ago)
- Last Synced: 2024-09-19T02:27:55.617Z (about 2 months ago)
- Topics: cron, cron-syntax, crontab
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/tscron
- Size: 62.5 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - pallavJha/tscron - tscron is a library for cron in Typescript. (TypeScript)
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`](https://github.com/pallavJha/tscron/blob/master/src/schedule/schedule.ts#L70)
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`](https://github.com/pallavJha/tscron/blob/master/src/schedule/schedule.ts#L181)
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:
```bash
$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:
```bash
$npm test> [email protected] test .\typescript-project
> env TS_NODE_COMPILER_OPTIONS='{"module": "commonjs" }' mocha -r ts-node/register test/errors.ts test/**/*.tsError Initialization
√ invalidBitError
√ ParseError
√ InvalidPositionErrorsetBits
√ 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/15getRange
√ * 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 sectionmustParseInt
√ 1 Digit Positive Number
√ 2 Digit Positive Number
√ 1 Digit Negative Number
√ 2 Digit Negative Numberparse
√ 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 fieldsRange
√ constructorDescribe
√ test all the cron test casesNext
√ test all the cron test cases33 passing (17ms)
```