js.spec icon indicating copy to clipboard operation
js.spec copied to clipboard

Better string predicates

Open prayerslayer opened this issue 9 years ago • 2 comments

There should be built-in predicates for

  • regexes
  • emails
  • URLs
  • ????

prayerslayer avatar Nov 24 '16 15:11 prayerslayer

I see you are already pulling in lodash.isregexp. What else is left except for exposing it in a regex predicate? Do you have any ideas on how to tackle predicates for the other two (i.e. emails and URLs)? Pull in another vetted library (such as validate.js) or would you rather roll your own?

michielvermeir avatar Dec 03 '16 20:12 michielvermeir

I think this only needs the regex predicate, something like (regex) => (data) => regex.test(data), and some tests (happy case, error cases, cases without regexes and strings).

Regarding emails and URLs I'm a bit torn. I don't want to bloat js.spec because of these helpers, but I want to include them so it's more useful right out of the box. On the other hand including those things and then doing a sloppy job is not great, so I'd explore how we can use validator.js without adding too much kilobytes.

Does that help?

prayerslayer avatar Dec 04 '16 13:12 prayerslayer