Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

README

Lightweight production-ready clock utility with zero dependencies.

Install

npm install clock-utils

Usage

import createClock from "clock-utils";

const clock = createClock({ format: "HH:MM:SS" });

// Get current time string
console.log(clock.getClock()); // "14:32:07"

// Start ticking
clock.start((time, date) => {
  console.log(time); // "14:32:08"
});

// Stop
clock.stop();

// Cleanup (e.g. on component unmount)
clock.destroy();

API

createClock(options?)

Option Type Default Description
format "HH:MM:SS" | "HH:MM" | "SS" "HH:MM:SS" Output format
onError (err: Error) => void undefined Callback error handler

Instance methods

Method Description
getClock() Returns current time as formatted string
getDate() Returns current Date object
start(callback) Starts ticking, fires callback each second
stop() Stops the ticker
isRunning() Returns true if active
destroy() Stops and marks instance as destroyed

License

MIT

About

A simple digital clock synchronized to the second, easy to use in JavaScript, React, Vue, or Node.js.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages