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

datelative

v0.0.8

Published

A library that converts relative string text to JavaScript dates

Downloads

229

Readme

Datelative

I wrote it '-5m' ago.

GitHub Workflow Status npm GitHub

Datelative is a JavaScript library that converts relative date strings to actual date objects. It's a handy tool for dealing with date and time manipulations in your JavaScript applications.

Installation

You can install Datelative using npm:

npm install datelative

Or using yarn:

yarn add datelative

Usage

First, import the relativeToDate function from the library:

import { relativeToDate } from 'datelative';

Then, you can use it to convert relative date strings to date objects. Here are some examples:

const reference = new Date(); // Optional reference date, defaults to the current date and time

// Add 2 days to the reference date
const date1 = relativeToDate('+2 days', reference);

// Subtract 2 days from the reference date
const date2 = relativeToDate('-2 days', reference);

// Add 2 weeks to the reference date
const date3 = relativeToDate('+2 weeks', reference);

// Subtract 2 weeks from the reference date
const date4 = relativeToDate('-2 weeks', reference);

// ... and so on for months, years, quarters, milliseconds, seconds, minutes, and hours

Available Units

The + sign is optional and can be omitted.

The space between the number and the unit is also optional.

For example +2 ms is the same as 2ms.

  • +2 ms
  • +2 milliseconds
  • +2 s
  • +2 sec
  • +2 second
  • +2 seconds
  • +2 Second
  • +2 Seconds
  • +2 m
  • +2 min
  • +2 minute
  • +2 minutes
  • +2 Min
  • +2 Minute
  • +2 Minutes
  • +2 h
  • +2 hr
  • +2 Hr
  • +2 hour
  • +2 hours
  • +2 Hour
  • +2 Hours
  • +2 d
  • +2 D
  • +2 day
  • +2 days
  • +2 Day
  • +2 Days
  • +2 w
  • +2 W
  • +2 wk
  • +2 Wk
  • +2 week
  • +2 weeks
  • +2 Week
  • +2 Weeks
  • +2 M
  • +2 mon
  • +2 month
  • +2 months
  • +2 Month
  • +2 Months
  • +2 y
  • +2 Y
  • +2 yr
  • +2 yrs
  • +2 year
  • +2 years
  • +2 Year
  • +2 Years
  • +2 q
  • +2 qr
  • +2 Q
  • +2 Qr
  • +2 qtr
  • +2 quarter
  • +2 quarters
  • +2 Quarter
  • +2 Quarters

see index.js for all available units.

Testing

This library includes a comprehensive set of tests to ensure its functionality. You can run these tests using npm:

npm test

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

This project is licensed under the terms of the MIT license.