@exobase/use-json-args
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.3 • Public • Published

Provides a hook to parse and validate request arguments from the json body.

Install

Yarn

yarn add @exobase/use-json-args

Usage

If you're writing Exobase endpoints in Typescript you'll want to import the Props type.

import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useJsonArgs } from '@exobase/use-json-args'
import { useLambda } from '@exobase/use-lambda'

type Args = {
  username: string
  password: string
}

const createAccount = async ({ args }: Props) => {
  // await db.users.add({
  //   username: args.username,
  //   password: args.password
  // })
}

const STRONG =
  /^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$/

export default compose(
  useLambda(),
  useJsonArgs(yup => ({
    username: yup.string().required(),
    password: yup
      .string()
      .matches(STRONG, { message: 'Password is too weak' })
      .required()
  })),
  createAccount
)

Readme

Keywords

none

Package Sidebar

Install

npm i @exobase/use-json-args

Weekly Downloads

0

Version

1.0.0-rc.3

License

MIT

Unpacked Size

16.9 kB

Total Files

17

Last publish

Collaborators

  • rayepps