-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.js
More file actions
18 lines (17 loc) · 815 Bytes
/
shared.js
File metadata and controls
18 lines (17 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* Check an item with a ._id property (e.g. a repeater item being read from a database) for a set of required properties
* @param {object} itemData - object to be checked for all required properties
* @param {array [string]} requiredProperties - array of all properties that are required
* @throws {Error} if item is passed without an ._id property
* @throws {Error} if the item is missing any of the required properties
*/
export function checkItemProperties(item, requiredProperties) {
if (item._id === undefined) {
throw new Error("Improper usage of checkItemProperties(); received an item without an ID")
}
requiredProperties.forEach((property) => {
if (!item.hasOwnProperty(property)) {
throw new Error("Item ID: " + item._id + " missing property: " + property)
}
});
}