2.0.5 • Published 8 months ago

@imaximus/typesafe v2.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

@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), ...);
2.0.5

8 months ago

2.0.0

9 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago