1.9.2 • Published 4 years ago

secval v1.9.2

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

PRs Welcome Codecov Coverage code style: prettier

SecVal - typed argument validator primarily for Express JS Framework.

This library in beta, though is used in production projects. Main idea is to provide way to validate input arguments and return typed arguments, errors and warnings.

Example of usage:

app.post('/users', async (req, res) => {
    let [err, options] = new Validator().with(req.body)
        .arg('username').required.string.between(3, 100)
        .arg('password').required.string.min(7)
        .arg('age').optional.unsigned.int.min(13)
        .arg('currency').required.string.trim.exactly(3).toUpperCase
        .arg('gender').optional.enumeration(['male', 'female'])
        .arg('location').optional.object
            .arg('latitude').optional.float
            .arg('longitude').optional.float
        .end
        .compound.allOrNothing('location.latitude', 'location.longitude')
        .build();

    if (err) {
        res.status(400).send({ error: err });
    }
    return new UserCtrl().create(req, res, options);
});

Another one

app.post('/api/v1/offices/:ouid/profiles', loginHelper.isLoggedInAndOfficeOwner, async (req, res) => {
    const [err, options] = new Validator()
        .with(req.params)
            .arg('ouid').required.uuid.v4
        .with(req.body)
            .arg('name').required.string
            .arg('printerName').required.string
            .arg('customData').required.object.end
            .arg('price').required.float.min(0)
            .arg('settings').as('printerSettings').required.object
                .arg('isColor').required.bool
                .arg('allowDuplex').required.bool
                .arg('dpix').required.float
                .arg('dpiy').required.float
            .end
            .arg('paper').required.object
                .arg('name').required.string
                .arg('coating').optional.default('Undefined')
                    .enumeration(['Undefined', 'Gloss', 'Matte', 'Velvet', 'Linen', 'Silk'])
                .arg('width').required.unsigned.int
                .arg('height').required.unsigned.int
                .arg('printWidth').required.unsigned.int
                .arg('printHeight').required.unsigned.int
                .arg('marginTop').required.unsigned.int
                .arg('marginLeft').required.unsigned.int
        .build();
    if (err) {
        return res.sendErr(400, err);
    }
    return new ProfileCtrl().create(req, res, options);
});

Installation

Install via npm

npm install secval --save

or directly from github

"secval": "git+https://github.com/ssypachev/secval.git"

Documentation

https://github.com/ssypachev/secval/wiki

Dependencies and testing

Library depends on moment.js and email-validator. For testing mocha, chai, uuid, nyc and prettier is used. To test call

npm run test

To cover with nyc

npm run cover

To format

npm run format

1.9.1

4 years ago

1.9.2

4 years ago

1.9.0

4 years ago

1.8.6

4 years ago

1.8.5

5 years ago

1.8.4

5 years ago

1.8.3

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago