Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
js-calendar
Advanced tools
A client- or server-side JavaScript calendar for generating days, week days and week number for datepickers and apps. Provides day of the week, week number, month info, can start week on monday or sunday and some other cool stuff.
npm install js-calendar
You can find a demo for the Browser here. If you want to play around with it, check this jsFiddle.
- Generator - the main "Core" feature, a function to generate calendar days for the requested month
- addLabels - the default iterator that adds basic CSS classes to each day object and labels for column head
// require it
var jsCalendar = require('js-calendar');
// configure it
var generator = new jsCalendar.Generator({onlyDays: false, weekStart: 1, lang: 'en'});
// use it
var january = generator(year, month, iteratorFn);
The configuration object has 3 keys, all optional. Calling a new instance is usefull to cache for example different languages. The options are:
false
;0
for US date formating, starting week on sunday or 1
for monday, using the ISO 8601 standard, used for example in Europe. When not specified it will default to 1
;0
).Note: The default language is English.
(object) O object with keys:
As mentioned above you can pass a iterator function (or array of functions). The iteration function receives two arguments, a object with the day info and the lang passed to the generator function config. The object receives the following properties:
false
if its a label cell.weekLabel
, dayLabel
, prevMonth
, nextMonth
or monthDay
.false
if its a label cell.The this inside the iterator function is set to the month object that the generator will return.
The iterator function(s) must return
a object, that will override the original object.
This method adds CSS classes, labels the day-in-week name and ads month name to each day and the month object, in the configured language. It has a .setLabels
method that receives a object with extra labels/languages to add to the current labels. The default labels do not get re-writen by the setLabels
method.
Get just the days in a month:
var jsCalendar = require('js-calendar');
var jsCal = new jsCalendar.Generator({onlyDays: true});
var januaryDays = jsCal(2016, 0);
var totalDays = januaryDays.daysInMonth; // 29
var days = januaryDays.cells;
console.log(januaryDays);
// [
// {"desc":1,"week":6,"type":"monthDay","date":"2016-01-31T23:00:00.000Z","index":5},
// {"desc":2,"week":6,"type":"monthDay","date":"2016-02-01T23:00:00.000Z","index":6},
// etc...
Get days and labels in a month:
var jsCalendar = require('js-calendar');
var jsCal = new jsCalendar.Generator({onlyDays: true});
var days = jsCal(2016, 1, jsCalendar.addLabels).cells;
console.log(days);
// [
// {"desc":"monday","week":5,"type":"weekLabel","date":false,"index":1,"class":["week-number"]},
// {"desc":"tuesday","week":5,"type":"dayLabel","date":false,"index":2,"class":["column-name"]},
// etc...
Compile HTML with jade
js-calendar uses mocha. To run the tests do in your command line:
npm install
npm test
npm build
- add even more tests
- add more usefull iterator function for standard uses
- add more examples like jade compiler or some other use case
- make it easyer to use in the Brower (maybe a dist build folder)
FAQs
JavaScript calendar days generator
We found that js-calendar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.