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

datelish

v2.0.0

Published

This class helps parse, format, and transform dates.

Downloads

31

Readme

Datelish

Originally written to help work with calendar data, this class helps parse, format, and transform dates. It supports both Node and browser use.

Usage

Node

npm install datelish

var Datelish = require("datelish");

Minified version:

var Datelish = require("datelish/dist/Datelish.min");

Visit package on npm

npm

Browser

import Datelish from "datelish";

Minified version:

import Datelish from "datelish/dist/Datelish.min";

Script tag:

<script src="node_modules/datelish/dist/Datelish.min.js"></script>

Notes

  • This project is lightweight and dependency free.
  • The source code is written in ES6 and transpiled with Babel.
  • If you need to create documentation for local use, run npm run doc. Otherwise, visit the online docs.

Samples

Static Methods

Datelish.toLittleEndian(date, divider = "/", prepend0 = true);

Datelish.toLittleEndian(new Date(2016, 1, 1));
// 01/02/2016

Datelish.toLittleEndian(Datelish.today(), "-", false);
// 10-1-2016

Datelish.fromLittleEndian(dateStr);

Datelish.fromLittleEndian("1/2/2016");
// Mon Feb 01 2016 00:00:00 GMT-0500 (EST)

Datelish.toMiddleEndian(date, divider = "/", prepend0 = true);

Datelish.toMiddleEndian(new Date(2016, 1, 1));
// 02/01/2016

Datelish.toMiddleEndian(new Date(2016, 1, 1), ".");
// 02.01.2016

Datelish.fromMiddleEndian(dateStr);

Datelish.fromMiddleEndian("2/1/2016");
// Mon Feb 01 2016 00:00:00 GMT-0500 (EST)

Datelish.toBigEndian(date, divider = "/", prepend0 = true);

Datelish.toBigEndian(new Date(2016, 1, 1));
// 2016/02/01

Datelish.toBigEndian(new Date(2016, 1, 1), "", false);
// 20160201

Datelish.fromBigEndian(dateStr);

Datelish.fromBigEndian("2016/2/1");
// Mon Feb 01 2016 00:00:00 GMT-0500 (EST)

Datelish.fromBigEndian("2016.02.01");
// Mon Feb 01 2016 00:00:00 GMT-0500 (EST)

Datelish.toISO8601(date);

Datelish.toISO8601(new Date(2016, 1, 1));
// 2016-02-01T00:00:00-05:00

Datelish.daysTotal(month, year);

Datelish.daysTotal("february", 2015);
// 28

Datelish.daysTotal("feb", 2016);
// 29

Datelish.daysTotal(1, 2016);
// 29

Datelish.daysPerMonth(month, year);

Datelish.daysPerMonth("feb", 2016);
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29

Datelish.dayCount(startDate, endDate);

Datelish.dayCount(new Date(2016, 1, 1), new Date(2016, 1, 10));
// 9

Datelish.monthAsNames(short = false);

Datelish.monthAsNames();
// January, February, March, April, May, June, July, August, September, October, November, December

Datelish.monthAsNames(true);
// Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec

Datelish.monthNameToIndex(month);

Datelish.monthNameToIndex("feb");
// 1

Datelish.monthNameToIndex("february");
// 1

Datelish.monthIndexToName(index, short = false);

Datelish.monthIndexToName(1);
// February

Datelish.monthIndexToName(1, true);
// Feb

Datelish.monthsFrom(startDate, endDate, includeStartDate = false);

Datelish.monthsFrom(new Date(2016, 1, 1), new Date(2016, 3, 1));
// Tue Mar 01 2016 00:00:00 GMT-0500 (EST), Fri Apr 01 2016 00:00:00 GMT-0400 (EDT)

Datelish.monthsFrom(new Date(2016, 1, 1), new Date(2016, 3, 1), true);
// Mon Feb 01 2016 00:00:00 GMT-0500 (EST), Tue Mar 01 2016 00:00:00 GMT-0500 (EST), Fri Apr 01 2016 00:00:00 GMT-0400 (EDT)

Datelish.dateIsBetween(date, startDate, endDate, includeEndDate = false);

Datelish.dateIsBetween(new Date(2016, 1, 1), new Date(2000, 10, 1), new Date(2020, 1, 1));
// true

Datelish.dateIsAfter(date, isAfterDate);

Datelish.dateIsAfter(new Date(2016, 1, 1), new Date(2016, 0, 1));
// true

Datelish.dateIsBefore(date, isBeforeDate);

Datelish.dateIsBefore(new Date(2016, 1, 1), new Date(2016, 0, 1));
// false

Datelish.todayIs(date);

Datelish.todayIs(new Date(2016, 1, 1));
// false

Datelish.years(from, to);

Datelish.years(2016, 2020);
// 2016, 2017, 2018, 2019, 2020

Datelish.years(2016, "4");
// 2016, 2017, 2018, 2019, 2020

Datelish.currYear();

Datelish.currYear();
// 2017

Datelish.prepend0(val);

Datelish.prepend0(1);
// 01

Datelish.prepend0("1");
// 01

Datelish.toMinutes(sec, prepend0 = true);

Datelish.toMinutes(90);
// 01:30

Datelish.toMinutes(90, false);
// 1:30

Datelish.daysFromDate(date, n);

Datelish.daysFromDate(new Date(2016, 1, 1), 5);
// Sat Feb 06 2016 00:00:00 GMT-0500 (EST)

Datelish.daysFromDate(Datelish.today(), -1);
// Mon Jan 09 2017 00:00:00 GMT-0500 (EST)

Datelish.now();

Datelish.now();
// Tue Jan 10 2017 12:02:58 GMT-0500 (EST)

Datelish.today();

Datelish.today();
// Tue Jan 10 2017 00:00:00 GMT-0500 (EST)

Datelish.tomorrow();

Datelish.tomorrow();
// Wed Jan 11 2017 00:00:00 GMT-0500 (EST)

Datelish.yesterday();

Datelish.yesterday();
// Mon Jan 09 2017 00:00:00 GMT-0500 (EST)

Datelish.prevMonth(date = null);

Datelish.prevMonth();
// Thu Dec 01 2016 00:00:00 GMT-0500 (EST)

Datelish.prevMonth(new Date(2017, 11, 1));
// Wed Nov 01 2017 00:00:00 GMT-0400 (EDT)

Datelish.nextMonth(date = null);

Datelish.nextMonth();
// Wed Feb 01 2017 00:00:00 GMT-0500 (EST)

Datelish.nextMonth(new Date(2017, 11, 1));
// Mon Jan 01 2018 00:00:00 GMT-0500 (EST)

See the full documentation here.

License

Copyright (c) 2016 Leandro Silva (http://grafluxe.com)

Released under the MIT License.

See LICENSE.md for entire terms.