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

@tito10047/vanilla-js-timepicker

v0.2.0

Published

Lightweight vanilla JavaScript timepicker with no dependencies

Readme

@tito10047/vanilla-js-timepicker

Test Deploy Docs & Demo npm version License: MIT

📖 Documentation · ▶ Live Demo

Lightweight, dependency-free time picker for vanilla JavaScript and TypeScript.

Looking for a date picker? Check out vanilla-js-datepicker.

@tito10047/vanilla-js-timepicker demo


Features

  • Zero dependencies — no jQuery, no Moment, no framework required.
  • TypeScript first — written in TypeScript, ships full declaration files.
  • 24h · 12h · seconds — HH:mm, hh:mm a, HH:mm:ss formats from a single format string.
  • Async lifecycle hooks — onBeforeOpen, onBeforeChange, and validate accept Promises.
  • Custom cell renderer — renderCell lets you style and disable individual grid cells asynchronously (e.g. mark booked slots grey and non-clickable).
  • Fully accessible — ARIA combobox, dialog, spinbutton roles; full keyboard navigation.
  • CSS-variable theming — light, dark, and auto (system) themes; 20+ override-ready variables.
  • Internationalization — built-in English, Slovak, Czech, German; register any custom locale.
  • Multiple formats — ESM, CommonJS, and UMD builds.

Installation

npm install @tito10047/vanilla-js-timepicker

Quick start

import { Timepicker } from '@tito10047/vanilla-js-timepicker'
import '@tito10047/vanilla-js-timepicker/dist/timepicker.css'

const tp = new Timepicker('#departure', {
  format: 'HH:mm',
  minuteStep: 15,
  showNowButton: true,
  showClearButton: true,
  locale: 'en',
  onChange: (value) => {
    console.log('Selected:', value) // e.g. "14:30"
  },
})
<input id="departure" type="text" placeholder="--:--" />

CDN (no build step)

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tito10047/vanilla-js-timepicker/dist/timepicker.css" />
<script type="module">
  import { Timepicker } from 'https://cdn.jsdelivr.net/npm/@tito10047/vanilla-js-timepicker/dist/timepicker.esm.js'
  new Timepicker('#time', { showNowButton: true })
</script>

Usage examples

24-hour with min/max

new Timepicker('#work-start', {
  format: 'HH:mm',
  minTime: '08:00',
  maxTime: '17:00',
  minuteStep: 15,
  onInvalid: (err) => showError(err.message),
})

12-hour AM/PM

new Timepicker('#alarm', {
  format: 'hh:mm a',
  locale: 'en',
  showConfirmButton: true,
  closeOnSelect: false,
})

With seconds

new Timepicker('#precise', {
  format: 'HH:mm:ss',
  minuteStep: 5,
  secondStep: 5,
})

Async validation

new Timepicker('#slot', {
  validate: async (value) => {
    const { available } = await fetch(`/api/slots?time=${value}`).then(r => r.json())
    return available ? true : `${value} is already booked`
  },
  onInvalid: (err) => showError(err.message),
})

Custom cell renderer — spinner view and grid view

renderCell works in both the spinner (value buttons you click to open the grid) and in the grid cells themselves. Pass a sync or async function; it receives the full formatted time and returns { className, title, clickable }.

import type { CellRenderResult } from '@tito10047/vanilla-js-timepicker'

new Timepicker('#appointment', {
  format: 'HH:mm',
  minuteStep: 30,
  renderCell: async (time): Promise<CellRenderResult> => {
    const { available } = await fetch(`/api/slots?time=${time}`).then(r => r.json())
    return {
      clickable: available,
      className: available ? undefined : 'vtp-cell--booked',
      title: available ? time : `${time} is already booked`,
    }
  },
})
/* Applied to value buttons in the spinner and to cells in the grid */
.vtp-cell--booked {
  color: #bbb;
  text-decoration: line-through;
  cursor: not-allowed;
}
  • Spinner view — called once with the current time on every update (open + arrow scroll). Class and title are applied to all value buttons. Stale results from fast scrolling are automatically discarded.
  • Grid view — called once per cell in parallel via Promise.all. Grid renders after all results arrive.

