javascript

node

Node.js is a JS runtime environment.

pnpm

My preferred package manager of choice for Node stuff is pnpm. pnpm saves disk space by saving dependency files in one place on disk and hard-linking dependencies from there on install, which also results in faster installs.

global packages
commitlintgit commit message linter
html-validateHTML validator
husky 🐺git hooks
lightningcssCSS minifier
svgoSVG optimiser
Vercelweb deployment

deno

Deno is another JS runtime and is currently my preferred one. Having a linter, formatter, and test runner built-in eliminates the need for extraneous dependencies like eslint, prettier, etc.

dependencies

Marty McFly's hand fading away due to a time paradox. Back to the Future (1985)
npm ERR! code ERESOLVE

The why reinvent the wheel and LEGO blocks counter-arguments to the preference of reducing dependencies break when you wake up one day to some audit alerts, or worse, production issues because of some unpatched bug in a dependency of a dependency of a dependency that has been unmaintained/abandoned for years and all because someone decided to use lodash just to…check if an array is empty?

It’s understandable for bigger/more complex things, but weaseling your way out of learning how to pick keys from an object or pad a string natively by relying on some library to do it for you is tacky. You’d just be adding a useless beam to what is likely an already needlessly convoluted project.

random

// get a random float between min and max
const rFloat = (min, max) => Math.random() * (max - min) + min

// get a random integer between min and max
const rInt = (min, max) => ~~(Math.random() * (max - min)) + min

// get a random element from an array
const rnArrEl = arr => arr[(Math.random() * arr.length) | 0]

golf

Number(x) === +x
Math.pow(x, y) === (x ** y)
Number.isInteger(x) === (x % 1 === 0)
BigInt(x) === xn

// mind the 32-bit integers ;)
Math.floor(x) === (x >> 0) === ~~x

console

console.table(['alice', 'cheshire', 'hatter'])
console.table({id: 1, item: 'teacup'})
 
let test = false
console.assert(test, 'message shows up')
test = true
console.assert(test, 'message does not show up')
 
console.time('ID')
/* do something */
console.timeEnd('ID')

Check if user is online

navigator.onLine

window.addEventListener("offline", (e) => { ... }
window.addEventListener("online", (e) => { ... }

resources