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

nowts

v1.4.4

Published

A library for date and time manipulation

Downloads

30

Readme

NowTS

NowTS is a lightweight, modular library for date and time manipulation. It provides a range of utilities for working with dates and times, including formatting, parsing, and calculating differences. NowTS is built with TypeScript to provide type safety and better development experience.

Features

  • Formatting dates and times
  • Parsing date and time strings
  • Adding and subtracting days and hours
  • Getting the difference in days between dates
  • Handling multiple time zones
  • Lightweight and modular
  • TypeScript support

Installation

You can install NowTS via npm:

npm install nowts

Usage

To use NowTS, you need to import and extend the desired plugins:

import NowTS from 'nowts';
import formatDate from 'nowts/plugins/formatDate';
import parseDate from 'nowts/plugins/parseDate';

NowTS.extend(formatDate);
NowTS.extend(parseDate);

const formattedDate = NowTS.formatDate(new Date(), 'YYYY-MM-DD');
const parsedDate = NowTS.parseDate('2024-01-01', 'YYYY-MM-DD');
console.log(formattedDate); // Outputs formatted date
console.log(parsedDate); // Outputs parsed date object

API

formatDate(date: Date, format: string): string

Formats a date object into a string according to the specified format.

parseDate(dateString: string, format: string, timezone?: string): Date

Parses a date string into a Date object according to the specified format and timezone.

addDaysToDate(date: Date, days: number): Date

Adds a specified number of days to a date object.

subtractDaysFromDate(date: Date, days: number): Date

Subtracts a specified number of days from a date object.

getDaysDifference(date1: Date, date2: Date): number

Returns the difference in days between two dates.

toISO(date: Date): string

Converts a date object to an ISO string.

startOfMonth(date: Date): Date

Returns a new date object set to the start of the month of the provided date.

endOfMonth(date: Date): Date

Returns a new date object set to the end of the month of the provided date.

formatCurrentTime(): string

Formats the current time in 'HH:mm:ss' format.

addHoursToDate(date: Date, hours: number): Date

Adds a specified number of hours to a date object.

subtractHoursFromDate(date: Date, hours: number): Date

Subtracts a specified number of hours from a date object.

parseTime(timeString: string): Date

Parses a time string into a Date object.

isLeapYear(year: number): boolean

Checks if a given year is a leap year.

isWeekday(date: Date): boolean

Checks if a given date is a weekday.

isSameDay(date1: Date, date2: Date): boolean

It compares two days and returns whether they are the same or not.

isBusinessDay(date: Date, holidays: Date[] = []): boolean

Check business days excluding holidays

Development

To set up the development environment, clone the repository and install the dependencies:

git clone https://github.com/lnpotter/NowTS.git
cd NowTS
npm install

Building the Library

To build the library, run:

npm run build

Running Tests

To run the tests, use:

npm run test

License

This project is licensed under the MIT License.