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

cron-converter

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-converter - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

test/cron.extra.js

21

gulpfile.js

@@ -8,4 +8,6 @@ var browserify = require('browserify');

var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var nodemon = require('gulp-nodemon');
var sloc = require('gulp-sloc');
var source = require('vinyl-source-stream');
var tape = require('gulp-tape');
var uglify = require('gulp-uglify');

@@ -27,6 +29,14 @@

return gulp.src('test/*.js')
.pipe(mocha())
.pipe(tape())
.pipe(istanbul.writeReports());
});
gulp.task('watch', ['test'], function() {
return nodemon({
watch: ['src', 'test'],
tasks: ['test'],
verbose: false
});
});
gulp.task('jscs', function() {

@@ -44,2 +54,7 @@ return gulp.src(allJsFiles)

gulp.task('sloc', function() {
return gulp.src(allJsFiles)
.pipe(sloc());
});
gulp.task('coveralls', ['test'], function() {

@@ -62,3 +77,3 @@ return gulp.src('coverage/lcov.info')

gulp.task('lint', ['jshint', 'jscs']);
gulp.task('lint', ['sloc', 'jshint', 'jscs']);

@@ -65,0 +80,0 @@ gulp.task('default', ['build']);

7

package.json
{
"name": "cron-converter",
"version": "0.0.6",
"version": "0.0.7",
"description": "Cron string converter",

@@ -26,5 +26,8 @@ "main": "src/cron.js",

"gulp-jshint": "~2",
"gulp-mocha": "^2.2.0",
"gulp-nodemon": "^2.0.4",
"gulp-sloc": "^1.0.4",
"gulp-tape": "0.0.7",
"gulp-uglify": "^1.5.1",
"jshint": "~2",
"tape": "^4.3.0",
"vinyl-buffer": "^1.0.0",

@@ -31,0 +34,0 @@ "vinyl-source-stream": "^1.1.0"

@@ -7,3 +7,3 @@ # cron-converter

[![npm](https://img.shields.io/npm/v/cron-converter.svg)](https://www.npmjs.com/package/cron-converter)
[![Bower](https://img.shields.io/bower/v/cron-converter.svg)]()
![Bower](https://img.shields.io/bower/v/cron-converter.svg)
[![Build Status](https://travis-ci.org/roccivic/cron-converter.svg)](https://travis-ci.org/roccivic/cron-converter)

@@ -86,2 +86,14 @@ [![Coverage Status](https://coveralls.io/repos/roccivic/cron-converter/badge.svg?branch=master&service=github)](https://coveralls.io/github/roccivic/cron-converter?branch=master)

### Constructor options
```js
var cronInstance = new Cron({
outputWeekdayNames: true,
outputMonthNames: true
});
cronInstance.fromString('* * * 1-3 1-5');
// Prints: '* * * JAN-MAR MON-FRI'
console.log(cronInstance.toString());
```
## Test and build

@@ -96,1 +108,3 @@

```
Run ```gulp watch``` to continuously run unit tests as you edit the code

@@ -14,5 +14,11 @@ 'use strict';

* @constructor
* @param {object} options The options to use
* @this {Cron}
*/
function Cron() {
function Cron(options) {
if (options) {
this.options = options;
} else {
this.options = {};
}
this.parts = null;

@@ -34,4 +40,5 @@ this.seeker = new Seeker(this);

if (parts.length === 5) {
var options = this.options;
this.parts = parts.map(function(str, idx) {
var part = new Part(units[idx]);
var part = new Part(units[idx], options);
part.fromString(str);

@@ -38,0 +45,0 @@ return part;

@@ -12,4 +12,10 @@ 'use strict';

* @param {object} unit The unit of measurement of time (see units.js).
* @param {object} options The options to use
*/
function Part(unit) {
function Part(unit, options) {
if (options) {
this.options = options;
} else {
this.options = {};
}
this.unit = unit;

@@ -27,10 +33,12 @@ }

_.union(
arr.map(
function(value) {
value = parseInt(value, 10);
if (isNaN(value)) {
throw new Error('Invalid value');
this.fixSunday(
arr.map(
function(value) {
value = parseInt(value, 10);
if (isNaN(value)) {
throw new Error('Invalid value');
}
return value;
}
return value;
}
)
)

@@ -67,6 +75,8 @@ )

_.union(
_.flatten(
_.map(
rangeString.split(','),
this.parseRange
this.fixSunday(
_.flatten(
_.map(
rangeString.split(','),
this.parseRange
)
)

@@ -85,2 +95,22 @@ )

/**
* Replace all 7 with 0 as Sunday can
* be represented by both.
*
* @this {Part}
* @param {array} values The values to process.
* @return {array} The resulting array.
*/
Part.prototype.fixSunday = function(values) {
if (this.unit.name === 'weekday') {
values = values.map(function(value) {
if (value === 7) {
return 0;
}
return value;
});
}
return values;
};
/**
* Parses a range string

@@ -170,2 +200,18 @@ *

/**
* Replaces the alternative number representations of strings.
* Used for weekdays and months.
*
* @this {Part}
* @param {string} str The string to process.
* @return {string} The processed string.
*/
Part.prototype.replaceOutputAlternatives = function(str) {
var unit = this.unit;
for (var i = 0; i < unit.alt.length; i++) {
str = str.replace(i + unit.min, unit.alt[i]);
}
return str;
};
/**
* Checks if a sorted array is in the range of this.unit

@@ -321,22 +367,30 @@ *

Part.prototype.toString = function() {
var retval = '';
if (this.isFull()) {
return '*';
}
var step = this.getStep();
if (step && this.isInterval(step)) {
if (this.isFullInterval(step)) {
return '*/' + step;
retval = '*';
} else {
var step = this.getStep();
if (step && this.isInterval(step)) {
if (this.isFullInterval(step)) {
retval = '*/' + step;
} else {
retval = this.min() + '-' + this.max() + '/' + step;
}
} else {
return this.min() + '-' + this.max() + '/' + step;
retval = this.toRanges().map(function(range) {
if (range.length) {
return range[0] + '-' + range[1];
}
return range;
}).join(',');
}
} else {
return this.toRanges().map(function(range) {
if (range.length) {
return range[0] + '-' + range[1];
}
return range;
}).join(',');
if (this.options.outputWeekdayNames && this.unit.name == 'weekday') {
retval = this.replaceOutputAlternatives(retval);
} else if (this.options.outputMonthNames && this.unit.name == 'month') {
retval = this.replaceOutputAlternatives(retval);
}
}
return retval;
};
module.exports = Part;

@@ -59,2 +59,3 @@ 'use strict';

reset = 'endOf';
date.subtract(1, 'minute'); // Ensure prev and next cannot be same time
}

@@ -61,0 +62,0 @@ var retry = 24;

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