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

plain-date

v1.0.1

Published

A simple, light-weight model for date handling

Downloads

3

Readme

plain-date

A simple, light-weight model for date handling in JavaScript

Module System

The package includes both an ESM module (browser-compatible) and CJS modules (npm-compatible).

plain-date is written in node-style and converted to ESM for wider distribution. The default is therefore the node variant.

CJS (node)

require('plain-date') gives you the PlainDate class. require('plain-date/calculation') gives you helper functions.

const PlainDate = require('plain-date')
const { startOfMonth, weekNumber } = require('plain-date/calculation')

ESM (browser)

index.mjs yields the PlainDate class as its default export and the helper functions as named exports.

import PlainDate, { startOfMonth, weekNumber } from 'plain-date'

API

Table of Contents

PlainDate

PlainDate objects represent calendar dates or months. They focus on ease of use and are very light in comparison with JavaScript's native Date type.

They have a small set of properties, are immutable, and every date can only ever exist once.

If you try to create a new PlainDate object with a date that has previously been created, you will receive that pre-existing PlainDate object.

Additionally, PlainDate objects can be intuitively compared.

PlainDate objects can be constructed with one to three parameters. Behaviour for unexpected inputs is not defined. In order to stay light-weight, there is no intelligent type checking.

Type: Object

Properties

Examples

new PlainDate('2019-04-01') === new PlainDate('2019-04-01') // => true
new PlainDate('2019-04-01') < new PlainDate('2019-04-01') // => false
new PlainDate('2019-04-01') < new PlainDate('2019-04-11') // => true
new PlainDate('2019-04-01') > new PlainDate('2019-04-11') // => false

getNativeDate

Creates a new equivalent Date object. Multiple calls yield multiple distinct objects.

Returns Date

getComplexDate

Returns Date

Meta

  • deprecated: Use getNativeDate instead

toString

Replaces each token in the given string by the appropriate string representation of the related data:

  • YYYY: full year-number.
  • YY: last two digits of year.
  • MM: zero-padded two-digit month.
  • DD: zero-padded two-digit date.

Defaults to the ISO format.

Parameters
  • format string (optional, default 'YYYY-MM[-DD]')

Returns string

valueOf

Enables fast comparison via < and >.

Returns number

PlainDate/3_parameters

Parameters

Examples

new PlainDate(2019, 4, 1)
new PlainDate('2019', '04', '01')

PlainDate/2_parameters

Parameters

Examples

new PlainDate(2019, 4)
new PlainDate('2019', '4')

PlainDate/1_parameter

Parameters

Examples

new PlainDate('2019-04-01')
new PlainDate('2019-04')
new PlainDate(new Date(2019,3,1))
new PlainDate({
  year: 2019,
  month: 4,
})

daysBetween

Parameters

Returns number Difference between both dates, in days.

startOfMonth

Parameters

Returns PlainDate The first of the same month.

endOfMonth

Parameters

Returns PlainDate The last of the same month.

startOfWeek

Parameters

Returns PlainDate The first of the same week.

endOfWeek

Parameters

Returns PlainDate The last of the same week.

weekNumber

Parameters

Returns number The number of the week within the current year, as per ISO 8601.