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/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd | |
export function closestElementComposed(selector, base = this) { | |
function __closestFrom(el) { | |
if (!el || el === document || el === window) return null; | |
let found = el.closest(selector); | |
return found ? found : __closestFrom(el.getRootNode().host); | |
} | |
return __closestFrom(base); | |
} |
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 fs = require('fs'); | |
const fetch = require('node-fetch'); | |
const FormData = require('form-data'); | |
const filePath = `path/to/file.ext`; | |
const form = new FormData(); | |
const stats = fs.statSync(filePath); | |
const fileSizeInBytes = stats.size; | |
const fileStream = fs.createReadStream(filePath); | |
form.append('field-name', fileStream, { knownLength: fileSizeInBytes }); |
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
// Hack for immer esm (see https://github.com/immerjs/immer/issues/557) | |
// and others that suffer the same | |
window.process = { ...window.process, env: { ...window?.process?.env, NODE_ENV: 'production' } }; |
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
customElements.define('my-component', class extends HTMLElement { | |
static get observedAttributes() { | |
return [ | |
// attrs | |
]; | |
} | |
constructor() { | |
super(); | |
this.attachShadow({ mode: 'open' }); | |
this.render(); |
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
/* Anchors */ | |
a.clear-style { | |
color: inherit; | |
text-decoration: none; | |
} | |
/* Buttons */ | |
button.clear-style, | |
input[type=button].clear-style, | |
input[type=reset].clear-style { |
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
// Derived from https://stackoverflow.com/a/52551910 | |
export function camelize(str) { | |
return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()); | |
} | |
export function pascalize(str) { | |
return (' ' + str).toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()); | |
} |
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 function eventPathFindTargetMatch(event, selector) { | |
return event.composedPath().find(target => target.matches?.(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
export const HISTORY_STATE_CHANGE_EVENT = 'historystatechange'; | |
history.pushState = changeState(history.pushState) | |
history.replaceState = changeState(history.replaceState) | |
window.addEventListener('popstate', fireStateChange) | |
setTimeout(fireStateChange); | |
function changeState(orig) { | |
return (...args) => { |
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 fetchJSON(url, options, retries = 0) { | |
return fetch(url, { cache: 'no-store', ...options }) | |
.then(res => { | |
if (res.ok) return res.json(); | |
if (retries > 0) return fetchJSON(url, options, --retries); | |
throw res; | |
}); | |
} |
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
{ | |
"version": "0.3.0", | |
"name": "url-fun", | |
"description": "URL fun", | |
"main": "url-fun.js", | |
"author": "pinkhominid <pinkhominid@birdbomb.com>", | |
"license": "MIT", | |
"homepage": "https://gist.github.com/pinkhominid/742ff38688f7638d4eb795048b620e8e" | |
} |
NewerOlder