-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow audiences helper to return a single string audience
- Loading branch information
Showing
4 changed files
with
30 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = function ensureConform(audiences) { | ||
assert(Array.isArray(audiences) && audiences.length, 'audiences must be an array with members'); | ||
module.exports = function ensureConform(audience) { | ||
assert( | ||
(Array.isArray(audience) || typeof audience === 'string') && audience.length, | ||
'audiences must be an array with members or a single string value', | ||
); | ||
|
||
const value = audiences.slice(); | ||
value.forEach((audience) => { | ||
assert(audience && typeof audience === 'string', 'audiences must be non-empty string values'); | ||
}); | ||
let value; | ||
if (typeof audience === 'string') { | ||
value = audience; | ||
} else { | ||
value = [...audience]; | ||
value.forEach((aud) => { | ||
assert(typeof aud === 'string' && aud.length, 'audiences must be non-empty string values'); | ||
}); | ||
} | ||
|
||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters