Skip to content

Instantly share code, notes, and snippets.

View erikthalen's full-sized avatar
🏝️

Erik Thalén erikthalen

🏝️
View GitHub Profile
@erikthalen
erikthalen / mini-server.js
Last active April 5, 2024 16:04
single file http server in 150 lines
import { createServer, staticFolders, routes, streamFile } from './server.js'
/**
* defaults
*/
// Set(2) { '', 'public' }
// Map(2) { '/' => 'index.html', 'error' => 'error.html' }
// add static folder
staticFolders.add('assets')
@erikthalen
erikthalen / cols.js
Last active June 17, 2022 08:38
Get a vw based on columns
export const postCSSFunctions = {
// get "i" cols excluding gutter
cols: i => `calc(var(--col) * ${i} + var(--gutter) * ${i - 1})`,
// get "i" cols including gutter
push: i => `calc((var(--col) + var(--gutter)) * ${i})`,
}
@erikthalen
erikthalen / getRefs.ts
Last active March 11, 2024 19:24
Never write a querySelector again
/**
*
* @param {HTMLElement} [target=document.body] - Element to querySelect in
* @param {boolean} [namespaced] - Only get children with data-ref-parent-ref
* @param {string} [exclude] - Selector or element who's children wont be selected
* @param {boolean | function} [watch] - Watches DOM and updates refs on mutation
* @param {boolean} [asArray] - Saves all refs in arrays, also single elements
* @returns {Object} { myRef: div, another: [button, span] }
*/
export default ({