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
class Collection { | |
#keys; | |
#values; | |
#map; | |
constructor(data) { | |
this.#keys = []; | |
this.#values = []; | |
this.#map = {} | |
if (data) { |
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
class Enum { | |
constructor(...keys) { | |
keys.forEach((key) => { | |
this[key] = key; | |
}); | |
Object.freeze(this); | |
} | |
*[Symbol.iterator]() { | |
for (let key of Object.keys(this)) { |
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 logReports(reports) { | |
console.warn('This page is using deprecated APIs or features:'); | |
console.table(reports.map((report) => ({ | |
url: report.url, | |
message: report.body.message, | |
line: report.body.lineNumber || '---', | |
column: report.body.columnNumber || '---', | |
anticipatedRemoval: report.body.anticipatedRemoval ? (new Date(report.body.anticipatedRemoval)).toLocaleDateString() : '---' | |
}))); | |
} |
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
.scrollable { | |
/* Make a container scrollable */ | |
overflow: auto; | |
/* Prevent scroll chaining to the parent element but still allows overscroll affordances*/ | |
overscroll-behavior: contain; | |
/* Space is reserved for the scrollbar to prevent layout shifts when the scrollbar appears or disappears */ | |
scrollbar-gutter: stable; | |
} | |
/* Alternative versions to restrict scrolling to the X or Y axes */ |
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 loadCSS(path) { | |
return new Promise((resolve, reject) => { | |
const link = document.createElement('link'); | |
link.rel = 'stylesheet'; | |
link.type = 'text/css'; | |
link.href = path; | |
link.onload = resolve; | |
link.onerror = reject; | |
document.head.appendChild(link); | |
}); |
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
// Check if an object is a promise instance | |
function isPromise(obj) { | |
return obj instanceof Promise; | |
} | |
// Better yet, detect a thenable to support alternative implementations | |
function isThenable(obj) { | |
return obj && typeof obj.then === 'function'; | |
} |
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 abortablePromise(executor) { | |
const controller = new AbortController(); | |
const promise = new Promise((resolve, reject) => { | |
controller.signal.addEventListener('abort', () => reject(new Error('Aborted'))); | |
executor(resolve, reject); | |
}); | |
// Add abort method to promise instance | |
promise.abort = controller.abort.bind(controller); | |
return promise; | |
} |
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 eventPromise(element, type) { | |
return new Promise((resolve) => element.addEventListener(type, resolve, {once: true})); | |
} |
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
// https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts | |
function isSecureContext() { | |
return window.isSecureContext || | |
location.protocol === 'https:' || | |
location.hostname === 'localhost' || | |
location.hostname === '127.0.0.1'; | |
} |
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 el = document.documentElement; | |
let state = el.className || null; | |
function setPageState(val) { | |
if (state) { | |
el.classList.remove(state); | |
} | |
state = val; | |
el.classList.add(state); | |
} |
NewerOlder