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
export const setCorrectViewportHeightUnit = (interval = 1000): void => { | |
let currentHeight: number | null = null; | |
const update = () => { | |
if(currentHeight !== window.innerHeight) { | |
currentHeight = window.innerHeight | |
const vh = window.innerHeight * 0.01; | |
document.documentElement.style.setProperty('--vh', `${vh}px`); | |
} | |
} |
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
export const firstLetter = (str: string): string => str[0]; | |
export const toUppercase = (str: string): string => str.toUpperCase(); | |
export const toLowercase = (str: string): string => str.toLowerCase(); | |
export const trim = (str: string) => str.trim(); | |
// https://stackoverflow.com/a/5717133/11351782 | |
export function isValidUrl(str: string): boolean { | |
const pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol | |
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name |
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
# place this after nvm initialization! | |
autoload -U add-zsh-hook | |
load-nvmrc() { | |
local node_version="$(nvm version)" | |
local nvmrc_path="$(nvm_find_nvmrc)" | |
# Get node version from package.json engines section (remove 'v' if present) | |
local package_json_node_version="$([ -r package.json ] && cat package.json | jq '.engines.node' --raw-output)" |
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
// If you are new to functional programming in JavaScript, the following is a must read! | |
// https://github.com/MostlyAdequate/mostly-adequate-guide | |
// Pipe and compose | |
// ================= | |
// https://dev.to/ascorbic/creating-a-typed-compose-function-in-typescript-3-351i | |
export const pipe = <T extends any[], R>(fn1: (...args: T) => R, ...fns: Array<(a: R) => R>) => { | |
const piped = fns.reduce( |