Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
@bva/countdown
Advanced tools
This is a JS based component for adding countdown timers using data attributes and minimal JS.
yarn add @bva/countdown
to install, and then import with import Timer from '@bva/countdown';
At the moment there is only one (very optional) parameter (passed in an object):
This is how the component does most of its configuration. There are a couple of data attributes that can be added to timers to change how they operate:
%D:%H:%M:%S
):
The component introduces a custom event as well:
countdownTimerEnded
: this is bound directly to timer elements and is dispatched when the timer's countdown ends.<!-- HTML -->
<div class="my-timer"
data-timer="3600"
data-timer-format="%M:%H"
data-complete-message="Time's up!"
data-lazy-timer
data-pause-timer>
</div>
// JavaScript
import Timer from '@bva/countdown';
document.addEventListener('DOMContentLoaded', () => {
// add event listeners to the timer elements
const timerElements = document.querySelectorAll('[data-timer]');
timerElements.forEach((timerElement) => {
timerElement.addEventListener('countdownTimerEnded', (event) => {
console.log('Timer has ended for:', event.target);
});
});
// now setup all the timers to start their countdowns
Timer.setup({});
});
There are two other methods the component exposes for more manual control over timers:
startTimer
: takes in the timer element as a parameter and will start the timer for that timer element.pauseTimer
: takes in the timer element as a parameter and will stop the timer for that timer element.Here is an example for the two methods:
import Timer from '@bva/countdown';
document.addEventListener('DOMContentLoaded', () => {
// Assuming there is only one timer on the page I care about
const myTimer = document.querySelector('[data-timer]');
Timer.startTimer(myTimer);
const stopButton = document.querySelector('[data-stop-button]');
stopButton.addEventListener('click', () => {
Timer.pauseTimer(myTimer)
});
});
FAQs
Adds a JS component for adding countdown timers
We found that @bva/countdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.