Dark theme

new Timepicker('#night', {
  theme: 'dark',
})

Programmatic API

const tp = new Timepicker('#tp')

await tp.setValue('09:30')
await tp.setNow()
await tp.clear()

const value = tp.getValue()   // "09:30"
const date  = tp.getDate()    // Date | null

await tp.open()
await tp.close()
await tp.toggle()

tp.destroy()

Auto-init from HTML attributes

<input data-timepicker data-timepicker-options='{"format":"HH:mm","showNowButton":true}' />
<input data-timepicker data-timepicker-options='{"format":"hh:mm a","locale":"en"}' />
const pickers = Timepicker.autoInit() // initialize all [data-timepicker] inputs

Options

| Option | Type | Default | Description | |---|---|---|---| | format | string | 'HH:mm' | Format tokens: HH (24h), hh (12h), mm, ss, a. | | locale | string \| LocaleConfig | 'en' | Built-in: en, sk, cs, de. Pass an object for custom. | | value | string \| Date \| null | — | Initial value. | | defaultValue | string \| Date \| null | — | Fallback initial value. | | minTime | string | '' | Earliest allowed time (HH:mm). | | maxTime | string | '' | Latest allowed time (HH:mm). | | minuteStep | number | 5 | Spinner step for minutes. | | secondStep | number | 1 | Spinner step for seconds. | | theme | 'light' \| 'dark' \| 'auto' | 'auto' | Colour scheme. | | showNowButton | boolean | false | Show "Now" button. | | showClearButton | boolean | false | Show "Clear" button. | | showConfirmButton | boolean | false | Show "Confirm" button. | | openOnFocus | boolean | true | Open on input focus. | | closeOnSelect | boolean | true | Close after selecting. | | allowManualInput | boolean | true | Allow keyboard entry. | | parseStrategy | 'right-fill' \| 'left-fill' \| 'smart' | 'right-fill' | How to interpret partial input. | | renderCell | (time: string) => CellRenderResult \| Promise<CellRenderResult> | — | Async cell renderer. Return { clickable, className, title } per cell. | | validate | (v: string) => boolean \| string \| Promise<...> | — | Custom validation function. | | onBeforeOpen | () => boolean \| Promise<boolean> | — | Guard before opening. | | onBeforeChange | (next, prev) => boolean \| Promise<boolean> | — | Guard before value commit. | | onChange | (value, event) => void | — | Fired when value changes. | | onInvalid | (err) => void | — | Fired when value is rejected. | | onClose | (reason) => void | — | Fired when dropdown closes. |

See the full options reference for all options.


Events

The picker dispatches CustomEvents on the <input> element for every lifecycle step:

| Event | Payload | Cancellable | |---|---|---| | vtp:beforeopen | {} | Yes | | vtp:open | { view } | No | | vtp:close | { reason } | No | | vtp:beforechange | { next, prev } | Yes | | vtp:change | { value, date, prev } | No | | vtp:input | { raw } | No | | vtp:invalid | { code, message, value } | No | | vtp:destroy | {} | No |

input.addEventListener('vtp:change', (e) => {
  console.log((e as CustomEvent).detail.value)
})

Theming

Override CSS custom properties to match your design system:

:root {
  --vtp-accent: #e63946;
  --vtp-bg-selected: #e63946;
  --vtp-radius: 4px;
  --vtp-font: 'Inter', sans-serif;
}

Full list of variables: Theming guide.


Keyboard navigation

| Key | Action | |---|---| | ArrowUp / Down | Increment / decrement the focused column | | Page Up / Down | Large increment / decrement | | Home / End | Jump to min / max value | | ArrowLeft / Right | Move between columns | | Escape | Close the dropdown | | Enter | Confirm / autofill |


Documentation

Full documentation: https://tito10047.github.io/vanilla-js-timepicker/

Live demo (8 interactive examples): https://tito10047.github.io/vanilla-js-timepicker/demo/


License

MIT © 2026 tito10047