Skip to content

Instantly share code, notes, and snippets.

@reecelucas
reecelucas / validate-email.js
Created July 2, 2018 20:31
Email validation utility
/**
* @param {String} email
* @return {Boolean}
*/
const validateEmail = email => {
const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return emailRegex.test(email);
};
@reecelucas
reecelucas / scroll-utils.js
Last active April 23, 2020 08:45
Utility functions to toggle page scroll
let bodyBlocked = false;
const { body, documentElement: html } = document;
export const blockScroll = () => {
if (bodyBlocked) {
return;
}
const scrollBarWidth = window.innerWidth - html.clientWidth;
@reecelucas
reecelucas / countdown-timer.js
Last active April 29, 2019 10:27
A simple native JS countdown timer
function getRemainingTime(endtime) {
if (typeof endtime !== 'object') {
throw new Error('getRemainingTime expects a Date object');
}
const total = Date.parse(endtime) - Date.parse(new Date());
return {
total: total,
days: Math.floor(total / (1000 * 60 * 60 * 24)),