# cronut

> Tasty task scheduler with a mungable internal clock filling.

Latest version **2.1.1** (published 2016-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install cronut
pnpm add cronut
yarn add cronut
bun add cronut
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2016-10-14 |
| First published | 2016-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shannon Moeller |
| Maintainers | shannonmoeller |

## Links

- npm: https://www.npmjs.com/package/cronut
- Repository: https://github.com/shannonmoeller/cronut
- Homepage: https://github.com/shannonmoeller/cronut#readme
- Issues: https://github.com/shannonmoeller/cronut/issues
- npm.io page: https://npm.io/package/cronut

## Dependencies (2)

- [cron](https://npm.io/package/cron.md) ^1.1.1
- [moment-timezone](https://npm.io/package/moment-timezone.md) ^0.5.6

## Recent versions

- 2.1.1 (latest) — 2016-10-14
- 2.1.0 — 2016-10-13
- 2.0.1 — 2016-10-13
- 2.0.0 — 2016-10-12
- 1.1.1 — 2016-10-12
- 1.1.0 — 2016-10-12
- 1.0.3 — 2016-10-12
- 1.0.2 — 2016-10-12
- 1.0.1 — 2016-10-12
- 1.0.0 — 2016-10-12

## README

# `cronut`

[![NPM version][npm-img]][npm-url] [![Downloads][downloads-img]][npm-url] [![Build Status][travis-img]][travis-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Tip][amazon-img]][amazon-url]

Tasty task scheduler with a mungable internal clock filling.

## Install

    $ npm install --save cronut

## Usage

### Schedule Tasks

```js
import cronut from 'cronut';

const cron = cronut();

cron('0 0 0 * * *', () => {
    console.log('another hour');
});

cron('0 0 * * * *', () => {
    console.log('another minute');
});

cron('* * * * * *', () => {
    console.log('another second');
});

cron('0 30 0,12 * * 1-5', () => {
    console.log('12:30 AM and PM on weekdays');
});
```

### Unschedule Tasks

```js
const removeTask = cron('0 * * * * *', () => {
    // only run 10 or so times
    console.log('another second');
});

// Unschedule after 10 seconds
setTimeout(removeTask, 10000);
```

## API

### cronut()

Creates a new task scheduler.

```js
import cronut from 'cronut';

const cron = cronut();
```

### cron(pattern, task[, options]) : Function
### cron.addTask(pattern, task[, options]) : Function

- `pattern` `String`
- `task` `Function`
- `options` `Object`
  - `resolution` `Number` Default: `100`.

Patterns are any valid pattern supported by [`cron`](http://npm.im/cron). The task is the function to be executed at the appointed times. Returns a function to stop the task.

```js
cron('* * * * * *', () => {
    console.log('another second');
});

// same as

cron.addTask('* * * * * *', () => {
    console.log('another second');
});

// removable

const removeTask = cron.addTask('* * * * * *', () => {
    console.log('another second');
});

removeTask();
```

### cron.now(fn)

- `fn` `Function`

Sets the [`moment.now`](http://momentjs.com/docs/#/customization/now/) function and resets internal cron timers.

```js
cron.now(() => {
    // It's tomorrow! Heh heh.
    return Number(new Date()) + (24 * 60 * 60 * 1000);
});
```

## Why?

There are a bunch of task schedulers already available, but none of them allowed me to mess with the internal clock for timeline manipulation or testing purposes.

## Contribute

Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.

### Test

    $ npm test

----

© Shannon Moeller <me@shannonmoeller.com> (http://shannonmoeller.com)

Licensed under [MIT](http://shannonmoeller.com/mit.txt)

[amazon-img]:    https://img.shields.io/badge/amazon-tip_jar-yellow.svg?style=flat-square
[amazon-url]:    https://www.amazon.com/gp/registry/wishlist/1VQM9ID04YPC5?sort=universal-price
[coveralls-img]: http://img.shields.io/coveralls/shannonmoeller/cronut/master.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/shannonmoeller/cronut
[downloads-img]: http://img.shields.io/npm/dm/cronut.svg?style=flat-square
[npm-img]:       http://img.shields.io/npm/v/cronut.svg?style=flat-square
[npm-url]:       https://npmjs.org/package/cronut
[travis-img]:    http://img.shields.io/travis/shannonmoeller/cronut/master.svg?style=flat-square
[travis-url]:    https://travis-ci.org/shannonmoeller/cronut

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