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 🙏

© 2026 – Pkg Stats / Ryan Hefner

convert-string-time

v7.0.2

Published

Simple utility to convert between 12/24 hours string formats

Readme

convert-string-time Build Status

Convert time strings between 12/24 hours formats

Installation

npm install convert-string-time
# or
yarn add convert-string-time
# or
bun add convert-string-time

API

to24Hours(timeString: string): string | null

Converts a 12-hour time string to 24-hour format.

import {to24Hours} from 'convert-string-time'

to24Hours('09:23 am') // '09:23'
to24Hours('11:00 PM') // '23:00'
to24Hours('12:00 AM') // '00:00'
to24Hours('12:30 PM') // '12:30'
to24Hours('invalid') // null

to12Hours(timeString: string): string | null

Converts a 24-hour time string to 12-hour format.

import {to12Hours} from 'convert-string-time'

to12Hours('23:13') // '11:13 PM'
to12Hours('09:00') // '09:00 AM'
to12Hours('00:00') // '12:00 AM'
to12Hours('12:00') // '12:00 PM'
to12Hours('invalid') // null

parseTime(timeString: string): ParsedTime

Automatically detects the time format and returns both 12-hour and 24-hour representations.

import {parseTime} from 'convert-string-time'

parseTime('11:00 PM')
// { format: '12h', time12h: '11:00 PM', time24h: '23:00' }

parseTime('23:00')
// { format: '24h', time12h: '11:00 PM', time24h: '23:00' }

parseTime('invalid')
// { format: null, time12h: null, time24h: null }

isValidTimeFormat(timeString: string): boolean

Validates if a time string is in a valid 12-hour or 24-hour format.

import {isValidTimeFormat} from 'convert-string-time'

isValidTimeFormat('23:00') // true
isValidTimeFormat('11:00 PM') // true
isValidTimeFormat('9:30 am') // true
isValidTimeFormat('25:00') // false
isValidTimeFormat('invalid') // false

Contribution

Local Development

This project uses Bun for development. Below is a list of commands you will probably find useful.

bun test

Runs the test suite using Bun's built-in test runner.

bun run build

Bundles the package to the dist folder. The package is optimized and bundled into multiple formats (CommonJS and ES Module).

bun run lint

Runs the linter to check for code quality issues.

bun run format

Formats the code using Prettier.

Author