aboutsummaryrefslogtreecommitdiff
path: root/src/lib/data-validator.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/data-validator.js')
-rw-r--r--src/lib/data-validator.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/lib/data-validator.js b/src/lib/data-validator.js
index 276ea9b..6d1d8f0 100644
--- a/src/lib/data-validator.js
+++ b/src/lib/data-validator.js
@@ -36,8 +36,9 @@ function checkType(expectedType, value) {
/**
* @param {object} data
* @param {array} schema
+ * @throws Error
*/
-function validateMessageData(data, schema) {
+function validateObjectSchema(data, schema) {
if (!isObject(data))
throw new Error(`data is not an object`)
@@ -68,4 +69,21 @@ function validateMessageData(data, schema) {
}
}
-module.exports = {validateMessageData} \ No newline at end of file
+function validateTargetsList(targets) {
+ if (!Array.isArray(targets))
+ throw new Error('targets must be array')
+
+ if (!targets.length)
+ throw new Error('targets are empty')
+
+ for (const t of targets) {
+ const type = typeof t
+ if (type !== 'string')
+ throw new Error(`all targets must be strings, ${type} given`)
+ }
+}
+
+module.exports = {
+ validateObjectSchema,
+ validateTargetsList
+} \ No newline at end of file