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

@axel669/timestring

v0.1.0

Published

Small library for parsing and generating simple timestrings.

Downloads

4

Readme

Timestring

Small library for parsing and generating simple timestrings.

Installation

pnpm add @axel669/timestring

Usage

parse(string)

Returns the number of milliseconds of the combined parsed time parts.
Time Part Format: <time value><unit> ("5m", "1w", "150ms", etc)
The string can have any number of time parts, and time parts with the same unit will be added together. Any part of the string that isn't a time part will be ignored.

Supported Units

  • w - Weeks
  • d - Days
  • h - Hours
  • m - Minutes
  • s - Seconds
  • ms - Milliseconds

Example

import tstring from "@axel669/timestring"

const duration = tstring.parse("15m 30s")

stringify(time, options)

Generates a time string from the time given, with options to control the output.

options

  • options.format

    default: "short". The format to use for the units in the time string. Currently accepts "short" and "long". Long format will use plurals when appropriate.

    // "1s 337ms"
    tstring.stringify(1337)
    // "1 second, 337 miliseconds"
    tstring.stringify(1337, { format: "long" })
  • options.returnError

    default: false If true, stringify will return errors instead of throwing them.

  • options.show0s

    default: false If true, the output will include every unit the formatter knows, putting 0s where necessary.

    // "0w 0d 0h 0m 1s 337ms"
    tstring.stringify(1337, { show0s: true })
    // "0 weeks, 0 days, 0 hours, 0 minutes, 1 second, 337 miliseconds"
    tstring.stringify(1337, { format: "long", show0s: true })
  • options.sep

    If given, will replace the normal separator for different parts in the time string (" " for short format, ", " for long format).

    // "1s|337ms"
    tstring.stringify(1337, { sep: "|" })
    // "0 weeks/0 days/0 hours/0 minutes/1 second/337 miliseconds"
    tstring.stringify(1337, { format: "long", sep: "/" })