From 51e8661144a285c995f95babca80e6814f5b18e4 Mon Sep 17 00:00:00 2001 From: Dmitrii Maganov Date: Sun, 10 Feb 2019 15:47:00 +0300 Subject: [PATCH] feat: aliases `optional()` and `unknown()` (#460) --- src/mixed.js | 1 + src/object.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/mixed.js b/src/mixed.js index 27f781cc9..921c215ba 100644 --- a/src/mixed.js +++ b/src/mixed.js @@ -512,3 +512,4 @@ for (const method of ['validate', 'validateSync']) for (const alias of ['equals', 'is']) proto[alias] = proto.oneOf; for (const alias of ['not', 'nope']) proto[alias] = proto.notOneOf; +proto.optional = proto.notRequired; diff --git a/src/object.js b/src/object.js index 417e83b5a..fdd51102e 100644 --- a/src/object.js +++ b/src/object.js @@ -245,6 +245,10 @@ inherits(ObjectSchema, MixedSchema, { return next; }, + unknown(allow = true, message = locale.noUnknown) { + return this.noUnknown(!allow, message); + }, + transformKeys(fn) { return this.transform(obj => obj && mapKeys(obj, (_, key) => fn(key))); },