@openframe-org/criteria-set-protocol 2.6.1 → 2.6.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/dist/v1/utils.js +10 -7
- package/package.json +1 -1
package/dist/v1/utils.js
CHANGED
|
@@ -101,40 +101,43 @@ exports.getCertificationsByValue = getCertificationsByValue;
|
|
|
101
101
|
* In all cases, the data should contain 'text' and 'readOnly' properties
|
|
102
102
|
*/
|
|
103
103
|
const validateData = (dataOrTreeElement) => {
|
|
104
|
+
if (("type" in dataOrTreeElement) && dataOrTreeElement.type === "task-item" && !("readOnly" in dataOrTreeElement)) {
|
|
105
|
+
throw new Error("Data is missing 'readOnly' property");
|
|
106
|
+
}
|
|
104
107
|
const data = "data" in dataOrTreeElement ? dataOrTreeElement.data : dataOrTreeElement;
|
|
105
108
|
if (!data) {
|
|
106
109
|
throw new Error("Invalid data object");
|
|
107
110
|
}
|
|
108
|
-
["
|
|
111
|
+
["value", "text"].forEach((property) => {
|
|
109
112
|
if (!(property in data)) {
|
|
110
|
-
throw new Error(`
|
|
113
|
+
throw new Error(`Data is missing '${property}' property`);
|
|
111
114
|
}
|
|
112
115
|
});
|
|
113
116
|
switch (data.type) {
|
|
114
117
|
case "number":
|
|
115
118
|
case undefined: {
|
|
116
119
|
if (typeof data.value !== "number") {
|
|
117
|
-
throw new Error(
|
|
120
|
+
throw new Error(`Data value is not numeric: ${data.value}`);
|
|
118
121
|
}
|
|
119
122
|
if (!("total" in data) || typeof data.total !== "number") {
|
|
120
|
-
throw new Error(
|
|
123
|
+
throw new Error(`Data total is missing or not numeric: ${data.total}`);
|
|
121
124
|
}
|
|
122
125
|
break;
|
|
123
126
|
}
|
|
124
127
|
case "percentage": {
|
|
125
128
|
if (typeof data.value !== "number") {
|
|
126
|
-
throw new Error(
|
|
129
|
+
throw new Error(`Data value is not numeric: ${data.value}`);
|
|
127
130
|
}
|
|
128
131
|
break;
|
|
129
132
|
}
|
|
130
133
|
case "boolean": {
|
|
131
134
|
if (typeof data.value !== "boolean") {
|
|
132
|
-
throw new Error(
|
|
135
|
+
throw new Error(`Data value is not a boolean: ${data.value}`);
|
|
133
136
|
}
|
|
134
137
|
break;
|
|
135
138
|
}
|
|
136
139
|
default:
|
|
137
|
-
throw new Error(`
|
|
140
|
+
throw new Error(`Data has an invalid 'type' property: ${data.type}`);
|
|
138
141
|
}
|
|
139
142
|
};
|
|
140
143
|
exports.validateData = validateData;
|
package/package.json
CHANGED