Convert Celsius to Fahrenheit
Apply the temperature conversion without rounding the result.
function toFahrenheit(value) { return value * 9 / 5 + 32; }miscCollection · 28 utilities
Conversions, runtime checks, cookies, timers and sequencing: small helpers that do not fit another section, with their limits written down.
Apply the temperature conversion without rounding the result.
function toFahrenheit(value) { return value * 9 / 5 + 32; }miscExpand #rgb if needed and read the red, green and blue channels.
function hexToRgb(hex) { return hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_, r, g, b) =>…miscRead a query string into an object; repeated keys become arrays.
function getUrlParams(query) { return Array.from(new URLSearchParams(query)).reduce((params, [k…miscDouble each digit of a #rgb color.
function toFullHexColor(color) { return `#${(color.startsWith('#') ? color.slice(1) : color).sp…miscSubtract 32 and multiply by 5/9.
function fahrenheitToCelsius(fahrenheit) { return (fahrenheit - 32) * 5 / 9; }miscParse an absolute URL and read one query parameter.
function getParam({ url, param }) { return new URL(url).searchParams.get(param); }miscPack three 0–255 channels into a #rrggbb string.
function rgbToHex({ red, green, blue }) { return `#${((1 << 24) + (red << 16) + (green << 8) + …miscParse a Cookie header string into name–value pairs.
function parseCookies(cookie) { return Object.fromEntries(cookie.split(';').filter(item => item…miscEvaluate a common easing curve at progress t between 0 and 1.
function ease({ name, t }) { return { linear: t, easeInQuad: t * t, easeOutQuad: t * (2 - t), e…miscPercent-encode a value, including !'()* that encodeURIComponent leaves alone.
function encodeStrict(value) { return encodeURIComponent(value).replace(/[!'()*]/g, char => `%$…miscFind one cookie by name in a Cookie header string.
function getCookie({ cookie, name }) { const match = `; ${cookie}`.split(`; ${name}=`); return …miscRead the internal [[Class]] tag via Object.prototype.toString.
function getTypeOf(value) { return Object.prototype.toString.call(value).match(/\[object (.*)\]…miscExchange two values with array destructuring.
function swap([a, b]) { [a, b] = [b, a]; return [a, b]; }miscRead the JSON payload of a JSON Web Token — without verifying it.
function decodeJwtPayload(token) { const base64 = token.split('.')[1].replace(/-/g, '+').replac…miscReturn the first item that is neither null nor undefined.
function coalesce(values) { return values.find(item => item !== undefined && item !== null) ?? …miscTurn a and b into chroma and hue degrees.
function labToLch([l, a, b]) { return [l, Math.hypot(a, b), ((Math.atan2(b, a) * 180) / Math.PI…miscTurn chroma and hue degrees back into a and b.
function lchToLab([l, c, h]) { return [l, Math.cos((h * Math.PI) / 180) * c, Math.sin((h * Math…miscLook for the JEST_WORKER_ID variable that Jest sets in its workers.
function isRunningInJest() { return typeof process !== 'undefined' && process.env.JEST_WORKER_I…miscLook for process.versions.node.
function isNode() { return typeof process !== 'undefined' && process.versions?.node != null; }miscLook for the window and document globals.
function isBrowser() { return typeof window === 'object' && typeof document === 'object'; }miscExpire every cookie that JavaScript can see on the current path.
function clearCookies() { for (const cookie of document.cookie.split(';')) { const name = cooki…miscRead the prefers-color-scheme media feature.
function isDarkMode() { return window.matchMedia?.('(prefers-color-scheme: dark)').matches ?? f…miscReturn an integer from 1 to 6.
function throwDice() { return Math.floor(Math.random() * 6) + 1; }miscCreate a counter that returns 0, 1, 2… on successive calls.
function createIdGenerator(start = 0) { let id = start; return () => id++; }miscReplace an http: address with the same address over https:.
function redirectToHttps() { if (location.protocol !== 'http:') return; const url = new URL(loc…miscStart each task after the previous one finishes and collect the results in order.
async function runInSequence(tasks) { const results = []; for (const task of tasks) results.pus…miscReturn a promise that resolves after the given milliseconds.
function wait(milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds));…miscResolve after the current task, letting queued timers, I/O and rendering run.
function nextTask() { return new Promise(resolve => setTimeout(resolve, 0)); }miscTry a function in the local code lab, then read its limits before using it in an application.