@wmfs/asl-choice-processor 1.23.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.24.0](https://github.com/wmfs/asl-choice-processor/compare/v1.23.0...v1.24.0) (2022-09-15)
2
+
3
+
4
+ ### ✨ Features
5
+
6
+ * IsBoolean operator ([b2ef9da](https://github.com/wmfs/asl-choice-processor/commit/b2ef9da9440fd8fd97f6ca413e6ac1947b31f546))
7
+ * IsString operator ([52fcedd](https://github.com/wmfs/asl-choice-processor/commit/52fcedd2df00c03027369882986f7d63c541a87c))
8
+
9
+
10
+ ### 📦 Code Refactoring
11
+
12
+ * tidy up IsNull and extend tests ([f5efe84](https://github.com/wmfs/asl-choice-processor/commit/f5efe84d1590c6d47dede3faeaa366c5012fbd0f))
13
+ * tidy up IsUndefined and extend tests ([00dea40](https://github.com/wmfs/asl-choice-processor/commit/00dea40f86d7bf5932841807d05ec6c73264941e))
14
+
1
15
  # [1.23.0](https://github.com/wmfs/asl-choice-processor/compare/v1.22.0...v1.23.0) (2022-08-12)
2
16
 
3
17
 
@@ -1,9 +1,11 @@
1
1
  module.exports = {
2
2
  BooleanEquals: require('./boolean-equals'),
3
3
  Includes: require('./includes'),
4
+ IsBoolean: require('./is-boolean'),
4
5
  IsUndefined: require('./is-undefined'),
5
6
  IsNull: require('./is-null'),
6
7
  IsPresent: require('./is-present'),
8
+ IsString: require('./is-string'),
7
9
  NumericEquals: require('./numeric-equals'),
8
10
  NumericGreaterThan: require('./numeric-greater-than'),
9
11
  NumericGreaterThanEquals: require('./numeric-greater-than-equals'),
@@ -0,0 +1,11 @@
1
+ module.exports = function isBooleanOperator (inputValue, comparisonValue, candidateStateName, cache) {
2
+ const isBoolean = typeof inputValue === 'boolean'
3
+
4
+ if (isBoolean && comparisonValue === true) {
5
+ return candidateStateName
6
+ }
7
+
8
+ if (!isBoolean && comparisonValue !== true) {
9
+ return candidateStateName
10
+ }
11
+ }
@@ -1,13 +1,13 @@
1
1
  'use strict'
2
2
 
3
3
  module.exports = function isNullOperator (inputValue, comparisonValue, candidateStateName, cache) {
4
- let nextState
4
+ const isNull = inputValue === null
5
5
 
6
- if (comparisonValue && inputValue === null) {
7
- nextState = candidateStateName
8
- } else if (!comparisonValue && inputValue !== null) {
9
- nextState = candidateStateName
6
+ if (isNull && comparisonValue === true) {
7
+ return candidateStateName
10
8
  }
11
9
 
12
- return nextState
10
+ if (!isNull && comparisonValue !== true) {
11
+ return candidateStateName
12
+ }
13
13
  }
@@ -0,0 +1,13 @@
1
+ 'use strict'
2
+
3
+ module.exports = function isStringOperator (inputValue, comparisonValue, candidateStateName, cache) {
4
+ const isString = typeof inputValue === 'string'
5
+
6
+ if (isString && comparisonValue === true) {
7
+ return candidateStateName
8
+ }
9
+
10
+ if (!isString && comparisonValue !== true) {
11
+ return candidateStateName
12
+ }
13
+ }
@@ -1,15 +1,13 @@
1
1
  'use strict'
2
2
 
3
3
  module.exports = function isUndefinedOperator (inputValue, comparisonValue, candidateStateName, cache) {
4
- let nextState
5
- if (comparisonValue === true) {
6
- if (inputValue === undefined) {
7
- nextState = candidateStateName
8
- }
9
- } else if (comparisonValue === false) {
10
- if (inputValue !== undefined) {
11
- nextState = candidateStateName
12
- }
4
+ const isUndefined = inputValue === undefined
5
+
6
+ if (isUndefined && comparisonValue === true) {
7
+ return candidateStateName
8
+ }
9
+
10
+ if (!isUndefined && comparisonValue !== true) {
11
+ return candidateStateName
13
12
  }
14
- return nextState
15
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wmfs/asl-choice-processor",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "description": "For determining the next state given an Amazon States Language 'Choices' definition and a set of values.",
5
5
  "author": "West Midlands Fire Service",
6
6
  "homepage": "https://github.com/wmfs/asl-choice-processor#readme",
@@ -67,9 +67,50 @@ const tests = {
67
67
  IsNull: [
68
68
  [null, true, 'NextState'],
69
69
  ['HELLO_WORLD', false, 'NextState'],
70
+ [undefined, false, 'NextState'],
71
+ [0, false, 'NextState'],
72
+ [false, false, 'NextState'],
70
73
 
71
74
  [null, false, 'DefaultState'],
72
- ['HELLO_WORLD', true, 'DefaultState']
75
+ ['HELLO_WORLD', true, 'DefaultState'],
76
+ [undefined, true, 'DefaultState'],
77
+ [0, true, 'DefaultState'],
78
+ [false, true, 'DefaultState']
79
+ ],
80
+ IsUndefined: [
81
+ [undefined, true, 'NextState'],
82
+ ['HELLO_WORLD', false, 'NextState'],
83
+ [null, false, 'NextState'],
84
+ [0, false, 'NextState'],
85
+ [false, false, 'NextState'],
86
+
87
+ [undefined, false, 'DefaultState'],
88
+ ['HELLO_WORLD', true, 'DefaultState'],
89
+ [null, true, 'DefaultState'],
90
+ [0, true, 'DefaultState'],
91
+ [false, true, 'DefaultState']
92
+ ],
93
+ IsBoolean: [
94
+ ['nope', false, 'NextState'],
95
+ [true, true, 'NextState'],
96
+ [false, true, 'NextState'],
97
+
98
+ ['nope', true, 'DefaultState'],
99
+ [true, false, 'DefaultState'],
100
+ [false, false, 'DefaultState']
101
+ ],
102
+ IsString: [
103
+ ['yep', true, 'NextState'],
104
+ [0, false, 'NextState'],
105
+ [true, false, 'NextState'],
106
+ [undefined, false, 'NextState'],
107
+ [null, false, 'NextState'],
108
+
109
+ ['yep', false, 'DefaultState'],
110
+ [0, true, 'DefaultState'],
111
+ [true, true, 'DefaultState'],
112
+ [undefined, true, 'DefaultState'],
113
+ [null, true, 'DefaultState']
73
114
  ]
74
115
  }
75
116