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

@ecromaneli/clockjs

v1.0.13

Published

A lightweight framework that simulates a clock and allows you to use listeners.

Downloads

10

Readme

Install

npm i @ecromaneli/clockjs

Constructors

Import script

To use ClockJS, import script with this code:

const {ClockJS} = require('@ecromaneli/clockjs')

Now

To get instance of ClockJS with actual date, use:

ClockJS.now(): ClockJS

From timestamp

To get instance of ClockJS with timestamp in milliseconds (like Date.now()), use:

ClockJS.fromTimestamp(timestamp: number): ClockJS

Public Methods

  • start(): void start ticking;
  • stop(): void stop ticking;
  • alreadyStarted(): boolean return if clock is already started;
  • tick(): void manually tick.

Events

  • ticking on clock tick;
  • year on year change;
  • month on month change;
  • day on day change;
  • hour on hour change;
  • minute on minute change;
  • second on second change.

Bind and Unbind handlers

.on (events: string, handler: (event: string, clock: ClockJS) => void)
.off(events: string, handler: (event: string, clock: ClockJS) => void)

Format date

You can format the clock time any way you want by using a string with:

  • Y year, 1 - 4 digits;
  • M month number, 1 or 2 digits;
  • W weekday number, 1 or 2 digits;
  • D day, 1 or 2 digits;
  • H hours (24 hours), 1 or 2 digits;
  • h hours, 1 or 2 digits;
  • m minutes, 1 or 2 digits;
  • s seconds, 1 or 2 digits;
  • u milliseconds in seconds, 1 digit (.000);
  • TZD timezone, [+-]HH:mm or Z;
  • MMM or MON month abbrev. (Jan, Feb, Mar...);
  • MONTH month name (January, February...);
  • WWW weekday abbrev. (Mon, Tue, Wed...);
  • WEEKDAY weekday name (Monday, Tuesday...).

The function:

    // Print something like 2018 Jun 04, 15:49:32.770
    .format('YYYY MON DD, hh:mm:ss.u')

For example:

The ISO 8601 format is: 2018-06-04T05:57:23.557Z.

    // ISO 8601
    clock.format('YYYY-MM-DDThh:mm:ss.uTZD')

Usage Example

const {ClockJS} = require('@ecromaneli/clockjs')
let clock = ClockJS.now()

let handler = (event, clock) => {
    console.log(clock.format('YYYY-MM-DD hh:mm:ss'))
};

// Start clock (now, clock ticking)
clock.start()

// Bind handler on year, day and second change
clock.on('year day second', handler)

// Unbind handler on year and day change
clock.off('year day', handler)

// Stop clock
clock.stop()

Obs.: You don't need start the clock to use date information or .format() method. You need start, to use listeners.

Getters (ES5 Format)

Year

  • year: number current year;
  • yearFloat: number year float value.

Month

  • month: number current month (0 - 11);
  • monthFloat: number month float value;
  • monthName: string english month name.

Week

  • weekday: number current weekday (0 - 6);
  • weekdayFloat: number weekday float value;
  • weekdayName: string english weekday name.

Day

  • lastDayOfMonth: number last day of current month;
  • day: number current day;
  • dayFloat: number day float value.

Hours

  • hours: number current hours;
  • hoursFloat: number hours float value.

Minutes

  • minutes: number current minutes;
  • minutesFloat: number minutes float value.

Seconds

  • seconds: number current seconds;
  • secondsFloat: number seconds float value.

Milliseconds

  • milliseconds: number milliseconds.

Others

  • dateTime: string string of current time in DateTime format;
  • timezone: string current timezone. ( [+-]hh:mm|Z )

Getters & Setters (ES5 Format)

  • speed: number clock speed [0 - 59] (default: 1);
  • timestamp: number current timestamp;
  • clockTick: number current clocktick time in ms [10 - 1000].

Example

let clock = ClockJS.fromTimestamp(0);
console.log(clock.timestamp); // GET (print 0)
clock.timestamp = Date.now(); // SET (update actual timestamp)

Author

License

MIT License