cron-converter
Advanced tools
Comparing version 1.0.2 to 2.0.0
{ | ||
"name": "cron-converter", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Cron string converter", | ||
"main": "src/cron.js", | ||
"type": "module", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/mjs/index.js", | ||
"types": "./dist/mjs/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/mjs/index.js", | ||
"require": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"src", | ||
"tsconfig.json" | ||
], | ||
"scripts": { | ||
"lint": "yarn jshint && yarn jscs", | ||
"jshint": "jshint -c .jshintrc src test", | ||
"jscs": "jscs -c .jscsrc src test", | ||
"build": "yarn lint && yarn coverage && yarn dist", | ||
"test": "tape test/*", | ||
"coverage": "nyc --reporter lcov tape test/*", | ||
"browserify": "browserify -s Cron -e src/cron.js -o temp/cron.bundle.js", | ||
"uglify": "uglifyjs -o dist/cron.min.js temp/cron.bundle.js", | ||
"dist": "yarn browserify && yarn uglify && yarn clean-temp", | ||
"clean-temp": "rm -rf temp", | ||
"watch": "nodemon -w src -w test -x yarn test", | ||
"zuul": "zuul -- test/*.js", | ||
"preversion": "yarn build && git add --force dist/cron.min.js && git commit -m \"Updated cron.min.js\"" | ||
"build": "rm -rf dist && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run mjs && npm run cjs", | ||
"cjs": "echo \"{\\\"type\\\": \\\"commonjs\\\"}\" > dist/cjs/package.json", | ||
"mjs": "echo \"{\\\"type\\\": \\\"module\\\"}\" > dist/mjs/package.json", | ||
"prepare": "npm run build", | ||
"test": "mocha --extension ts --require ts-node/register --loader=ts-node/esm test", | ||
"coverage": "c8 -r lcov -e .ts -x 'test/**/*' npm run test" | ||
}, | ||
@@ -39,20 +46,23 @@ "keywords": [ | ||
"devDependencies": { | ||
"browserify": "~16", | ||
"browserify-shim": "^3.8.14", | ||
"isparta": "^4.1.1", | ||
"jscs": "^3.0.7", | ||
"jshint": "~2", | ||
"nyc": "~15", | ||
"tape": "~5", | ||
"uglify-js": "^3.6.0", | ||
"zuul": "^3.12.0" | ||
"@types/chai": "^4.2.21", | ||
"@types/luxon": "^3.1.0", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "*", | ||
"c8": "^7.12.0", | ||
"chai": "^4.3.4", | ||
"husky": "^7.0.2", | ||
"mocha": "^9.1.1", | ||
"prettier": "^2.3.2", | ||
"pretty-quick": "^3.1.1", | ||
"ts-node": "^10.2.1", | ||
"typescript": "^4.4.2" | ||
}, | ||
"dependencies": { | ||
"moment-timezone": "~0.5", | ||
"sprintf-js": "~1" | ||
"luxon": "^3.1.0" | ||
}, | ||
"browserify-shim": { | ||
"moment": "global:moment", | ||
"sprintf-js": "global:sprintf" | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
} | ||
} |
163
README.md
@@ -6,15 +6,15 @@ # cron-converter | ||
[![npm version](https://badge.fury.io/js/cron-converter.svg)](https://badge.fury.io/js/cron-converter) | ||
[![Bower version](https://badge.fury.io/bo/cron-converter.svg)](https://badge.fury.io/bo/cron-converter) | ||
[![Build status](https://github.com/roccivic/cron-converter/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/roccivic/cron-converter/actions/workflows/build.yml) | ||
[![Coverage Status](https://coveralls.io/repos/roccivic/cron-converter/badge.svg?branch=master&service=github)](https://coveralls.io/github/roccivic/cron-converter?branch=master) | ||
[![dependencies Status](https://status.david-dm.org/gh/roccivic/cron-converter.svg)](https://david-dm.org/roccivic/cron-converter) | ||
## Install | ||
Try the [online demo](https://cron-converter-demo.netlify.app/) and check the [source code](https://github.com/roccivic/cron-converter-demo) for the integration. | ||
### Npm | ||
# Install | ||
```bash | ||
yarn add cron-converter | ||
``` | ||
or | ||
```bash | ||
@@ -24,27 +24,28 @@ npm install cron-converter --save | ||
### Bower | ||
```bash | ||
bower install cron-converter --save | ||
``` | ||
# Compatibility | ||
## Use | ||
This step is for usage from node, | ||
the bower build exposes a global | ||
```js | ||
var Cron = require('cron-converter'); | ||
``` | ||
Versions `2.x.x` of `cron-converter` are not backwards compatible with versions `1.x.x`. | ||
### Create a new instance | ||
```js | ||
var cronInstance = new Cron(); | ||
| | `2.x.x` | `1.x.x` | | ||
| ---- | ------------- | ------------- | | ||
| API | Functional | Object-oriented | | ||
| Loader | ESM and CommonJS | CommonJS only | | ||
| Type definitions | Bundled | Install [`@types/cron-converter`](https://www.npmjs.com/package/@types/cron-converter) | | ||
| Date/time | [`Luxon`](https://moment.github.io/luxon/) | [`Moment.js`](https://momentjs.com/) | | ||
| Tree-shaking | ✅ | ❌ | | ||
# Import | ||
```ts | ||
import { stringToArray, arrayToString, getSchedule, getUnits } from "cron-converter"; | ||
``` | ||
### Parse a cron string | ||
```js | ||
# Usage | ||
## Convert a string to an array | ||
```ts | ||
// Every 10 mins between 9am and 5pm on the 1st of every month | ||
cronInstance.fromString('*/10 9-17 1 * *'); | ||
const arr = stringToArray("*/10 9-17 1 * *"); | ||
// Prints: '*/10 9-17 1 * *' | ||
console.log(cronInstance.toString()); | ||
// Prints: | ||
@@ -58,29 +59,65 @@ // [ | ||
// ] | ||
console.log(cronInstance.toArray()); | ||
console.log(arr); | ||
``` | ||
### Parse an Array | ||
```js | ||
cronInstance.fromArray([[0], [1], [1], [5], [0,2,4,6]]); | ||
## Convert an array to a string | ||
```ts | ||
const str = arrayToString([[0], [1], [1], [5], [0, 2, 4, 6]]); | ||
// Prints: '0 1 1 5 */2' | ||
console.log(cronInstance.toString()); | ||
console.log(str); | ||
``` | ||
### Get the schedule execution times | ||
```js | ||
// Parse a string to init a schedule | ||
cronInstance.fromString('*/5 * * * *'); | ||
## Formatting options | ||
### outputMonthNames | ||
Default: `false` | ||
```ts | ||
const arr = [[1], [1], [1], [1, 2, 3], [1, 2, 3]]; | ||
const str = arrayToString(arr, { outputMonthNames: true }); | ||
// Prints: '1 1 1 JAN-MAR 1-3' | ||
console.log(str); | ||
``` | ||
### outputWeekdayNames | ||
Default: `false` | ||
```ts | ||
const arr = [[1], [1], [1], [1, 2, 3], [1, 2, 3]]; | ||
const str = arrayToString(arr, { outputWeekdayNames: true }); | ||
// Prints: '1 1 1 1-3 MON-WED' | ||
console.log(str); | ||
``` | ||
### outputHashes | ||
Default: `false` | ||
```ts | ||
const arr = [[1], [1], [1], [1, 6, 11], [0, 1, 2, 3, 4, 5, 6]]; | ||
// Prints: '1 1 1 H/5 H' | ||
console.log(arrayToString(arr, { outputHashes: true })); | ||
``` | ||
## Get the schedule execution times | ||
```ts | ||
// Convert a string to an array | ||
const arr = stringToArray("*/5 * * * *"); | ||
// Get the iterator, initialised to now | ||
var schedule = cronInstance.schedule(); | ||
let schedule = getSchedule(arr); | ||
// Optionally, use a reference Date or moment object | ||
var reference = new Date(2013, 2, 8, 9, 32); | ||
reference = moment([2013, 2, 8, 9, 32]); | ||
// And pass the reference to .schedule() | ||
schedule = cronInstance.schedule(reference); | ||
// Optionally pass a reference `Date` and a `timezone` | ||
let reference = new Date(2013, 2, 8, 9, 32); | ||
const schedule = getSchedule(arr, reference, "Europe/London"); | ||
// Calls to ```.next()``` and ```.prev()``` | ||
// return a Moment.js object | ||
// Calls to `.next()` and `.prev()` return a Luxon `DateTime` object | ||
@@ -101,38 +138,8 @@ // Prints: '2013-03-08T09:35:00+00:00'' | ||
### Constructor options | ||
#### outputWeekdayNames and outputMonthNames | ||
Default: false | ||
```js | ||
var cronInstance = new Cron({ | ||
outputWeekdayNames: true, | ||
outputMonthNames: true | ||
}); | ||
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5'); | ||
// Prints: '*/5 *(10-16)/2 * JAN-MAR MON-FRI' | ||
console.log(cronInstance.toString()); | ||
## Get the units configuration | ||
This is useful if you are creating a user interface. See [units.ts](./src/units.ts). | ||
```ts | ||
const units = getUnits(); | ||
``` | ||
#### outputHashes | ||
Default: false | ||
```js | ||
var cronInstance = new Cron({ | ||
outputHashes: true | ||
}); | ||
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5'); | ||
// Prints: 'H/5 H(10-16)/2 H 1-3 1-5' | ||
console.log(cronInstance.toString()); | ||
``` | ||
#### timezone | ||
Default: Local timezone | ||
```js | ||
var cronInstance = new Cron({ | ||
timezone: "Europe/London" | ||
}); | ||
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5'); | ||
// Finds the next execution time in the London timezone | ||
console.log(cronInstance.schedule().next()); | ||
``` | ||
## Test and build | ||
@@ -143,6 +150,6 @@ | ||
cd cron-converter | ||
yarn install | ||
yarn | ||
yarn build | ||
yarn test | ||
yarn coverage | ||
``` | ||
Run ```yarn watch``` to continuously run unit tests as you edit the code |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77742
1
36
2490
151
Yes
12
1
+ Addedluxon@^3.1.0
+ Addedluxon@3.5.0(transitive)
- Removedmoment-timezone@~0.5
- Removedsprintf-js@~1
- Removedmoment@2.30.1(transitive)
- Removedmoment-timezone@0.5.46(transitive)
- Removedsprintf-js@1.1.3(transitive)