Skip to content

Releases: icebob/fastest-validator

v1.19.0

28 Jul 10:39
Compare
Choose a tag to compare

What's Changed

  • hotfix shorthand label in object by @FerX in #345
  • replace deprecated method substr by @FerX in #346
  • improving the custom function with arrays of elements by @FerX in #332

New Contributors

  • @FerX made their first contribution in #345

Full Changelog: v1.18.0...v1.19.0

v1.18.0

21 Apr 11:58
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.17.0...v1.18.0

v1.17.0

23 Apr 14:23
Compare
Choose a tag to compare

What's Changed

  • consider null as a value by @Freezystem in #317
  • Add type definition for haltOnFirstError on Validator constructor | fix: #316 by @hateablestream in #322

New Contributors

Full Changelog: v1.16.0...v1.17.0

v1.16.0

17 Dec 12:08
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.15.0...v1.16.0

v1.15.0

30 Aug 16:14
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.14.0...v1.15.0

v1.14.0

27 Aug 16:50
Compare
Choose a tag to compare

What's Changed

  • Add: haltOnFirstError option by @avanelli in #304
  • fix: Multi-schema nullable validators not working as expected. #303

New Contributors

Full Changelog: v1.13.0...v1.14.0

v1.13.0

15 Aug 16:56
Compare
Choose a tag to compare

What's Changed

Full Changelog: v1.12.0...v1.13.0

v1.12.0

17 Oct 12:54
Compare
Choose a tag to compare

Changes

  • update dev dependencies.
  • add parameters to dynamic default value function. E.g: age: (schema, field, parent, context) => { ... }
  • fix typescript definitions. #269, #270, #261
  • fix multi validate with object strict remove. #272
  • add normalize method. #275 E.g.: validator.normalize({ a: "string[]|optional" })

v1.11.1

14 Jul 17:16
Compare
Choose a tag to compare

Changes

  • fix debug mode. #237
  • fix object "toString" issue. #235
  • remove Node 10 from CI pipeline.
  • refactoring the typescript definitions. #251
  • update examples in readme. #255

v1.11.0

11 May 11:51
Compare
Choose a tag to compare

Async custom validator supports

const schema = {
    // Turn on async mode for this schema
    $$async: true,
    name: {
        type: "string",
        min: 4,
        max: 25,
        custom: async (v) => {
            await new Promise(resolve => setTimeout(resolve, 1000));
            return v.toUpperCase();
        }
    },

    username: {
        type: "custom",
        custom: async (v) => {
            // E.g. checking in the DB that whether is unique.
            await new Promise(resolve => setTimeout(resolve, 1000));
            return v.trim();
        }
    },
}

The compiled check function has an async property to detect this mode. If true it returns a Promise.

const check = v.compile(schema);
console.log("Is async?", check.async);

Meta-information for custom validators

You can pass any extra meta information for the custom validators which is available via context.meta.

const schema = {
    name: { type: "string", custom: (value, errors, schema, name, parent, context) => {
        // Access to the meta
        return context.meta.a;
    } },
};
const check = v.compile(schema);

const res = check(obj, {
    // Passes meta information
    meta: { a: "from-meta" }
});

Changes

  • support default and optional in tuples and arrays #226
  • fix that this points to the Validator instance in custom functions #231