
Product
Unify Your Security Stack with Socket Basics
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
temporal-constants
Advanced tools
Constants to compute with time units without magic numbers.
How often do you have to do some calculations to convert seconds to milliseconds, hours to days, or any number of others? Does everyone looking at your code understand why you are multipling a number of days by 86400?
We use these constant values in computations all the time in code, yet we also know that magic numbers are to be avoided:
Unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants -- Wikipedia
This tiny library defines those constants for you, so now instead of:
Math.round(ms / 60000)
, you can write Math.round(ms / MillisecondsInMinute)
Or in place of: setTimer(() => runMyFunction(), 24*60*60*1000)
you get the clearer (and faster): setTimer(() => runMyFunction(), MillisecondsInDay)
.
Compatible with Javascript ES2015/ES6 and newer, as well as Typescript.
Q: Why should I introduce another dependency for a few constants that I can define myself?
A: Have you defined them? Did you make any mistakes computing them?
If you don't want a dependency, feel free to copy the lines into your own source. In this case, the times they are not a-changin'.
FAQs
Constants to compute with time units without magic numbers.
We found that temporal-constants demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
Product
Socket is launching experimental protection for the Hugging Face ecosystem, scanning for malware and malicious payload injections inside model files to prevent silent AI supply chain attacks.
Research
/Security News
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.