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 delegate(context, type, selector, fn) { | |
context.addEventListener(type, (e) => fn(e, e.target.closest(selector))); | |
} |
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 hashmap(...props) { | |
const map = Object.create(null, { | |
[Symbol.iterator]: { | |
enumerable: false, | |
writable: false, | |
configurable: false, | |
value: () => ({ | |
items: Object.entries(map), | |
next: function next() { | |
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
function inherit(subclass, superclass) { | |
subclass.prototype = Object.create(superclass.prototype, { | |
constructor: { | |
value: subclass | |
} | |
}); | |
} |
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 isArrayLike(value) { | |
return value | |
&& typeof value === 'object' | |
&& typeof value.length === 'number' | |
&& value.length >= 0 | |
&& value.length % 1 === 0; | |
} |
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
* { | |
outline: 1px solid #fff !important; | |
background-color: rgba(0,2,54,.1) !important; | |
} |
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 query(selector, root = document) { | |
let context = [root]; | |
const tokens = selector.trim().split(/\s*(>|\+(?!\d)|~(?!=)|\s)\s*/).filter(n => !!n); | |
while (tokens.length && context.length) { | |
let token = tokens.shift(), combinator; | |
if (/>|\+(?!\d)|~(?!=)|\s/.test(token)) { | |
combinator = token; | |
token = tokens.shift(); | |
} | |
context = context.reduce((nodes, el) => { |
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 stacktrace(error = new Error()) { | |
if (Error.captureStackTrace) { | |
Error.captureStackTrace(error, stacktrace); | |
return error.stack; | |
} | |
return error.stack; | |
} |
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 logError(error, fatal = false) { | |
const description = typeof error === 'string' ? error : error.message; | |
gtag('event', 'exception', { | |
description, | |
fatal | |
}); | |
} |
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.reddit.com/r/javascript/comments/4wrdxd/comment/d69j04s/ | |
const proxies = new WeakSet(); | |
function createProxy(target, handler) { | |
const proxy = new Proxy(target, handler); | |
proxies.add(proxy); | |
return proxy; | |
} | |
function isProxy(obj) { |
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
// Traversing with firstChild/nextSibling is much faster than childNodes: https://jsperf.app/nextsibling-vs-childnodes | |
function forEachChild(element, callback) { | |
let node = element.firstChild; | |
while (node) { | |
callback(node); | |
node = node.nextSibling; | |
} | |
} |
OlderNewer