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 { AxiosError } from "axios"; | |
export const DefaultErrorMessage = "An error occurred. please try again."; | |
export const getApiError = (error: unknown, defaultMessage = DefaultErrorMessage) => { | |
try { | |
if (typeof error === "string") { | |
return error; | |
} | |
if (error instanceof AxiosError) { |
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 cryptoLib from "crypto"; | |
/** | |
* Generate a random 32-byte buffer and convert it to a hex string | |
* @returns A random hex string | |
*/ | |
export const generateResetToken = () => { | |
const token = cryptoLib.randomBytes(32).toString("hex"); | |
return token; | |
}; |
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 { get } from "lodash-es"; | |
/** Takes a list of strings (`["a", "b", "c"]`) and returns a map (`{ a: "a", b: "b", c: "c" }`) */ | |
export const strListToMap = (list: string[]) => | |
Object.assign({}, ...list.map((item) => ({ [item]: item }))) as Record<string, string>; | |
// TODO: Handle nested keys like "a.b.c" | |
// TODO: Override iterator | |
export const listToMap = < | |
I extends Record<string, unknown> = Record<string, unknown>, |
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
/** | |
* Usage: | |
* var dataServiceInfo = wrapForCallInfo(require('../services/data').prototype); | |
* process.on('exit', function() { | |
* dataServiceInfo.print('DataService'); | |
* }); | |
* | |
* @param {Object} toWrap an object (or its prototype) to wrap for call statistics gathering. | |
* @returns {{print:function, data:Object}} | |
*/ |
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
## The characters treated as closing brackets when justifying | |
## paragraphs. They cannot contain blank characters. Only closing | |
## punctuation, optionally followed by closing brackets, can end | |
## sentences. | |
## | |
set brackets ""')>]}" | |
## Constantly display the cursor position in the statusbar. Note that | |
## this overrides "quickblank". | |
# set const |
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
eval "$(/opt/homebrew/bin/brew shellenv)" | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm | |
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads | |
nvm bash_completion | |
export PYENV_ROOT="$HOME/.pyenv" | |
export PYTHONPYCACHEPREFIX="${HOME}/.cache/Python" | |
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH" |
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 { useEffect, useState } from "react"; | |
export const useDebounce = <V = string>(value: V, delay = 1000) => { | |
const [debouncedValue, setDebouncedValue] = useState<V>(value); | |
useEffect(() => { | |
const handler = setTimeout(() => { | |
setDebouncedValue(value); | |
}, delay); |
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 { useState } from "react"; | |
export type LoadingState = "pending" | "success" | "error"; | |
export const useLoadingState = (initial: LoadingState = "pending") => { | |
const [loadingState, setLoadingState] = useState<LoadingState>(initial); | |
const isPending = loadingState === "pending"; | |
const isSuccess = loadingState === "success"; | |
const isError = loadingState === "error"; |
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
"use client"; | |
import { useLayoutEffect, useState } from "react"; | |
export const useLockBodyScroll = ({ | |
enableInitial = false, | |
element = document.body, | |
}: { | |
enableInitial?: boolean; | |
element?: HTMLElement; | |
} = {}) => { |
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
"use client"; | |
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | |
import { useEffect, useState } from "react"; | |
import { QueryParams } from "../url"; | |
export function useQueryParams() { | |
const router = useRouter(); | |
const pathname = usePathname(); | |
const _searchParams = useSearchParams(); |
NewerOlder