This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let bodyBlocked = false; | |
const { body, documentElement: html } = document; | |
export const blockScroll = () => { | |
if (bodyBlocked) { | |
return; | |
} | |
const scrollBarWidth = window.innerWidth - html.clientWidth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {String} key | |
* @param {Any} value | |
* @param {Number} expirationDays | |
* @returns {void} | |
*/ | |
export const saveToLocalStorage = ({ key, value, expirationDays }) => { | |
// Try for localStorage support... | |
try { | |
// Convert days to milliseconds (ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ('serviceWorker' in navigator) { | |
window.addEventListener('load', function() { | |
navigator.serviceWorker | |
.register('path/to/service-worker.js') | |
.then(registration => { | |
console.log('SW registered: ', registration); | |
}) | |
.catch(registrationError => { | |
console.log('SW registration failed: ', registrationError); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const preventOrphanWord = (string) => { | |
const words = string.trim().split(' '); | |
// Only proceed if we've got at least 3 words | |
if (words.length < 3) { | |
return string; | |
} | |
const [nextToLastWord, lastWord] = words.slice(-2); | |
const precedingWords = words.slice(0, words.length - 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const form = document.querySelector('form'); | |
const config = { | |
errorAttribute: 'aria-invalid', | |
errorClass: 'error' | |
}; | |
// Helpers | |
const isFormInput = target => { | |
const { nodeName } = target; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = { | |
selector: '[data-observe]', | |
isVisibleClass: 'is-visible', | |
observerOptions: { | |
threshold: 0, | |
rootId: null, | |
rootMargin: '0px 0px 0px 0px', | |
once: true | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = { | |
accordionSelector: "[data-accordion]", | |
headingSelector: "[data-accordion-heading]", | |
buttonSelector: "[data-accordion-button]" | |
}; | |
const setup = accordion => { | |
const headings = [...accordion.querySelectorAll(config.headingSelector)]; | |
if (!headings || headings.length === 0) return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import debounce from "lodash/debounce"; | |
const getPageHeight = () => | |
Math.max( | |
document.body.scrollHeight, | |
document.body.offsetHeight, | |
document.documentElement.clientHeight, | |
document.documentElement.scrollHeight, | |
document.documentElement.offsetHeight | |
); |
OlderNewer