sindresorhus / ow

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

Add public method to Predicate class for customize validate message #156

Closed Rastopyr closed 4 years ago

Rastopyr commented 5 years ago

Hi guys,

this PR just add validateMessage method to Predicate class and should fix #122 , so it could be used in all cases of predicates:

// Chain from any predicate instance
ow.unicorn.validateMessage('We wait all unicorns')

// Chain from any predicate rule(because it the same predicate instance)
ow.unicorn.withRainbow.validateMessage('We wait all unicorns')

this method not affect any current features and not fail any test. It just extend predicate class.

P.S.: I'm not sure that validateMessage is good name for this method, but message method already defined in some Predicate classes(error for example).


IssueHunt Summary ### Referenced issues This pull request has been submitted to: - [#122: Custom error message](https://issuehunt.io/repos/105227249/issues/122) --- IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
Rastopyr commented 5 years ago

@sindresorhus linter is failing, but i'm pull it from last master. should i fix linter?

Rastopyr commented 5 years ago

But this PR still have a problem, predicates heritable from BasePredicate class not support this feature

sindresorhus commented 4 years ago

@Rastopyr Did you have a chance to look more into the problem?

sindresorhus commented 4 years ago

@Rastopyr Bump :)