@imaximus/typesafe
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

@imaximus/typesafe

Introducing "typesafe", an npm package providing object-oriented type safety for Express and general usage.

Installation

Install @imaximus/typesafe with yarn

yarn add @imaximus/typesafe

General Usage

test/index.ts

import { typesafe, IMatch } from '@imaximus/typesafe';

const schema: IMatch = {
    body: {
        name: {
            string: {
                min: 1,
                max: 15,
                custom: (value: string) => {
                    if (value === 'reject')
                        return false;
                    else if value === 'error')
                        throw new Error('error');

                    return true;
                } 
            }
        }
    }
};

const input = {
    body: {
        name: 'Hello World!'
    }
};

typesafe(schema)(input)
    .then(() => console.log('OK'))
    .catch(err => console.error(err.message));

Middleware Usage

import { Request, Response, NextFunction } from 'express';
import { middleware, IMatch } from '@imaximus/typesafe';

const app = ...;

const schema: IMatch = {
    ...
}

app.post('/', middleware(schema), ...);

Package Sidebar

Install

npm i @imaximus/typesafe

Weekly Downloads

3

Version

2.0.5

License

ISC

Unpacked Size

26.8 kB

Total Files

25

Last publish

Collaborators

  • imaximus