Skip to content

Releases: icebob/fastest-validator

v1.10.1

22 Mar 16:56
Compare
Choose a tag to compare

Changes

  • fix issue with regex pattern in string rule #221
  • fix returned value issue in email rule in case of empty: false #224

v1.10.0

03 Feb 17:10
Compare
Choose a tag to compare

Changes

  • fix issue in multiple custom validator #203
  • Add min, max property to email rule #213
  • Add base64 property to string rule #214

v1.9.0

16 Nov 14:28
Compare
Choose a tag to compare

Changes

v1.8.0

18 Oct 19:07
Compare
Choose a tag to compare

New nullable rule attribute in #185

const schema = {
    age: { type: "number", nullable: true }
}
v.validate({ age: 42 }, schema); // Valid
v.validate({ age: null }, schema); // Valid
v.validate({ age: undefined }, schema); // Fail because undefined is disallowed
v.validate({}, schema); // Fail because undefined is disallowed

Changes

  • Shorthand for array foo: "string[]" // means array of string in #190
  • allow converting objectID to string in in #196

v1.7.0

30 Aug 08:30
Compare
Choose a tag to compare

Changes

v1.6.1

11 Aug 15:41
Compare
Choose a tag to compare

Changes

  • Fix issue with ObjectID rule

v1.6.0

06 Aug 20:28
Compare
Choose a tag to compare

New objectID rule

You can validate BSON/MongoDB ObjectID's

Example

const  { ObjectID } = require("mongodb") // or anywhere else 
const schema = {
    id: {
        type: "objectID",
        ObjectID // passing the ObjectID class
    }  
}
const check = v.compile(schema);
check({ id: "5f082780b00cc7401fb8e8fc" }) // ok
check({ id: new ObjectID() }) // ok
check({ id: "5f082780b00cc7401fb8e8" }) // Error

Dynamic default value

You can use dynamic default value by defining a function that returns a value.

Example
In the following code, if createdAt field not defined in object`, the validator sets the current time into the property:

const schema = {
    createdAt: {
        type: "date",
        default: () => new Date()
    }
};
const obj = {}
v.validate(obj, schema); // Valid
console.log(obj);
/*
{
    createdAt: Date(2020-07-25T13:17:41.052Z)
}
*/

Changes

  • Add support for uuid v6. #181
  • Add addMessage method for using in plugins #166
  • Fix uppercase uuid issue. #176
  • Add singleLine property to string rule. #180

Credits

Many thanks to @intech and @erfanium for contributing.

v1.5.1

19 Jun 17:27
Compare
Choose a tag to compare

Changes

  • Fixing issue with pattern & empty handling in string rule #165

v1.5.0

18 Jun 17:40
Compare
Choose a tag to compare

New tuple validation rule

Thanks for @Gamote, in this version there is a new tuple. This rule checks if a value is an Array with the elements order as described by the schema.

Example

const schema = {
    grade: { type: "tuple", items: ["string", "number", "string"] }
};
const schema = {
    location: { type: "tuple", empty: false, items: [
        { type: "number", min: 35, max: 45 },
        { type: "number", min: -75, max: -65 }
    ] }
}

Define aliases & custom rules in constructor options #162

You can define aliases & custom rules in constructor options instead of using v.alias and v.add.

Example

const v = new Validator({
    aliases: {
        username: {
            type: 'string',
            min: 4,
            max: 30
        }
    },
    customRules: {
        even: function({ schema, messages }, path, context) {
            return {
                source: `
                    if (value % 2 != 0)
                        ${this.makeError({ type: "evenNumber",  actual: "value", messages })}

                    return value;
                `
            };
        })
    }
});

Support plugins

Thanks for @erfanium, you can create plugin for fastest-validator.

Example

// Plugin Side
function myPlugin(validator){
    // you can modify validator here
    // e.g.: validator.add(...)
    // or  : validator.alias(...)
}
// Validator Side
const v = new Validator();
v.plugin(myPlugin)

Changes

  • Allow empty property in string rule with pattern #149
  • Add empty property to url and email rule #150
  • Fix custom rule issue when multiple rules #155
  • Update type definition #156

v1.4.2

03 Jun 20:51
Compare
Choose a tag to compare

Changes