aiparking_api/node_modules/ow-lite/lib/string.js
2020-02-02 15:24:30 +07:00

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'
}
}