Simple Typescript utilities
npm install @holdenmatt/ts-utilsA few simple zero-dependency Typescript utilities I commonly use across projects.
- getEnvironment
- isDevelopment
- isProduction
- isDebug
- isBrowser
- isServer
- isString
- isArray
- isRecord
- isNotNull
- JSONPrimitive
- JSONArray
- JSONObject
- JSONValue
- logElapsedTime
Usage:
``We did some stuff
const start = performance.now();
// Do stuff...
logElapsedTime(, start);`
- HttpErrorAssertionError
- assertError(message: string)
- assertTrue(condition: boolean, message: string)
-
- isValidUrl
- modKey(shortcut: string): Returns a string like "⌘C" (on macOS) or "Ctrl+C" (on Windows/Linux), or undefined (on other platforms).isModKey(e: KeyboardEvent): boolean
- : Is the mod key (Ctrl on Windows/Linux, Command on macOS) pressed?
Add a logger:
``
addLogger((error: Error, cause?: unknown) => { ...do something })
Log an error (with all added loggers):
```
logError(new Error("Uh oh), {more: "info"})
By default, we console log to the browser only if isDebug is true.