ow-lite
Version:
Lightweight replacement for the ow validation library meant for browser usage.
27 lines (22 loc) • 667 B
JavaScript
const { func } = require('./symbols')
const stringPredicates = {
empty: (value) => (value === ''),
nonEmpty: (value) => (value !== ''),
[func]: {
is: (fn) => fn,
eq: (v) => (value) => (value === v),
length: (v) => (value) => (value.length === v),
minLength: (v) => (value) => (value.length >= v),
maxLength: (v) => (value) => (value.length <= v),
matches: (v) => (value) => v.test(value),
startsWith: (v) => (value) => value.startsWith(v),
endsWith: (v) => (value) => value.endsWith(v)
}
}
module.exports = {
predicates: stringPredicates,
validator: (value) => {
return typeof value === 'string'
}
}