0.1.16 • Published 1 year ago

@holdenmatt/ts-utils v0.1.16

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago