27 lines
667 B
JavaScript
27 lines
667 B
JavaScript
'use strict'
|
|
|
|
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'
|
|
}
|
|
}
|