npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cronstrue-zh_cn

v1.60.7

Published

Convert cron expressions into human readable descriptions

Downloads

115

Readme

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 24 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 i cronstrue-zh_cn

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

Node

var cronstrue = require('cronstrue-zh_cn');

ES6/TypeScript

import cronstrue from 'cronstrue-zh_cn';

Browser

The cronstrue-zh_cn.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-zh_cn.min.js" type="text/javascript"></script>
<script>
  var cronstrue = window.cronstrue;
</script>

CDN

A simple way to load the library in a browser is by using the unpkg CDN, which is a "fast, global content delivery network for everything on npm". To use it, include a script tag like this in your file:

<script src="https://unpkg.com/cronstrue@latest/dist/cronstrue.min.js" async></script>

Using the "latest" tag will result in a 302 redirect to the latest version tag so it is highly recommended to use a specific version tag such as https://unpkg.com/[email protected]/dist/cronstrue.min.js to avoid this redirect.

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
  • cs - Czech
  • es - Spanish
  • da - Danish
  • de - German
  • fi - Finnish
  • fr - French
  • he - Hebrew
  • it - Italian
  • ja - Japanese
  • nb - Norwegian
  • nl - Dutch
  • pl - Polish
  • pt_BR - Portuguese (Brazil)
  • ro - Romanian
  • ru - Russian
  • sk - Slovakian
  • sl - Slovenian
  • sw - Swahili
  • sv - Swedish
  • tr - Turkish
  • uk - Ukrainian
  • zh_CN - Chinese (Simplified)
  • zh_TW - Chinese (Traditional)

License

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