Skip to content

Releases: icebob/fastest-validator

v1.4.1

13 May 13:07
Compare
Choose a tag to compare

Changes

  • Fix custom function issue in array rule and in root-level #136, #137

v1.4.0

08 May 11:53
Compare
Choose a tag to compare

New custom function signature

Thanks for @erfanium, in this version there is a new signature of custom check functions.
In this new function you should always return the value. It means you can change the value, thus you can also sanitize the input value.

Old custom function:

const v = new Validator({});

const schema = {
    weight: {
        type: "custom",
        minWeight: 10,
        check(value, schema) {
            return (value < schema.minWeight)
                ? [{ type: "weightMin", expected: schema.minWeight, actual: value }]
                : true;
        }
    }
};

New custom function:

const v = new Validator({
    useNewCustomCheckerFunction: true, // using new version
});

const schema = {
    name: { type: "string", min: 3, max: 255 },
    weight: {
        type: "custom",
        minWeight: 10,
        check(value, errors, schema) {
            if (value < minWeight) errors.push({ type: "weightMin", expected: schema.minWeight, actual: value });
            if (value > 100) value = 100
            return value
        }
    }
};

Please note: the old version will be removed in the version 2.0.0!

The signature is used in custom function of built-in rules.

const v = new Validator({
    useNewCustomCheckerFunction: true // using new version
});

const schema = {
    phone: { type: "string", length: 15, custom(v, errors) => {
        if (!v.startWith("+")) errors.push({ type: "phoneNumber" })
        return v.replace(/[^\d+]/g, ""); // Sanitize: remove all special chars except numbers
    } }	
};

v1.3.0

29 Apr 16:44
Compare
Choose a tag to compare

Changes

  • Add new class rule to check the instance of value #126
  • Updated typescript definitions #127 #129
  • Fix deep-extend function to detect objects better. #128
  • Add hex check to string rule #132

v1.2.0

05 Apr 08:52
Compare
Choose a tag to compare

Changes

v1.1.0

22 Mar 17:37
Compare
Choose a tag to compare

Changes

v1.0.2

09 Feb 14:30
Compare
Choose a tag to compare

Changes

  • Fix string with a pattern where regular expression contains a double quote #111 by @FranzZemen

v1.0.1

01 Feb 10:26
Compare
Choose a tag to compare

Changes

  • fix missing field property in custom rules #109

v1.0.0

18 Dec 21:41
Compare
Choose a tag to compare

Changes

  • add unique validation in array rule #104

v1.0.0-beta4

17 Nov 21:06
Compare
Choose a tag to compare
v1.0.0-beta4 Pre-release
Pre-release

Changes

  • fix array rule return value issue (again).

v1.0.0-beta3

17 Nov 20:17
Compare
Choose a tag to compare
v1.0.0-beta3 Pre-release
Pre-release

Changes

  • fix optional multi rule.