From 1060ba3c599679ba4d2f1bb68e8a5602ae9a4d40 Mon Sep 17 00:00:00 2001 From: Romina Date: Thu, 3 Dec 2020 19:21:47 -0300 Subject: [PATCH] feat(Validation): add small validation options for checkboxes and radio options --- package.json | 2 +- src/surveys.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ef9beb6..5d88bb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ushahidi-platform-sdk", - "version": "v0.3.0", + "version": "v0.3.1", "description": "An SDK for the Ushahidi Platform - V3+ compatible", "engines": { "node": ">= 10 <13" diff --git a/src/surveys.ts b/src/surveys.ts index 1885b36..3176a77 100644 --- a/src/surveys.ts +++ b/src/surveys.ts @@ -10,6 +10,16 @@ export class Surveys { this.backendUrl = backendUrl; this.setToken(token, expires); } + static validateUniqueOptions(options: []) { + + // converting to Set would remove duplicates,so if size matches original we are good + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set + return new Set(options).size === options.length; + } + static validateNonEmptyOptions(options: []) { + // check against duplicate or empty options + return options.filter(i => i === '' || i === null).length > 0; + } setToken(token?: string, expires?: number): object { this.token = null;