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

nb-moment-calendar

v0.8.2

Published

NB Moment Calendar core

Downloads

27

Readme

NB MOMENT CALENDAR

This is the base class for generator calendar using moment.js and lodash

This created because of another project I am working on - NB Angular Calendar

By separating them, the developer can have access just the underlying data.


UPDATE: Dec 2016 from V0.7.0 completely rewritten in ES6, and the export module will be in UMD format.

Install

bower install nb-moment-calendar --save

In our bower.json file, I have set to use the locale version instead; because using the standard version cause a bug when try to change the start of week from Sunday to Monday (google it, lots of people have the same problem). If you don't want to include a big file. You can still do it by override it in your bower - with the locale files that you need.

 {
	 "override": {
		 "moment": [
		 	"moment.js",
			"locale/en-gb.js"
		 ]
	 }		 
 }

Or use it with your node / browsersify / webpack project

npm install nb-moment-calendar --save

// in your js

const NBMomentCalendar = require('nb-moment-calendar');
const calInstance = new NBMomentCalendar['default'](); // note this is due to the UMD export

// ESPECIALLY FOR BROWSER
var moment = new NBMomentCalendar['default']();

This is why I EXTREMELY HIGHLY RECOMMEND YOU TO START USING ES6!!!!

import NBMomentCalendar from 'nb-moment-calendar';

no fuss!

DEMO

Clone this repo, cd into the root directory then

$ npm run demo

The file is demo.js.

Usage

~We have a top level name space NB (In browser) and this package is MomentDateGenerator~

 var nbMomentCalObj = new NBMomentCalendar.default();

Internally we guarantee the config get run at least once. But you could also provide your configuration as soon as you have init the instance.

By default we have the following options

var options = {
	locale: 'en-gb',
	localeConfig: {
		weekdaysMin: ['Mo' , 'Tu' , 'We' , 'Th' , 'Fr' , 'Sa' , 'Su'],
		week : {
			dow : 1 // Monday is the first day of the week
		}
	}
};

The following method pass to the init method like this:

moment.locale(this.options.locale , this.options.localeConfig);

The this.options will merge with your configuration first (see API below)


API

List of API available

getMoment(options)

Setup the moment configuration, note that moment is mutable, once we call the config, and we will reuse the same moment object internally. Until it gets re-init again.

note the previous ~~setOptions~~ move to a private method. This is the only method to call during init.

getConfig()

return the config options.

getMonth(year , month)

This is a breaking change in V0.7.0. It was call get before. But using ES6 get has a differnet meaning

  • year (int) 4 digit (or any moment accepted year format)
  • month (int) month in digit (not index!)

This method is a wrapper of getMergeMonth and lookup if there is a cache version first.

This will return (array) weeks (array by week index) in the format below

	{
		'day': _date.format('D'),
		'wend': (wend===0 || wend===6),
		'fday': _date.format('YYYY-MM-DD'),
		'wday': _date.isoWeekday()
	}

We don't provide the underlying moment object because most of the time, you don't need it. So save some memory size. And if you need it, at the beginning of the call, if you use the getMoment method, you already got the original object. Then just create a clone to work with it.

var nbCalMoment = calInstance.getMoment(options);
var yourMomentClone = nbCalMoment().clone();

getYear(year , headingFormat)

  • year (int) year in 4 digit

Return (array) 12 months of padded month data. In the following format

{
	year: year
	month: month,
	heading: 'MMM YYYY' || headingFormat
	data: [blocks of months]
}

getMonths(year , month , months , headingFormat)

  • year (int) start year
  • month (int) start month
  • months (int) total months you want to retrieve from the start month
  • headingFormat (string) how you want to format the month heading

This will return the number of padded months you specified. In the same format as getYear

getRawMonths(year , month , months)

  • year (int) start year
  • month (int) start month
  • months (int) total months you want to retrieve from the start month

This will return the number of months (no padding) you specified.


Develop

There is a simple test file in the same folder, just run:

$ gulp dev

Will open your default browser.

And you can generate the compress version with. We are using rollup since the V0.7.0

$ npm run build

Joel Chu © 2015

-- EOF --