utils/README.md
2024-01-27 12:21:23 -05:00

1.0 KiB

ItsEricWoodward's Utils

A small collection of common libraries and functions I like to use in my Node applications.

I figure that publishing them in a public repo on my gitea instance will make them easier to use.

The functions exported by this library are:

  • convertCamelToUpperSnakeCase(str: string)
    • Converts textLikeThis (or TextLikeThis) to TEXT_LIKE_THIS.
    • Returns: Converted version of str
  • getDirname()
    • Reads and returns variables __dirname and __filename, as with CJS Node.
    • Returns: { __dirname: string, __filename: string }
  • getTime()
    • Returns: the current time in a standardized format.
  • log(...msg: unknown[])
    • Prints the contents of msg to the console with my preferred formatting.
  • readJsonIfExists(filePath: string | URL)
    • Reads the contents of the JSON or JSON5 file at indicated filePath.
    • Returns: the JSON.parsed contents of the file.