0.1.16 • Published 4 months ago

@holdenmatt/ts-utils v0.1.16

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

ts-utils

A few simple zero-dependency Typescript utilities I commonly use across projects.

Environment checks

  • getEnvironment
  • isDevelopment
  • isProduction
  • isDebug
  • isBrowser
  • isServer

Basic type guards

  • isString
  • isArray
  • isRecord
  • isNotNull

JSON types

  • JSONPrimitive
  • JSONArray
  • JSONObject
  • JSONValue

Simple perf timing

  • logElapsedTime

Usage:

const start = performance.now();
// Do stuff...
logElapsedTime(`We did some stuff`, start);

Errors

  • HttpError
  • AssertionError
  • assertError(message: string)
  • assertTrue(condition: boolean, message: string)

URLs

  • isValidUrl

Keyboard

  • 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?

Logging

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.

0.1.16

4 months ago

0.1.15

6 months ago

0.1.14

8 months ago

0.1.13

8 months ago

0.1.12

9 months ago

0.1.11

9 months ago

0.1.10

9 months ago

0.1.9

9 months ago

0.1.8

10 months ago

0.1.7

10 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago