Skip to content

Instantly share code, notes, and snippets.

@volosovich
Last active September 20, 2023 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volosovich/0d002202be3b3bba14d337eaaf37a350 to your computer and use it in GitHub Desktop.
Save volosovich/0d002202be3b3bba14d337eaaf37a350 to your computer and use it in GitHub Desktop.
prettier and editorconfig configs
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 4
[*.{diff,md}]
trim_trailing_whitespace = false
# .prettierrc or .prettierrc.yaml
# need to use with .editorconfig
trailingComma: "es5"
semi: true
singleQuote: true
printWidth: 120
@volosovich
Copy link
Author

volosovich commented Apr 17, 2023

prettier command for package.json
"prettify": "prettier --write \"**/*.{ts,tsx,js,json}\"",

# .prettierrc or .prettierrc
# need to use with .editorconfig
singleQuote: true
printWidth: 120
jsxSingleQuote: true
useTabs: true

@volosovich
Copy link
Author

zsh nvm auto-switcher

# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
  local node_version="$(nvm version)"
  local nvmrc_path="$(nvm_find_nvmrc)"

  if [ -n "$nvmrc_path" ]; then
    local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")

    if [ "$nvmrc_node_version" = "N/A" ]; then
      nvm install
    elif [ "$nvmrc_node_version" != "$node_version" ]; then
      nvm use
    fi
  elif [ "$node_version" != "$(nvm version default)" ]; then
    echo "Reverting to nvm default version"
    nvm use default
  fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc

@volosovich
Copy link
Author

debounce TS

export function debounce<T>(cb: (...rest: Array<T>) => void, t: number) {
  let timer: ReturnType<typeof setTimeout>;
  return function (...rest: Array<T>) {
    timer && clearTimeout(timer);
    timer = setTimeout(() => cb(...rest), t);
  };
}

@volosovich
Copy link
Author

set node version

"engines": {
    "node": "^10.23 || ^12",
    "npm": "^6"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment