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

dayparting

v0.2.0

Published

A Dayparting micro library to present time of day in Dayparts.

Downloads

2

Readme

Dayparting

A Dayparting micro library to present time of day in Dayparts.

i.e. 8:00 AM => Early Morning

It follows standard dayparting conventions (read more about Dayparting on Wikipedia).

###Example Example Results

###Configure

####In web browser Include dayparting.js like your any other JS file using script tag in your page <head>.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
	<title>My Webpage</title>
	...
	...
	<script type="text/javascript" src="js/dayparting.js"></script>
</head>

####In Node Environment Install dayparting using npm

npm install dayparting --save-dev

Use require to load Dayparting module.

var dayparting = require('dayparting');

###Use

####Basic Usage

  • Initialize: Instantiate the dayparting with a locale configuration.
var myDaypart = daypart({
	locale: 'en-US',
	localeJSON: {
		"en-US": {
	        "earlyMorning": "Early Morning",
	        "lateMorning": "Late Morning",
	        "afternoon": "Afternoon",
	        "earlyFringe": "Early Fringe",
	        "lateFringe": "Late Fringe",
	        "lateNight": "Late Night",
	        "overnight": "Overnight",
	        "primeAccess": "Prime Access",
	        "primeTime": "Prime Time"
	    }
	}
});

This will set en-US as default locale for myDaypart and use given localeJSON, note that structure of localeJSON follows ICU Message Syntax where keynames have to be same as given in the example. You can have strings for multiple locales within same localeJSON like (and thus load external JSON file containing strings for multiple locales);

{
	"en-US": {
        "earlyMorning": "Early Morning",
        "lateMorning": "Late Morning",
        ...
        ...
        "primeTime": "Prime Time"
    },
    "fr_FR": {
	    "earlyMorning": "Tôt le matin",
        "lateMorning": "Tard dans la matinée",
        ...
        ...
        "primeTime": "Prime Time"
    }
}
  • Call: Daypart provides a method for() which accepts date object as a parameter, and returns string representation for the time within that date object.
var date = new Date();

date.setHours(13);
date.setMinutes(15);

myDatepart.for(date); // returns 'Afternoon'

Use with Databinding

  • Initialize During initialization, along with locale and localeJSON, you can provide binding to enable data-binding on elements, it is false by default.
var myDaypart = daypart({
	locale: 'en-US',
	localeJSON: {
		"en-US": {
	        "earlyMorning": "Early Morning",
	        ....
	        "primeTime": "Prime Time"
	    }
	},
	binding: true
});
  • Attaching Elements Once myDaypart is initialized and you have DOM with existing elements as follows;
<div class="container">
	Will be aired at tomorrow 7:06 PM <label id="showTime"></label>
</div>

Use attach() to add elements which will be bound to Daypart.

myDaypart.attach(new Date(2015, 12, 24, 19, 06), document.getElementById('showTime'));

This will automatically set string for 7:06 PM in the label with en-US locale.

  • Switch Locales Once elements are attached with daypart object, simply call setLocale on the object and contents of all the attached elements will be updated automatically.
myDaypart.setLocale('fr-FR');

###Version Information

  • 0.2.0 - Added support for one-way data-binding to enable live locale switch, bug fixes.
  • 0.1.1 - Minor refactoring, README updated.
  • 0.1.0 - First Release.

###Author

Kushal Pandya