This file contains hidden or 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
| /** | |
| * Sets up a DOM MutationObserver that watches for elements using undefined CSS | |
| * class names. Performance should be pretty good, but it's probably best to | |
| * avoid using this in production. | |
| * | |
| * Usage: | |
| * | |
| * import cssCheck from './checkForUndefinedCSSClasses.js' | |
| * | |
| * // Call before DOM renders (e.g. in <HEAD> or prior to React.render()) |
This file contains hidden or 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 linear = t => t; | |
| export const easeInQuad = t => t * t; | |
| export const easeOutQuad = t => t * (2 - t); | |
| export const easeInOutQuad = t => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t; | |
| export const easeInCubic = t => t * t * t; | |
| export const easeOutCubic = t => (--t) * t * t + 1; | |
| export const easeInOutCubic = t => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1; | |
| export const easeInQuart = t => t * t * t * t; | |
| export const easeOutQuart = t => 1 - (--t) * t * t * t; | |
| export const easeInOutQuart = t => t < 0.5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t; |
This file contains hidden or 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 resolveHostname(url) { | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| const { hostname } = a; | |
| return hostname.indexOf('www.') === 0 ? hostname.slice(4) : hostname; | |
| } | |
| // test | |
| resolveHostname('http://localhost:3000/some/route?some=arg#hash'); // localhost | |
| resolveHostname('https://www.cosmo.ru/beauty/star_beauty/?utm_source=pulse_mail_ru&utm_referrer=https%3A%2F%2Fpulse.mail.ru'); // cosmo.ru |
This file contains hidden or 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 add = (...args) => { | |
| const sum = (...args) => { | |
| sum.result = args.reduce((res, n) => res + n, sum.result); | |
| return sum; | |
| } | |
| sum.result = 0; | |
| sum.valueOf = () => sum.result; | |
| sum(...args); |
This file contains hidden or 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
| [8, 42, 38, 111, 2, 39, 1].forEach(num => setTimeout(() => console.log(num), num)); |
This file contains hidden or 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 handleClickOutside = ({trigger, popup, cb}) => (e) => { | |
| const {target} = e; | |
| if ( | |
| !popup.contains(target) | |
| && !trigger.contains(target) | |
| && target !== trigger | |
| ) { | |
| cb(e); | |
| } |
This file contains hidden or 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
| Promise.resolve() | |
| .then(() => setTimeout(() => console.log('1'), 0)) | |
| .then(() => console.log('2')) | |
| .then(() => console.log('3')) | |
| Promise.resolve() | |
| .then(() => console.log('4')) | |
| .then(() => console.log('5')) | |
| .then(() => console.log('6')) |
This file contains hidden or 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
| [1, 2, 3, 4, 5].sort(() => 0.5 - Math.random()); |
This file contains hidden or 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 elements = document.querySelectorAll('a, button, img'); | |
| const head = document.querySelector('head'); | |
| const link = document.createElement('link'); | |
| link.rel = 'stylesheet'; | |
| link.type = 'text/css'; | |
| link.href = 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css'; | |
| head.appendChild(link); | |
| const effects = ["bounce","flash","pulse","rubberBand","shake","swing","tada","wobble","jello","heartBeat","flip","hinge","jackInTheBox"]; |
This file contains hidden or 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 popChars = (str, count) => ({ | |
| val: str.substr(-count), | |
| str: str.slice(0, -count), | |
| }); | |
| const checkPrev = (str, val) => new RegExp(--val + '$').test(str); | |
| const stepSequence = (str, digit) => { | |
| let step = popChars(str, digit) | |
| while (checkPrev(step.str, step.val)) { |
NewerOlder