Skip to content

Instantly share code, notes, and snippets.

View thathurtabit's full-sized avatar

Stephen Fairbanks thathurtabit

View GitHub Profile
@thathurtabit
thathurtabit / getNumberSuffix.ts
Last active August 5, 2023 10:37
Get Number Suffix (-st, -nd, -rd, -th)
export const getNUmberSuffix = (number: number): string => {
const thExceptions = (number: number) =>
[11, 12, 13].some((exception) => exception === number);
const lastDigit = number % 10;
if (thExceptions(number) || lastDigit === 0 || lastDigit > 3)
return `${number}th`;
if (lastDigit === 1) return `${number}st`;
if (lastDigit === 2) return `${number}nd`;
return `${number}rd`;
@thathurtabit
thathurtabit / TS-Generics.ts
Created May 1, 2021 17:15
TypeScript Generics Example (by @wesbos)
// This function takes a Generic of FoodType
function makeABunchOf<FoodType>(food: FoodType, howMany: number): FoodType[] {
const foodArray = Array.from({ length: howMany }, () => food);
return foodArray;
}
// Make our Food Types
interface Pizza { name: string; slices: number; }
interface Sandwich { name: string; veggie: boolean; }
// Make some Food
@thathurtabit
thathurtabit / useFetchWithAbort.tsx
Created June 29, 2021 09:33
React: Fetch Hook (with AbortController to avoid race conditions and memory leaks)
import { useState, useEffect } from "react";
/* H/T:
Avoiding Race Conditions and Memory Leaks in React useEffect
https://javascript.plainenglish.io/avoiding-race-conditions-and-memory-leaks-in-react-useeffect-2034b8a0a3c7
*/
interface IUseFetchWithAbortResponse {
fetchedData: unknown;
isLoading: boolean;
@thathurtabit
thathurtabit / .eslintignore
Created October 30, 2021 10:21 — forked from nnance/.eslintignore
Create React App with ESLint, TypeScript, Prettier
src/serviceWorker.ts