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

date-lube

v1.4.2

Published

Simplify Date Manipulation in JavaScript

Downloads

8

Readme

Date Lube

Simplify Date Manipulation in JavaScript

Working with dates in JavaScript can often be challenging, especially when it comes to parsing, formatting, and performing calculations.
However, with the "date-lube" library, managing dates becomes a seamless experience.
This powerful JavaScript library provides a comprehensive set of functions that simplify date manipulation tasks and empower developers to work efficiently with dates.

Installation

npm i date-lube
pnpm i date-lube
bun i date-lube

How to use

To convert Date time

import { add } from "date-lube"

var d: Date = add(new Date, "-2Y")
//=> Date { 2 year ago }

var d: Date = add(new Date, "-1D")
//=> Date { yesterday }

var d: Date = add(new Date(0), "1Y2M-3D 4H 5m6s -7sss")
//=> Date { 1971-02-26T04:05:05.993Z }

var d: Date = add(new Date(0), "1Y-3D2M 4H 5m6s -7sss")
//=> Date { 1971-03-01T04:05:05.993Z }

To convert Date to String

import { dateToString } from "date-lube"

var s: string = dateToString(new Date("2222-03-04T11:22:33.444"))
//=> "2222-03-04T11:22:33.444"

var s: string = dateToString(
    new Date("2222-03-04T11:22:33.444"),
    "HHhmmmssSsss _ YYYY/MM/DD"
)
//=> "11h22m33s444 _ 2222/03/04"

To convert String to Date

import { stringToDate } from "date-lube"

var d: Date = stringToDate("2222-03-04T11:22:33.444")
//=> Date { 2222-03-04T11:22:33.444 in Locale }

var d: Date = stringToDate(
    "11h22m33s444 _ 2222/03/04",
    "HH mm ss sss _ YYYY MM DD"
)
//=> Date { 2222-03-04T11:22:33.444 in Locale }

To convert Date using time zone offset

import { timeZone } from "date-lube"
import { TimeZone } from "date-lube/@types"

var d: Date = new Date// UTC+9
//=> Date { now }

var d: Date = timeZone(new Date, "Europe/London")
//=> Date { 8 or 9 hours ago }

var d: Date = timeZone(new Date, "America/New_York")
//=> Date { 13 or 14 hours ago }

var d: Date = timeZone(new Date, "America/New_York", true)
//=> Date { 13 or 14 hours later }

var arr: TimeZone[] = ["America/New_York", "Zulu"]
for (var tz of arr) {
	timeZone(new Date, tz)
}

Time Unit

import { timeUnit } from "date-lube"

typeof timeUnit == {
	DD: 86400000// 1day = 86400000ms
	HH: 3600000// 1hour = 3600000ms
	mm: 60000// 1minute = 60000ms
	ss: 1000// 1second = 1000ms
}