# random-cron-generator

> Generate cron strings with random values.

Latest version **0.1.6** (published 2024-04-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install random-cron-generator
pnpm add random-cron-generator
yarn add random-cron-generator
bun add random-cron-generator
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2024-04-22 |
| First published | 2024-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 67.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shoki Ishii |
| Maintainers | sho-ki |
| Keywords | cron, random, generator |

## Links

- npm: https://www.npmjs.com/package/random-cron-generator
- Repository: https://github.com/Sho-ki/random-cron-generator
- Issues: https://github.com/Sho-ki/random-cron-generator/issues
- npm.io page: https://npm.io/package/random-cron-generator

## Dependencies (5)

- [luxon](https://npm.io/package/luxon.md) ^3.4.4
- [typescript](https://npm.io/package/typescript.md) ^5.4.5
- [cron-parser](https://npm.io/package/cron-parser.md) ^4.9.0
- [cron-validate](https://npm.io/package/cron-validate.md) ^1.4.5
- [cron-validator](https://npm.io/package/cron-validator.md) ^1.3.1

## Recent versions

- 0.1.6 (latest) — 2024-04-22
- 0.1.5 — 2024-04-22
- 0.1.4 — 2024-04-22
- 0.1.3 — 2024-04-22
- 0.1.2 — 2024-04-22
- 0.1.1 — 2024-04-21
- 0.1.0 — 2024-04-21

## README

# Random Cron Generator

This package provides tools to generate random cron expressions based on configurable parameters and calculate the next run time for any given cron expression. It uses `cron-validate` to ensure generated cron expressions are valid and `cron-parser` integrated with `luxon` for calculating run times.

## Features

- Generate random cron expressions with configurable settings.
- Validate cron expressions for correctness.
- Calculate the next run time of a cron expression.
- Optional logging of next run times during cron generation.

## Installation

Install the package with npm:

```bash
npm install random-cron-generator
```


## Usage
### Importing the module
```typescript
import { RandomCronGenerator, generateRandomCron, getNextRunTime } from 'random-cron-generator';
```

### Generating a Random Cron Expression
```typescript
// Generate a cron expression with default settings:
const cronExpression = generateRandomCron();
console.log(cronExpression); // Outputs a valid cron string (e.g. '0 0 * * *')

// Generate a cron expression with custom settings:
const customCronExpression = generateRandomCron({
    randomConfig: {
        minute: { min: 0, max: 59 }, // range of minutes
        hour: true, // random hour. If false, it will be * (default)
        dayOfMonth: '*/7', // string cron expression
        month: 5, // specific month
        dayOfWeek: undefined // * (default)
    },
    log: true // log the next run time
    }
); 
console.log(customCronExpression); // Outputs a valid cron string and logs the next run time (e.g. '33 * 1 10 *')
```

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