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

time-pocket

v2.2.4

Published

Simple time utilities

Downloads

42

Readme

Time Pocket - time utilities

Some simple time utilities which you can have with you while developing in JS.

🌟 Types Included 🌟

How to use

Install

npm install time-pocket --save-dev

namedDay()

Returns day name if it is today, tomorrow or yesterday, otherwise returns the day of the week.

Arguments

| Number | Type | Description | | ------ | ---- | -------------------- | | 0 | Date | Date to get day from |

Examples

import { datePrettify } from 'time-pocket'
const today = new Date(Date.now())

const yesterday = new Date(today)
yesterday.setDate(yesterday.getDate() - 1)

const tomorrow = new Date(today)
tomorrow.setDate(tomorrow.getDate() + 1)

const randomDate = new Date(today)
randomDate.setDate(randomDate.getDate() + 12)

console.log(namedDay(today))
console.log(namedDay(tomorrow))
console.log(namedDay(yesterday))
console.log(namedDay(randomDate))

/*
Today
Tomorrow
Yesterday
Thursday
*/

datePrettify()

Returns date in pretty format

Arguments

| Number | Type | Description | | ------ | ------------------- | ------------------ | | 0 | Date | Date to prettify | | 1 | Options | Additional options |

Options

| Name | Type | Default | Description | | ------ | ------- | ----------- | ----------------------------------------- | | pretty | boolean | true | If you also want the prettified string | | format | string | DD-YY-MM DY | Format of the output of the pretty fromat |

Formats

| Name | Description | Example | Description | | ---- | ----------- | ------- | ---------------- | | DD | Date | 19 | Date | | MM | Month | January | Month in Letters | | mM | Month (N) | Jan | Month short | | mm | Month (N) | 01 | Month in Numbers | | YY | Year | 2021 | Year | | DY | Day | Monday | Day full | | dy | Day | Mon | Day short |

Examples

import { datePrettify } from 'time-pocket'
const today = new Date(Date.now())

console.log(datePrettify(today))
/* 
{
  date: 29,
  month: 'May',
  year: 2021,
  day: 'Saturday',
  pretty: '29-May-2021, Saturday'
}
*/

console.log(datePrettify(today, { pretty: true, format: 'DD mM MM mm YY DY dy' }))
/*
{
  date: 29,
  month: 'January',
  year: 2021,
  day: 'Friday',
  pretty: '29 01 January Jan 2021 Friday Fri'
}
*/

timePrettify()

Returns date in pretty format

Arguments

| Number | Type | Description | | ------ | ------------------- | -------------------------- | | 0 | Date | Date to prettify time from | | 1 | Options | Additional options |

Options

| Name | Type | Default | Description | | ---------- | ------- | ------- | -------------------------------------- | | pretty | boolean | true | If you also want the prettified string | | twelveHour | boolean | false | If you want the time in 12 hour format |

Examples

import { timePrettify } from 'time-pocket'
const today = new Date(Date.now())

console.log(timePrettify(today))
/* 
{ hour: 19, min: 57, sec: 59, pretty: '19:57:59' }
*/

hoursToMinSec()

Convert decimal hours to min and seconds

Arguments

| Number | Type | Description | | ------ | ------------------- | --------------------- | | 0 | number | Decimal time in hours | | 1 | Options | Additional options |

Options

| Name | Type | Default | Description | | ------------ | ------- | ------- | ------------------------------------ | | milliseconds | boolean | false | Also return the milliseconds | | txt | boolean | false | Also return the value in text format |

Examples

import { hoursToMinSec } from 'time-pocket'

console.log(hoursToMinSec(1.25))
// { hours: 1, minutes: 15, seconds: 0 }

console.log(hoursToMinSec(21.2534))
// { hours: 21, minutes: 15, seconds: 12 }

console.log(hoursToMinSec(0.756))
// { hours: 0, minutes: 45, seconds: 21 }

console.log(hoursToMinSec(1.25, { milliseconds: true, txt: true }))
/* 
{
  hours: 1,
  minutes: 15,
  seconds: 0,
  milliseconds: 0,
  txt: '1 hour 15 min 0 sec'
}
*/

console.log(hoursToMinSec(0.756, { milliseconds: true, txt: true }))

/*
{
  hours: 0,
  minutes: 45,
  seconds: 21,
  txt: '45 min 21 sec 599 millisecond',
  milliseconds: 599,
}
*/

timeDifference()

Convert decimal hours to min and seconds

Arguments

| Number | Type | Description | | ------ | ------- | ----------------------------------------- | ---------- | | 0 | string | Date | Start date | | 1 | string | Date | End date | | 2 | Boolean | If you want to seconds in the text output |

Examples

import { timeDifference } from 'time-pocket'

const today = new Date(Date.now())

const endDate = new Date(today)

endDate.setMinutes(endDate.getMinutes() + 5)

console.log(timeDifference(endDate, String(today)))
// { hours: 0, minutes: 5, seconds: 0, txt: '5 min 0 sec' }