Skip to content

Commit

Permalink
feat: IsString operator
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda committed Sep 15, 2022
1 parent 00dea40 commit 52fcedd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/operators/index.js
Expand Up @@ -5,6 +5,7 @@ module.exports = {
IsUndefined: require('./is-undefined'),
IsNull: require('./is-null'),
IsPresent: require('./is-present'),
IsString: require('./is-string'),
NumericEquals: require('./numeric-equals'),
NumericGreaterThan: require('./numeric-greater-than'),
NumericGreaterThanEquals: require('./numeric-greater-than-equals'),
Expand Down
13 changes: 13 additions & 0 deletions lib/operators/is-string.js
@@ -0,0 +1,13 @@
'use strict'

module.exports = function isStringOperator (inputValue, comparisonValue, candidateStateName, cache) {
const isString = typeof inputValue === 'string'

if (isString && comparisonValue === true) {
return candidateStateName
}

if (!isString && comparisonValue !== true) {
return candidateStateName
}
}
13 changes: 13 additions & 0 deletions test/data-test-expr-tests.js
Expand Up @@ -98,6 +98,19 @@ const tests = {
['nope', true, 'DefaultState'],
[true, false, 'DefaultState'],
[false, false, 'DefaultState']
],
IsString: [
['yep', true, 'NextState'],
[0, false, 'NextState'],
[true, false, 'NextState'],
[undefined, false, 'NextState'],
[null, false, 'NextState'],

['yep', false, 'DefaultState'],
[0, true, 'DefaultState'],
[true, true, 'DefaultState'],
[undefined, true, 'DefaultState'],
[null, true, 'DefaultState']
]
}

Expand Down

0 comments on commit 52fcedd

Please sign in to comment.