# lw-cron-parser

> Node.js library for parsing crontab instructions

Latest version **1.0.1** (published 2020-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install lw-cron-parser
pnpm add lw-cron-parser
yarn add lw-cron-parser
bun add lw-cron-parser
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-10-29 |
| First published | 2020-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=0.8 |
| Dependencies | 2 |
| Unpacked size | 35.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jeppe Kaare Larsen |
| Maintainers | jeppelarsen |
| Keywords | cron, crontab, parser |

## Links

- npm: https://www.npmjs.com/package/lw-cron-parser
- Repository: https://github.com/JeppeLarsen/lw-cron-parser
- Homepage: https://github.com/JeppeLarsen/lw-cron-parser#readme
- Issues: https://github.com/JeppeLarsen/lw-cron-parser/issues
- npm.io page: https://npm.io/package/lw-cron-parser

## Dependencies (2)

- [dayjs](https://npm.io/package/dayjs.md) ^1.9.3
- [is-nan](https://npm.io/package/is-nan.md) ^1.3.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-10-29
- 1.0.0 — 2020-10-29

## README

Lightweight Cron Parser
================

Lightweight Cron Parser is a fork of [cron-parser by Harri Siirak](https://github.com/harrisiirak/cron-parser) that utilizes [Day.js](https://day.js.org/en/) instead of [Moment Timezone](https://momentjs.com/timezone/). This significantly reduces the bundle size.

Timezones are not supported at the moment.

Setup
========
```bash
npm install lw-cron-parser
```

Supported format
========

```
*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    |
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)
```

Supports mixed use of ranges and range increments (L and W characters are not supported currently). See tests for examples.

Usage
========

Simple expression.

```javascript
var parser = require('cron-parser');

try {
  var interval = parser.parseExpression('*/2 * * * *');

  console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
  console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:44:00 GMT+0200 (EET)

  console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
  console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:40:00 GMT+0200 (EET)
} catch (err) {
  console.log('Error: ' + err.message);
}

```

Iteration with limited timespan. Also returns ES6 compatible iterator (when iterator flag is set to true).

```javascript
var parser = require('cron-parser');

var options = {
  currentDate: new Date('Wed, 26 Dec 2012 12:38:53 UTC'),
  endDate: new Date('Wed, 26 Dec 2012 14:40:00 UTC'),
  iterator: true
};

try {
  var interval = parser.parseExpression('*/22 * * * *', options);

  while (true) {
    try {
      var obj = interval.next();
      console.log('value:', obj.value.toString(), 'done:', obj.done);
    } catch (e) {
      break;
    }
  }

  // value: Wed Dec 26 2012 14:44:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 15:00:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 15:22:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 15:44:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 16:00:00 GMT+0200 (EET) done: false
  // value: Wed Dec 26 2012 16:22:00 GMT+0200 (EET) done: true
} catch (err) {
  console.log('Error: ' + err.message);
}

```

Options
========

* *currentDate* - Start date of the iteration
* *endDate* - End date of the iteration

`currentDate` and `endDate` accept `string`, `integer` and `Date` as input.

In case of using `string` as input, not every string format accepted
by the `Date` constructor will work correctly. The supported format are [`ISO8601`](https://en.wikipedia.org/wiki/ISO_8601)


* *iterator* - Return ES6 compatible iterator object 
* *utc* - Enable UTC

---
_Source: https://npm.io/package/lw-cron-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
