@s54a/cliclock

4.0.0 • Public • Published

Table of Contents generated with DocToc

@s54a/CLI Clock || CLI Clock && Timer && Stopwatch

CliClock is a command-line tool that allows users to perform various time-related functions such as displaying the current time, starting a stopwatch, setting a timer, and more, all from the comfort of their terminal.

Installation

This package provides an Executable Command

So You will have to install this package globally to be able to use the init command.

npm install -g @s54a/cliclock

OR

npx @s54a/cliclock

Features

  • Display Current Time: Simply type t to display the current time.
  • Stopwatch Functionality: Start a stopwatch by typing t -s.
  • Set a Timer: Set a timer by typing t [time]. Supported time units include hours (h), minutes (m), and seconds (s).
  • Funny Sound Option: Add a fun element to your timer with the -f flag, e.g., t 10m -f.
  • Customize VLC Path: Set the path to the VLC executable for audio playback.
  • Customize Audio Path: Set the path to the audio file for the alarm, including the option to use the default audio file.

Usage

  • To display the current time:

    t
  • To start a stopwatch:

    t -s
  • To set a timer:

    t [time]

    Example: t 10m (for 10 minutes)

    I have wasted a lot of timer on Regex so all these are correct inputs

    "1h 42 m 30 s"
    "1h42m30s"
    "1 h 42 m 30 s"
    "1 m 30 s"
    "1m 30s"
    "1m 30 s"
    "30 s"
    "1h30 s"
    " 1 h 30 s "
  • To set a timer with a funny sound:

    t [time] -f
  • To set the path to the VLC executable:

    t --vlc-path [path]
  • If you don't have VLC installed or don't want to play sound when the timer ends you can just set VLC.exe Path as no

    t --vlc-path no
  • To set new Audio for when the timer Ends:

    t --audio-path [path]
  • To set back to default:

    t --audio-path "default-audio"

For a detailed help menu, type:

t -h
  • To exit any time press Esc

Folder Structure

📁 cliClock
├── 📁 src
│ ├── 📄 cliInterface.js
│ ├── 📄 config.js
│ ├── 📄 exitCliClock.js
│ ├── 📄 fixWindowsPath.js
│ ├── 📄 getVLCPath.js
│ ├── 📄 handleSnoozeInput.js
│ ├── 📄 index.js
│ ├── 📄 notifyTimer.js
│ ├── 📄 parseTimeInput.js
│ ├── 📄 runCommand.js
│ ├── 📄 saveConfig.js
│ ├── 📄 setDefaultAudioPath.js
│ └── 📄 soundFunctions.js
├── 📄 .gitignore
├── 🎵 audio.mp3
├── 🎵 sound.mp3
├── 📜 LICENSE
├── 📝 Readme.md
├── 📋 package.json
├── 📋 package-lock.json
└── 🖼️ timer-svgrepo-com.png

Github

https://github.com/s54a/s54a-cliclock

NPM

https://www.npmjs.com/package/@s54a/cliclock

License

This project is licensed under the MIT License

Why I Made this:

It would an under statement to say that I have been a Professional Times Waster.

I way I figured out to Waste Less Time was setting timer then waste my time only till the timer ended.

But it was a hassle to set timers usi GUI so for a really long timer I wanted to build a CLI Timer.

So some time ago learned to make CLI Programs using Node JS. So I made this.

And I have spent a bit much to make it cross platform but I didn't had the resources to Test it so feel free to make any changes

How it works (A bit of Code Explanation)

I will explain the Timer Part only rest is very simple

First it runs a function called getVLCPath. It guess a correct path for the VLC.exe but if it all possible guessed paths are wrong then it will prompt you to enter the VLC.exe path.

If you don't want to give the path for VLC.exe you can answer no and it will start the timer but won't play the audio file.

But you can change this behavior any time by using the --vlc-path flag and set path for VLC.exe and it will play the audio.

But I have set it so that it will play a beep sound or whatever your system has using the Node-Notifier when the timer ends.

Then it sets the path for sound.mp3 in config.js so that VLC can play the sound.

Then it passes the user input through parseInputTimer function which extracts the units for timer and starts a timer using Set Interval.

When the timer ends it uses node-notifier to send notifications. And in the push notification there is an option to Snooze Timer for 3 Minutes & Another Option to End Timer

While in terminal it prompts you to snooze timer which uses the Readline Module. Input Time & Press Enter and it will restart Timer.

So I the timer never stops if you want to stop it you will have to press ESC or CTRL + C on your Keyboard

There is a bug or a little inconvenience in the Package when you snooze the timer and then if you try to exit the timer while it is running it takes almost 3 seconds to exit.

I don't know why it happens.

And I have tried to fix but it I can't there were a few fixes such just remove the function to exit and the user can exit by pressing CTRL + C.

A few question you might ask

Why there is a file called fixWindowsPath.js ?

Well File paths in windows use "" which in JS is used as a Escape Character and then it creates issues.

What I have learned after making a few NPM Packages

What you are trying to build will be build very easily but the validation, errors, more feature, things which you didn't planned for, and etc

e.g. When I started to build this package the Timer, StopWatch, Clock Functionality was done in about Two Hours but I wanted to send notification and play sound then I wanted the user to have the ability to enter timer in any format, then being able to change the audio it took more then 20 Days.

If you are a web developer you will think there must a native in node js to play sound and stop playing sound.

But there isn't.

So I think & according to this StackOverFlow answer there are Four Packages

  • Node Speaker (I cant figure this one)
  • Audic (The Size Bloats to 180 MBs)
  • SoundPlay (It can play sound but can't stop it)
    • I tried to change the source code and the functionality to stop the playing sound but it didn't happen.
    • So after banging my head on this issue for a few days Chat GPT gave me a solution to play sound using VLC Media Player and it was cross platform as well.
    • I will create this as a package and upload soon.
  • PlaySound (Didn't work)
Credit For Timer Ending Sound

Sound Effect by UNIVERSFIELD from Pixabay

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @s54a/cliclock

    Weekly Downloads

    0

    Version

    4.0.0

    License

    MIT

    Unpacked Size

    1.21 MB

    Total Files

    19

    Last publish

    Collaborators

    • s54a