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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@timclark/sdate

v1.0.9

Published

A simple date class with methods to manipulate the date and format the date

Readme

sdate

A simple and immutable date library for TypeScript/JavaScript.

sdate provides a straightforward and chainable API for common date manipulations, ensuring that you always work with predictable and immutable date objects.

Installation

npm install @timclark/sdate

Usage

Import the sdate class and create a new instance.

import sdate from '@timclark/sdate';

// Create a date object for today
const today = new sdate();

// Create a date object for a specific date
const specificDate = new sdate('2023-10-27');

// The sdate object is immutable. All manipulation methods return a new sdate instance.
const nextWeek = specificDate.addDays(7);

console.log(specificDate.toString()); // Output: 2023-10-27
console.log(nextWeek.toString());     // Output: 2023-11-03

API Reference

constructor(dateString?: string | Date)

Creates a new sdate instance.

  • If no argument is provided, it initializes with the current date.
  • dateString: An optional string in YYYY-MM-DD format or a Date object.

addDays(days: number): sdate

Adds a specified number of days to the date. Returns a new sdate instance.


addMonths(months: number): sdate

Adds a specified number of months to the date. Returns a new sdate instance.


addYears(years: number): sdate

Adds a specified number of years to the date. Returns a new sdate instance.


difference(anotherDate: sdate): number

Calculates the difference in days between the sdate instance and another.


fDate(): string

Formats the date as DD/MM/YYYY.


equals(anotherDate: sdate | Date): boolean

Checks if the sdate instance is equal to another sdate or Date object.


toString(): string

Returns the date as a string in YYYY-MM-DD format.


year(): number

Returns the four-digit year.


yearShort(): string

Returns the last two digits of the year.


month(): number

Returns the month (1-12).


monthPad(): string

Returns the month, padded with a leading zero if necessary (e.g., 01, 12).


date(): number

Returns the day of the month (1-31).


datePad(): string

Returns the day of the month, padded with a leading zero if necessary.


day(): number

Returns the day of the week (0 for Sunday, 1 for Monday, etc.).


ymd(): { year: number, month: number, date: number }

Returns an object containing the year, month, and day.


ymddt(): { year: number, month: number, date: number, day: number }

Returns an object containing the year, month, day, and day of the week.


startOfWeek(): sdate

Returns a new sdate instance for the start of the week (Monday).


daysInWeek(): sdate[]

Returns an array of sdate objects for the entire week (Monday to Sunday).


isInArray(arrayToCheck: (string | sdate | Date)[]): boolean

Checks if the sdate instance exists in an array of dates.


inMonth(year?: number, month?: number): boolean

Checks if the date is in a specific month. Defaults to the current month if no arguments are provided.


isToday(): boolean

Checks if the date is today.


startOfMonth(): sdate

Returns a new sdate instance for the first day of the month.


endOfMonth(): sdate

Returns a new sdate instance for the last day of the month.


daysInMonth(): sdate[]

Returns an array of sdate objects for every day in the month.