@kravc/schema 2.3.1 → 2.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/schema",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Advanced JSON schema manipulation and validation library.",
5
5
  "keywords": [
6
6
  "JSON",
@@ -137,6 +137,13 @@ describe('Validator', () => {
137
137
  expect(validInput.preferences.isNotificationEnabled).to.eql(false)
138
138
 
139
139
  expect(() => {
140
+ input.preferences.isNotificationEnabled = 'NaN'
141
+ validInput = validator.validate(input, 'Profile')
142
+ expect(validInput.preferences.isNotificationEnabled).to.eql('NaN')
143
+ }).to.throw('"Profile" validation failed')
144
+
145
+ expect(() => {
146
+ input.preferences.isNotificationEnabled = 0
140
147
  input.preferences.height = 'NaN'
141
148
  validInput = validator.validate(input, 'Profile')
142
149
  expect(validInput.preferences.height).to.eql('NaN')
@@ -1,5 +1,8 @@
1
1
  'use strict'
2
2
 
3
+ const BOOLEAN_STRING_TRUE_VALUES = ['yes', 'true', '1']
4
+ const BOOLEAN_STRING_FALSE_VALUES = ['no', 'false', '0']
5
+
3
6
  const normalizeType = (type, value) => {
4
7
  let normalizedValue = value
5
8
 
@@ -22,8 +25,12 @@ const normalizeType = (type, value) => {
22
25
  }
23
26
 
24
27
  if (isStringValue) {
25
- const isTrue = value.toLowerCase() === 'true' || value === '1'
26
- normalizedValue = isTrue ? true : false
28
+ const isTrue = BOOLEAN_STRING_TRUE_VALUES.includes(value.toLowerCase())
29
+ const isFalse = BOOLEAN_STRING_FALSE_VALUES.includes(value.toLowerCase())
30
+
31
+ if (isTrue || isFalse) {
32
+ normalizedValue = isTrue ? true : false
33
+ }
27
34
  }
28
35
  }
29
36
  }