@onehat/ui 0.3.320 → 0.3.321

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": "@onehat/ui",
3
- "version": "0.3.320",
3
+ "version": "0.3.321",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,13 +1,18 @@
1
1
  import * as yup from 'yup';
2
+ import _ from 'lodash';
2
3
 
3
- export default function json() {
4
+ export default function json(isRequired = false) {
4
5
  return yup.mixed().test(
5
6
  'is-json',
6
7
  '${path} is not valid JSON',
7
8
  value => {
8
9
  try {
9
- JSON.parse(value);
10
- return true; // Valid JSON
10
+ const json = JSON.parse(value);
11
+ // Valid JSON
12
+ if (isRequired && _.isEmpty(json)) {
13
+ return false; // Empty JSON
14
+ }
15
+ return true;
11
16
  } catch (error) {
12
17
  return false; // Invalid JSON
13
18
  }