New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

wc-timer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wc-timer

A lightweight, dependency-free countdown timer Web Component.

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

wc-timer

A high-performance, dependency-free Web Component for countdowns, elapsed time, and static dates. It uses a shared ticker and cached Intl formatters for maximum efficiency.

Features

  • High Performance: Uses a shared global ticker (TickHub) to sync all instances. It calculates dates using O(1) math and caches Intl objects to save memory.
  • Smart Formatting: Supports Intl.DurationFormat with a robust fallback for older browsers.
  • Versatile Presets: Choose from hms, dhms, ydhms, auto, or static date.
  • Light DOM: Renders as a standard Text Node. The text is selectable and inherits global CSS styles easily.
  • Auto-Restart: If you update the target to a future date, the timer restarts automatically.

Installation

npm install wc-timer

Usage

  • Import the script:
import 'wc-timer';
// Or via script tag:
// <script type="module" src="wc-timer.js"></script>

  • Use in HTML:
<wc-timer target="2026-01-01T00:00:00Z"></wc-timer>

<wc-timer 
  target="2026-06-01T12:00:00Z" 
  preset="dhms" 
  labels="long" 
  compact 
  locale="pl">
</wc-timer>

<wc-timer preset="date" target="2025-12-31"></wc-timer>

API Reference

Attributes

AttributeTypeDefaultDescription
targetstringnowThe target date (ISO 8601 string or Date compatible).
presetstringautoformatting mode: auto, hms, dhms, ydhms, date.
labelsstringshortunit labels: none (00:00:00), short (1h 5m), long (1 hour 5 minutes).
compactbooleanfalseif present, hides zero-value high units (e.g. hides "0 years").
localestringautooverrides browser language (e.g. pl, en-US).

Presets Details

  • auto: shows HH:MM:SS. If duration > 30 days, it adds days.
  • hms: hours, minutes, seconds.
  • dhms: days, hours, minutes, seconds.
  • ydhms: years, months, days, hours, minutes, seconds.
  • date: static date formatted via Intl.DateTimeFormat.

JavaScript Properties

You can control the element programmatically.

const el = document.querySelector('wc-timer');

// Update target (accepts Date object, string, or timestamp)
el.target = new Date('2030-01-01');

// Change settings on the fly
el.preset = 'ydhms';
el.compact = true;
el.labels = 'long';

Styling

Since wc-timer uses Light DOM, you can style it with standard CSS.

wc-timer {
  font-family: 'Courier New', monospace;
  font-weight: bold;
  color: #2563eb;
}

Browser Support

Works in all modern browsers. It uses Intl.DurationFormat if available. Otherwise, it falls back to a custom formatter using Intl.PluralRules.

License

Copyright 2026 Dávid Ali

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

web-component

FAQs

Package last updated on 06 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts