This file contains hidden or 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
| type RGBA = { r: number, g: number, b: number, a: number }; | |
| const fg = { r: 255, g: 0, b: 0, a: 0.5 }; // semi-transparent red | |
| const bg = { r: 255, g: 255, b: 255, a: 1 }; // white | |
| console.log(contrastRatio(fg, bg)); // 2.44 | |
| // –––––––––––– | |
| function contrastRatio(fg: RGBA, bg: RGBA) { |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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( |
NewerOlder