Skip to content

dxgi/typesafe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published