Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cron-time-generator

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-time-generator - npm Package Compare versions

Comparing version 1.0.7 to 1.1.0

58

helpers.ts

@@ -1,2 +0,18 @@

// @ts-check
const DaysDictionary: Record<string,number> = {
sun: 0,
mon: 1,
tue: 2,
wed: 3,
thu: 4,
fri: 5,
sat: 6,
sunday: 0,
monday: 1,
tuesday: 2,
wednesday: 3,
thursday: 4,
friday: 5,
saturday: 6,
};
export = {

@@ -41,22 +57,26 @@ /**

if (typeof day === "number") return day;
day = day.toLowerCase();
day = day.trim().toLowerCase();
switch (day) {
case "sunday":
return 0;
case "monday":
return 1;
case "tuesday":
return 2;
case "wednesday":
return 3;
case "thursday":
return 4;
case "friday":
return 5;
case "saturday":
return 6;
default:
throw Error(`Day: "${day}" is not a valid day.`);
if (!DaysDictionary.hasOwnProperty(day))
throw Error(`Day: "${day}" is not a valid day.`);
return DaysDictionary[day];
},
/**
* Get the integer representation of multiple day strings.
* @param days
*/
daysToIntegers(days: (string | number)[]): number[] {
const newDays: number[] = [];
for (const day of days) {
if (typeof day === "string") {
newDays.push(this.dayToInt(day))
} else {
newDays.push(day);
}
}
return newDays;
},

@@ -63,0 +83,0 @@

@@ -171,2 +171,30 @@ import Helpers from './helpers';

/**
* On Specific Days
* @param {(string|number)[]} days
*/
static onSpecificDays(days: (string | number)[]) {
if (!Array.isArray(days) || days.length) {
throw new Error("onSpecificDays requires days to be an array of days string.");
}
days = Helpers.daysToIntegers(days);
return `0 0 * * ${days}`
}
/**
* On Specific Days At
* @param {(string|number)[]} days
* @param {number} hourOfTheDay - Hour of the Day
* @param {number} minuteOfTheHour - Minute of the hour
*/
static onSpecificDaysAt(days: (string | number)[], hourOfTheDay: number, minuteOfTheHour: number = 0) {
if (!Array.isArray(days) || days.length === 0) {
throw new Error("onSpecificDays requires days to be an array of days string.");
}
days = Helpers.daysToIntegers(days);
return `${minuteOfTheHour} ${hourOfTheDay} * * ${days}`
}
/**
* Every Week

@@ -184,3 +212,3 @@ */

*/
static everyWeekAt(dayOfTheWeek: number, hourOfTheDay: number = 0, minuteOfTheHour: number = 0): string {
static everyWeekAt(dayOfTheWeek: number | string, hourOfTheDay: number = 0, minuteOfTheHour: number = 0): string {
return `${minuteOfTheHour} ${hourOfTheDay} * * ${dayOfTheWeek}`

@@ -187,0 +215,0 @@ }

{
"name": "cron-time-generator",
"version": "1.0.7",
"version": "1.1.0",
"description": "Cron Time Expression Generator",
"main": "dist/index.js",
"main": "./dist/index.js",
"types": "./dist/types/index.d.ts",
"repository": "https://github.com/trapcodeio/cron-time.git",

@@ -23,8 +24,6 @@ "author": "trapcodeio",

"devDependencies": {
"@types/node": "^14.11.5",
"@types/node": "^14.14.14",
"japa": "^3.1.1",
"ts-node": "^9.0.0",
"ts-node-dev": "^1.0.0-pre.63",
"typescript": "^4.0.3"
"typescript": "^4.1.3"
}
}

@@ -67,3 +67,3 @@ # Cron-Time

By default week days is from **Monday** to **Friday** while weekend days are **Saturdays** and **Sundays**
By default, week days is from **Monday** to **Friday** while weekend days are **Saturdays** and **Sundays**

@@ -92,2 +92,11 @@ This can be changed like so:

### onSpecificDays and onSpecificDaysAt
To target specific days
```javascript
cronTime.onSpecificDays(['sunday', 'tuesday', 'thursday']); // 0 0 * * 0,2,4
// With time
cronTime.onSpecificDaysAt(['sunday', 'tuesday', 'thursday'], 3, 30); // 0 0 * * 0,2,4
```
### Every Nth Time

@@ -128,2 +137,3 @@ ```javascript

### All Functions

@@ -130,0 +140,0 @@

const test = require('japa');
const cronTime = require('./');
test('everyMinute()', assert => {
assert.equal(cronTime.everyMinute(), '* * * * *')
})
test('everyMinute(): "* * * * *"', assert => {
assert.equal(cronTime.everyMinute(), '* * * * *');
});
test('everyHour()', assert => assert.equal(cronTime.everyHour(), '0 * * * *'));
test('everyHour(): "0 * * * *"',
assert => assert.equal(cronTime.everyHour(), '0 * * * *'));
test('everyHourAt(30)', assert => assert.equal(cronTime.everyHourAt(30), '30 * * * *'));
test('everyHourAt(30): "30 * * * *"',
assert => assert.equal(cronTime.everyHourAt(30), '30 * * * *'));
test('everyDay()', assert => assert.equal(cronTime.everyDay(), '0 0 * * *'))
test('everyDay(): "0 0 * * *"',
assert => assert.equal(cronTime.everyDay(), '0 0 * * *'));
test('every(nth)', assert => {
assert.equal(cronTime.every(5).minutes(), '*/5 * * * *');
assert.equal(cronTime.every(5).hours(), '0 */5 * * *')
test('every(nth)', () => {
test('every(5).minutes(): "*/5 * * * *"',
assert => assert.equal(cronTime.every(5).minutes(), '*/5 * * * *'));
test('every(5).hours(): "0 */5 * * *"',
assert => assert.equal(cronTime.every(5).hours(), '0 */5 * * *'));
});
test(`onSpecificDays(['sunday', 'tuesday', 'thursday']): "0 0 * * 0,2,4"`, assert => {
assert.equal(
cronTime.onSpecificDays(['sunday', 'tuesday', 'thursday']),
'0 0 * * 0,2,4');
});
test(`onSpecificDaysAt(['sunday', 'tuesday', 'thursday'], 3, 30): "30 3 * * 0,2,4"`, assert => {
assert.equal(
cronTime.onSpecificDaysAt(['sunday', 'tuesday', 'thursday'], 3, 30),
'30 3 * * 0,2,4');
});

@@ -20,3 +20,3 @@ {

/* Generates corresponding '.d.ts' file. */
"declarationDir": "types",
"declarationDir": "dist/types",
/* Generates corresponding '.d.ts' file. */

@@ -87,5 +87,6 @@ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */

"exclude": [
"types",
"dist"
"dist",
"dist/types",
"test.js"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc