Giter Site home page Giter Site logo

elisekain / cronstrue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bradymholt/cronstrue

0.0 1.0 0.0 1.32 MB

JavaScript library that converts Cron expressions into human readable descriptions

Home Page: http://bradymholt.github.io/cRonstrue/

License: MIT License

JavaScript 3.79% TypeScript 96.21%

cronstrue's Introduction

cRonstrue Build Status NPM Package

cRonstrue is a JavaScript library that parses a cron expression and outputs a human readable description of the cron schedule. For example, given the expression "*/5 * * * *" it will output "Every 5 minutes".

This library was ported from the original C# implemenation called cron-expression-descriptor and is also available in a few other languages.

Features

  • Zero dependencies
  • Supports all cron expression special characters including * / , - ? L W, #
  • Supports 5, 6 (w/ seconds or year), or 7 (w/ seconds and year) part cron expressions
  • Supports Quartz Job Scheduler cron expressions
  • i18n support with 17 languages

Installation

cRonstrue is exported as an UMD module so it will work in an AMD, CommonJS or browser global context.

First, install the module:

npm install cronstrue

Then, depending upon your usage context, add a reference to it:

Node

var cronstrue = require('cronstrue');

ES6/TypeScript

import cronstrue from 'cronstrue';

Browser

The cronstrue.min.js file from the /dist folder in the npm package should be served to the browser. There are no dependencies so you can simply include the library in a <script> tag.

<script src="cronstrue.min.js" type="text/javascript"></script>
<script>
  var cronstrue = window.cronstrue;
</script>

Usage

cronstrue.toString("* * * * *");
> "Every minute"

cronstrue.toString("0 23 ? * MON-FRI");
> "At 11:00 PM, Monday through Friday"

cronstrue.toString("23 12 * * SUN#2");
> "At 12:23 PM, on the second Sunday of the month"

cronstrue.toString("23 14 * * SUN#2", { use24HourTimeFormat: true });
> "At 14:23, on the second Sunday of the month"

cronstrue.toString("* * * ? * 2-6/2", { dayOfWeekStartIndexZero: false });
> "Every second, every 2 days of the week, Monday through Friday"

For more usage examples, including a demonstration of how cRonstrue can handle some very complex cron expressions, you can reference the unit tests.

Demo

A demo is available here here.

i18n

To use the i18n support cRonstrue provides, you must use the packaged library that contains the locale transalations. Once you do this, you can pass the name of a supported locale as an option to cronstrue.toString(). For example, for the es (Spanish) locale, you would use: cronstrue.toString("* * * * *", { locale: "es" });.

Node

var cronstrue = require('cronstrue/i18n');
cronstrue.toString("*/5 * * * *", { locale: "fr" });

Browser

The cronstrue-i18n.min.js file from the /dist folder in the npm package should be served to the browser.

<script src="cronstrue-i18n.min.js" type="text/javascript"></script>
<script>
  cronstrue.toString("*/5 * * * *", { locale: "fr" });
</script>

Supported Locales

  • en - English
  • da - Danish
  • nl - Dutch
  • fr - French
  • de - German
  • it - Italian
  • ja - Japanese
  • nb - Norwegian
  • pl - Polish
  • pt_BR - Portuguese (Brazil)
  • ro - Romanian
  • ru - Russian
  • sl - Slovenian
  • es - Spanish
  • sv - Swedish
  • tr - Turkish
  • uk - Ukrainian
  • zh_CN - Chinese (Simplified)

License

cRonstrue is freely distributable under the terms of the MIT license.

cronstrue's People

Contributors

artigat1 avatar bradymholt avatar colegillespie avatar folderol4 avatar grisha-kotler avatar seveves avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.