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
// Also available on NPM: https://www.npmjs.com/package/safe-try | |
// By @typeofweb 2024 | |
// License: MIT | |
type PromiseToTupleResult<T> = [Error, null] | [null, Awaited<T>]; | |
export const try_ = async <T extends Promise<unknown>>( | |
promise: T, | |
): Promise<PromiseToTupleResult<T>> => { | |
try { |
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
// See https://typeofweb.hashnode.dev/nextjs-prefetch-onmouseenter for a detailed explanation and more code | |
// See it in action: https://demo.yournextstore.com | |
"use client"; | |
import Link from "next/link"; | |
import { useRouter } from "next/navigation"; | |
import { type ComponentPropsWithRef } from "react"; | |
export const SuperLink = (props: ComponentPropsWithRef<typeof Link>) => { | |
const router = useRouter(); |
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
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"definitions": { | |
"Permission": { | |
"title": "Permission", | |
"description": "An enumeration.", | |
"enum": [ | |
"MANAGE_USERS", | |
"MANAGE_STAFF", | |
"IMPERSONATE_USER", |
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
import type { Stripe } from "stripe"; | |
type StripeWebhookEventTypes = Stripe.WebhookEndpointCreateParams.EnabledEvent; | |
type StripeWebhookEvent<EventType extends StripeWebhookEventTypes, Payload> = { | |
type: EventType; | |
data: { | |
object: Payload; | |
}; | |
}; |
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
import Fetch from 'node-fetch'; | |
interface JJITOffer { | |
title: string; | |
street: string; | |
city: string; | |
country_code: string; | |
address_text: string; | |
marker_icon: string; | |
workplace_type: string; |
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 LogicValues = [true, false] as const; | |
type Logic = typeof LogicValues[number]; | |
const CARDINALITY = LogicValues.length; | |
type Literal = { __t: "Literal"; symbol: string }; | |
type UnaryOperator = { __t: "Unary"; e: (a: Logic) => Logic }; | |
type BinaryOperator = { __t: "Binary"; e: (a: Logic, b: Logic) => Logic }; | |
type Token = Literal | UnaryOperator | BinaryOperator; |
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
/* eslint-disable functional/no-this-expression -- it's a class */ | |
/* eslint-disable functional/prefer-readonly-type -- it's a class */ | |
export const useBodyFix = () => { | |
return fixBodyService; | |
}; | |
class FixBodyService { | |
private windowOffsetY: number = 0; | |
private scrollbarWidth: number = 0; |
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 getHexValue(intInput: number) { | |
return intInput.toString(16).padStart(2, "0"); | |
} | |
function getTintValue(tint: number, bgTint: number, alpha: number) { | |
return Math.min(Math.floor((1 - alpha) * bgTint + alpha * tint), 255); | |
} | |
class Color { | |
constructor( |
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 getAllCSSVariableNames = () => | |
Array.from(document.styleSheets) | |
.filter((s) => s.href === null || s.href.startsWith(window.location.origin)) | |
.flatMap((s) => Array.from(s.cssRules)) | |
.filter((r): r is CSSStyleRule => r.type === CSSRule.STYLE_RULE) | |
.flatMap((r) => (r.selectorText === ":root" ? Array.from(r.style) : [])) | |
.filter((name) => name.startsWith("--")) | |
.sort(); | |
const getCSSColorVariableNames = () => |
NewerOlder