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

jstimes

v2.0.0

Published

A lightweight and efficient npm package providing essential time functions for JavaScript, empowering developers with versatile tools for handling time-related operations with ease.

Downloads

9

Readme

jstimes

A lightweight and efficient npm package providing essential time functions for JavaScript, empowering developers with versatile tools for handling time-related operations with ease.

Getting Started

To install the package, run the following command in your project directory:

$ npm i jstimes

or if you use Yarn:

$ yarn add jstimes

Functions

sleep :

Delay a promise a specified amount of milliseconds

import { sleep } from "jstimes";

console.log("start");

await sleep(3000); // should be placed in an async function

// Executed 3 seconds later
console.log("end");

isLeapYear :

Check if a year is a leap year

import { isLeapYear } from "jstimes";

console.log(isLeapYear("2024")); // true

isWeekend :

Checks if a given date falls on a weekend.

import { isWeekend } from "jstimes";

console.log(isWeekend(new Date("2024/07/07"))); // true

getDaysBetweenTwoDate :

returns the count of days between two dates

import { getDaysBetweenTwoDate } from "jstimes";

console.log(getDaysBetweenTwoDate("2024-01-02", "2024-01-08")); // 7

formatDuration :

Formats a duration (given in milliseconds) into a readable string (e.g., "1h 30m 45s").

import { formatDuration } from "jstimes";

console.log(formatDuration(108020000)); // "30h 0m 20s"

formatDate :

Formats a Date object into a readable string format.

import { formatDate } from "jstimes";

console.log(formatDate(new Date("2024/07/25"), "MM-DD at HH:mm")); // "07-25 at 00:00"

addDays :

Adds a specified number of days to a date.

import { addDays, formatDate } from "jstimes";

console.log(formatDate(addDays(new Date("2024/11/28"), 10), "YYYY-MM-DD")); // "2024-12-08"

subtractDays :

Subtracts a specified number of days from a date.

import { subtractDays, formatDate } from "jstimes";

console.log(formatDate(subtractDays(new Date("2024/11/28"), 40), "YYYY-MM-DD")); // 2024-10-19

addMonths :

Adds a specified number of months to a date.

import { addMonths, formatDate } from "jstimes";

console.log(formatDate(addMonths(new Date("2024/11/28"), 10), "YYYY-MM-DD")); // "2025-09-28"

subtractMonths :

Subtracts a specified number of months from a date.

import { subtractMonths, formatDate } from "jstimes";

console.log(
  formatDate(subtractMonths(new Date("2024/11/28"), 4), "YYYY-MM-DD")
); // "2024-07-28"

addHours :

Adds a specified number of hours to a date.

import { addHours, formatDate } from "jstimes";

console.log(
  formatDate(
    addHours(new Date("2024/11/28 08:10:05"), 10),
    "YYYY-MM-DD HH:mm:ss"
  )
); // "2024-11-28 18:10:05"

subtractHours :

Subtracts a specified number of hours from a date.

import { subtractHours, formatDate } from "jstimes";

console.log(
  formatDate(
    subtractHours(new Date("2024/11/28 23:10:05"), 10),
    "YYYY-MM-DD HH:mm:ss"
  )
); // "2024-11-28 13:10:05"

getWeekOfYear :

Returns the ISO week number for a given date.

import { getWeekOfYear } from "jstimes";

console.log(getWeekOfYear(new Date("2024/02/02"))); // 5

getDayOfYear :

Returns the day number of the year for a given date.

import { getDayOfYear } from "jstimes";

console.log(getDayOfYear(new Date("2024/02/28"))); // 59

Variables

weekDays :

weekDays = [
  { id: 0, label: "Monday", value: 0 },
  { id: 1, label: "Tuesday", value: 1 },
  ...,
  { id: 5, label: "Saturday", value: 5 },
  { id: 6, label: "Sunday", value: 6 },
];

Months :

Months = [
  { id: 0, label: "January", value: 0, shortLabel: "Jan" },
  { id: 1, label: "February", value: 1, shortLabel: "Feb" },
  ...,
  { id: 10, label: "November", value: 10, shortLabel: "Nov" },
  { id: 11, label: "December", value: 11, shortLabel: "Dec" },
];

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -m 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request!

Authors

  • Tofigh Nazari