sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.8k stars 105 forks source link

Add method to return the error without throwing #176

Closed Aqzhyi closed 3 years ago

Aqzhyi commented 4 years ago

Hi, the project joi has API validate it returns {error, value} such as:

let schema = Joi.string().empty('');
schema.validate(''); // returns { error: null, value: undefined }

schema = schema.empty();
schema.validate(''); // returns { error: "value" is not allowed to be empty, value: '' }

Or .error(new Error(...))

const schema = Joi.string()
  .error(new Error('Was REALLY expecting a string'));

schema.validate(3);
// returns Error('Was REALLY expecting a string')

So I make API validate and createValidate it also returns {error, value}.

What do you think?

Fixes #169

sindresorhus commented 4 years ago

@hilezir Bump

sindresorhus commented 3 years ago

Closing for lack of response.

https://github.com/sindresorhus/ow/issues/169#issuecomment-701031535