@lambda-func/guard
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

@lambda-func/guard

This package contains a middleware to use type guards for type narrowing.

Usage

import { guard } from '@lambda-func/guard'

const isString = (value: unknown): value is string => typeof value === 'string'

// will throw an error if not passed
export const handler = guard(isString)(async (event) => {
  return event.length
})

// can pass an alternate error handler
const throwCustomError = async () => {
  throw new CustomError()
}

export const handler = guard(isString, { onFailedPredicate: throwCustomError })(async (event) => {
  return event.length
})

Readme

Keywords

none

Package Sidebar

Install

npm i @lambda-func/guard

Weekly Downloads

1

Version

0.0.0

License

ISC

Unpacked Size

2.81 kB

Total Files

6

Last publish

Collaborators

  • cgiles95