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 raf = 0; | |
const animations = []; | |
function remove(animation) { | |
const index = animations.indexOf(animation); | |
if (index > -1) { | |
animations.splice(index, 1); | |
} | |
} |
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 has = {}.hasOwnProperty; | |
function getPath(root, tester, path = []) { | |
for (const key in root) { | |
if (has.call(root, key)) { | |
const value = root[key]; | |
if (tester(key, value) === true) { | |
path.push(key); | |
return path; | |
} |
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
// https://stackoverflow.com/a/46759625 | |
function isConstructable(fn) { | |
try { | |
Reflect.construct(function () {}, [], fn); | |
return true; | |
} catch (e) { | |
return false; | |
} | |
} |
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
@media (min-width: 640px) { | |
/* Small */ | |
} | |
@media (min-width: 768px) { | |
/* Medium */ | |
} | |
@media (min-width: 1024px) { | |
/* Large */ |
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 JSON_RE = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/; | |
function parseData(data) { | |
if (data == null || data === 'null' || data === 'undefined' || data === '') { | |
return null; | |
} | |
if (data === 'true') { | |
return true; | |
} | |
if (data === 'false') { |
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 cache = new Map(); | |
const template = document.createElement('template'); | |
function parseHTML(html) { | |
if (cache.has(html)) { | |
return cache.get(html).cloneNode(true); | |
} | |
template.innerHTML = html; | |
cache.set(html, template.content); | |
return cache.get(html).cloneNode(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
// Spec: https://wicg.github.io/ua-client-hints | |
// Support: https://caniuse.com/mdn-api_navigator_useragentdata | |
const isMobile = navigator.userAgentData.mobile; //=> true/false |
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
// Get the IANA timezone | |
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; | |
// My result | |
console.log(timezone); //=> "America/Toronto" |
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 supportsContainerQueries() { | |
return !!window.CSSContainerRule; | |
} | |
function supportsCustomPropertyDefinitions() { | |
return !!window.CSSPropertyRule; | |
} | |
function supportsScopedCSS() { | |
return !!window.CSSScopeRule; |
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
/* Courtesy of: https://www.24a11y.com/2018/accessible-svg-icons-with-inline-sprites/ */ | |
.svg-icon { | |
/* Place the icon on the text baseline. */ | |
position: relative; | |
top: .125em; | |
/* Prevent the icon from shrinking inside a flex container. */ | |
flex-shrink: 0; | |
/* Scale the icon to match the font-size. */ | |
height: 1em; |