NK
Size: a a a
NK
A
NK
NK
A
1
NK
NK
A
j
function check (src, operation) {
const match = operation.match(/^(!?)([a-z]*)([<>=]*)(\d*)$/)
if (match) {
const isNotSubstr = match[1]
const mainSubstr = match[2]
const compareSubstr = match[3]
const numberSubstr = match[4]
let result
if (mainSubstr === 'empty') {
result = src === ''
} else if (mainSubstr === 'length' && compareSubstr && numberSubstr) {
const number = Number(numberSubstr)
if (compareSubstr === '<=') {
result = src.length <= number
} else {
return false
}
} else {
return false
}
if (isNotSubstr) {
result = !result
}
return result
}
}
console.log(check('aaa', '!length<=10'))
j
A
j
A
j
j
A
A
j
j