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

format-your-date

v2.0.4

Published

A simple date formatting package providing a variety of date formats.

Downloads

7

Readme

format-your-date

format-your-date is a lightweight and flexible Node.js package for formatting JavaScript Date objects into various customizable date formats. Whether you need a simple date format or a more complex one with full month names, this package has you covered.

Features

  • Supports multiple date formats, including numeric and text-based month representations
  • Customizable date separator options
  • Lightweight and easy to use
  • Written in TypeScript for type safety
  • Compatible with modern JavaScript environments

Installation

Install the package via npm:

npm install format-your-date

Usage

Importing the Package

import { DateFormatter } from 'format-your-date';

Basic Formating

You can easily format a Date object into various formats as shown below.

const date = new Date();

console.log(DateFormatter.formatDate(date, 'dd-mm-yyyy')); // Output: 24-08-2024
console.log(DateFormatter.formatDate(date, 'fullDate')); // Output: Saturday, 24 August 2024

Custom Separator

You can use a custom separator (like . or /) between the date components.

console.log(DateFormatter.formatWithCustomSeparator(date, '/', 'dd-mm-yyyy')); // Output: 24/08/2024
console.log(DateFormatter.formatWithCustomSeparator(date, '.', 'yyyy-mm-dd')); // Output: 2024.08.24

Supported Formats

The package supports a variety of date formats, allowing flexibility in how you want your date to be displayed:

| Format | Example Output | |------------------|--------------------------| | dd-mm-yyyy | 24-08-2024 | | mm-dd-yyyy | 08-24-2024 | | yyyy-mm-dd | 2024-08-24 | | dd/mm/yyyy | 24/08/2024 | | mm/dd/yyyy | 08/24/2024 | | yyyy/mm/dd | 2024/08/24 | | fullDate | Saturday, 24 August 2024 | | dd-mmm-yyyy | 24 Aug, 2024 | | dd-mmmm-yyyy | 24 August, 2024 | | mmm-dd-yyyy | Aug 24, 2024 | | mmmm-dd-yyyy | August 24, 2024 |

Customizing Format

In the format string:

  • dd: Day of the month (2 digits)
  • mm: Month as a number (2 digits)
  • mmm: Month as a short name (e.g., Aug)
  • mmmm: Full month name (e.g., August)
  • yyyy: Full year (e.g., 2024)

Functions

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

Formats a Date object into the specified format.

Parameters:

  • date: The JavaScript Date object to be formatted.
  • format: A string representing the desired date format (e.g., dd-mm-yyyy).

Returns:

  • A string representing the formatted date.

Example:

const date = new Date();

// Basic formats
console.log(DateFormatter.formatDate(date, 'dd-mm-yyyy')); // Output: 24-08-2024
console.log(DateFormatter.formatDate(date, 'mm-dd-yyyy')); // Output: 08-24-2024
console.log(DateFormatter.formatDate(date, 'yyyy-mm-dd')); // Output: 2024-08-24

// Full date
console.log(DateFormatter.formatDate(date, 'fullDate')); // Output: Saturday, 24 August 2024

// Month names
console.log(DateFormatter.formatDate(date, 'dd-mmm-yyyy')); // Output: 24 Aug, 2024
console.log(DateFormatter.formatDate(date, 'dd-mmmm-yyyy')); // Output: 24 August, 2024
console.log(DateFormatter.formatDate(date, 'mmmm-dd-yyyy')); // Output: August 24, 2024
console.log(DateFormatter.formatDate(date, 'mmm-dd-yyyy')); // Output: Aug 24, 2024

// ISO and timestamp
console.log(DateFormatter.formatToISO(date)); // Output: 2024-08-24T00:00:00.000Z
console.log(DateFormatter.formatToTimestamp(date)); // Output: 1692844800000 (example)

const customSeparatorDate = new DateFormatter();
console.log(customSeparatorDate.formatWithCustomSeparator(date, '/', 'dd/mm/yyyy')); // Output: 24/08/2024

// Time formats
console.log(DateFormatter.formatToTime(date, '24-hour')); // Output: 00:00
console.log(DateFormatter.formatToTime(date, '12-hour')); // Output: 12:00 AM

// Relative time
console.log(DateFormatter.formatToRelativeTime(new Date(new Date().getTime() - 3600000))); // Output: 1 hour ago

// Parsing date
console.log(DateFormatter.parseDate('24-08-2024', 'dd-mm-yyyy')); // Output: Sat Aug 24 2024 ...

// Human-readable time
console.log(DateFormatter.formatToHumanReadable(new Date())); // Output: today

// Utility functions
console.log(DateFormatter.isValidDate(new Date())); // Output: true
console.log(DateFormatter.isLeapYear(2024)); // Output: true
console.log(DateFormatter.daysInMonth(2024, 1)); // Output: 29
console.log(DateFormatter.weekNumber(new Date())); // Output: 34 (example)

Development

To contribute or modify the package, follow these steps:

  1. Clone the repository:
git clone https://github.com/Anshjatana/format-your-date.git
  1. Install the dependencies:
npm install
  1. Build the project:
npm run build

This will generate the files in the dist/ folder.

  1. Test your changes locally before publishing or submitting a pull request.

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, feel free to open an issue or create a pull request. GitHub Repo: Repository

Author

👤 Ansh Jatana

License

This project is licensed under the MIT License - see the LICENSE file for details.

This project was created with ❤️ by Ansh Jatana