stripUnknown

stripUnknown()

Effect

When you call allowKnown to allow unknown keys, the return value of validate and validateSilent will retain the unknown keys and corresponding values. If you want to strip the unknown keys and corresponding values, you can call stripUnknown.

NOTE

If you called stripUnknown, you don't need to call allowKnown, stripUnknown contains the effect of allowKnown.

Arguments

None

Example

const schema1 = racoon.object({
  name: racoon.string()
}).allowUnkown();
const result1 = schema1.validate({
  name: 'Jack',
  age: 22
}); // pass, and result1 is { name: 'Jack', age: 22 }

const schema2 = racoon.object({
  name: racoon.string()
}).allowUnkown().stripUnkown();
const result2 = schema2.validate({
  name: 'Jack',
  age: 22
}); // pass, and result1 is { name: 'Jack' }

// schema2 is same as schema3 below
const schema3 = racoon.object({
  name: racoon.string()
}).stripUnkown();

Last updated