Skip to content

Commit

Permalink
feat(Validation): add small validation options for checkboxes and rad…
Browse files Browse the repository at this point in the history
…io options
  • Loading branch information
rowasc committed Dec 3, 2020
1 parent ba55ef8 commit 1060ba3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 10 additions & 0 deletions src/surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1060ba3

Please sign in to comment.