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

@tiny-libs/time

v1.0.0

Published

Tiny date/time formatting library.

Downloads

1

Readme

@tiny-libs/time

Tiny date/time formatting library. Inspired by Day.js and Moment.js.

Features

  • No chaining
  • Only practical APIs
  • Minimal and fast
  • Support Node.js and browser
  • ESM support

Install

npm i @tiny-libs/time

Usage

import time from '@tiny-libs/time'

time.format(new Date(), 'YYYY/MM/DD HH:mm')

APIs

format

Format date/time.

  • Type Signature:

    function format(date: Date, formatStr?: string): string
  • Example Usage:

    time.format(new Date(2024, 3, 19), 'YYYY-MM-DD') // 2024-03-19

    List of formats

    | Format | Output | Description | | ------ | ---------------- | ------------------------------------- | | YY | 24 | Two-digit year | | YYYY | 2024 | Four-digit year | | M | 1-12 | The month, beginning at 1 | | MM | 01-12 | The month, 2-digits | | MMM | Jan-Dec | The abbreviated month name | | MMMM | January-December | The full month name | | D | 1-31 | The day of the month | | DD | 01-31 | The day of the month, 2-digits | | d | 0-6 | The day of the week, with Sunday as 0 | | dd | Su-Sa | The min name of the day of the week | | ddd | Sun-Sat | The short name of the day of the week | | dddd | Sunday-Saturday | The name of the day of the week | | H | 0-23 | The hour | | HH | 00-23 | The hour, 2-digits | | h | 1-12 | The hour, 12-hour clock | | hh | 01-12 | The hour, 12-hour clock, 2-digits | | m | 0-59 | The minute | | mm | 00-59 | The minute, 2-digits | | s | 0-59 | The second | | ss | 00-59 | The second, 2-digits | | SSS | 000-999 | The millisecond, 3-digits | | Z | +05:00 | The offset from UTC, ±HH:mm | | ZZ | +0500 | The offset from UTC, ±HHmm | | A | AM PM | | | a | am pm | |

add

Clone a date object with a specified amount of time added.

  • Type Signature:

    function add(date: Date, num: number, unit: TimeUnit): Date

    Time Unit: second, minute, hour, day, week, month, year

  • Example Usage:

    time.add(new Date(), -1, 'day')

startOf

Clone a date object and set it to the start of the time unit.

  • Type Signature:

    function startOf(date: Date, unit?: TimeUnit): Date
  • Example Usage:

    time.startOf(new Date(), 'day')

endOf

Clone a date object and set it to the end of the time unit.

  • Type Signature:

    function endOf(date: Date, unit?: TimeUnit): Date
  • Example Usage:

    time.endOf(new Date(), 'day')

isSame

Compares two dates for equality in specified exact units.

  • Type Signature:

    function isSame(date1: Date, date2: Date, unit?: TimeUnit): boolean
  • Example Usage:

    const date = time.add(new Date(), -1, 'minute')
    
    time.isSame(date, new Date(), 'hour') // true

clone

Clone for specified date object.

  • Type Signature:

    function clone(date: Date | number): Date

from

Returns the string of relative time from now.

  • Type Signature:

    function fromNow(date: number | Date, withoutAffix?: boolean, allowNow?: boolean): string
  • Example Usage:

    const d1 = time.add(new Date(), -1, 'minute')
    const d2 = time.add(new Date(), 1, 'hour')
    
    time.fromNow(d1) // 1 minute ago
    time.fromNow(d2) // in 1 hour

    The base strings are localized by the current locale and can be customized with the relativeTime locale object.

socialize

Returns the social style date/time string of relative time from now.

  • Type Signature:

    function socialize(date: Date | number, displayHourMinute?: boolean): string
  • Example Usage:

    const d1 = new Date()
    const d2 = time.add(new Date(), 1, 'day')
    const d3 = time.add(new Date(), 2, 'day')
    
    time.socialize(d1) // 22:00
    time.socialize(d2) // Yesterday
    time.socialize(d3) // Monday 22:00

    | Range | Key | Sample Output | | ------------------------------------------ | ------------------------- | ---------------- | | Today | LT | 22:00 | | Yesterday | Yesterday | Yesterday LT | Yesterday 22:00 | | From this week to the day before yesterday | LW | LWT | wed 22:00 | | This year | LDM | LDMT | 11/12 22:00 | | Before this year | LDMY | LDMYT | 11/12/2024 22:00 |

    These strings are localized, and can be customized with the formats locale object.

I18n

Built-in en-US and zh-CN locales. You can customize the locale by following other locale object templates.

import time from '@tiny-libs/time'
import zh from '@tiny-libs/time/zh'

time.locale('zh-CN', zh)

License

MIT copyright © 2024-present alex wei