@awesomeness-js/utils 1.2.11 → 1.2.12

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils/clean.js +28 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -165,6 +165,18 @@ function cleanArray(arr, schema = {}, {
165
165
 
166
166
  } else {
167
167
 
168
+
169
+ if(schema.requiredIfPresent === true){
170
+
171
+ throw {
172
+ message: 'requiredIfPresent item is null',
173
+ item,
174
+ key
175
+ };
176
+
177
+ }
178
+
179
+
168
180
  return; // skip this item if it's not required and is null
169
181
 
170
182
  }
@@ -410,6 +422,22 @@ function cleanObject(obj, schema, {
410
422
  }
411
423
 
412
424
 
425
+ if(
426
+ schema.properties[key].required === false
427
+ && schema.properties[key].requiredIfPresent === true
428
+ && cleanedValue === null
429
+ ){
430
+
431
+ throw {
432
+ message: 'value invalid',
433
+ value,
434
+ key,
435
+ requirements: schema.properties[key],
436
+ };
437
+
438
+ }
439
+
440
+
413
441
  cleanObj[key] = cleanedValue;
414
442
 
415
443
  });