Socket
Book a DemoInstallSign in
Socket

@lambda-func/guard

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lambda-func/guard

The utils of lambda-func

latest
Source
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

@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
})

FAQs

Package last updated on 29 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts