EmailOptionsHelper.js 921 B

1234567891011121314151617181920212223242526272829
  1. function _getIndefiniteArticle(providerName) {
  2. const vowels = ['a', 'e', 'i', 'o', 'u']
  3. return vowels.includes(providerName.charAt(0).toLowerCase()) ? 'an' : 'a'
  4. }
  5. function _actionBuilder(providerName, action, accountLinked) {
  6. if (providerName.toLowerCase() !== 'google') {
  7. return `${providerName} account ${action}`
  8. }
  9. return accountLinked ? `New account ${action}` : `Account ${action}`
  10. }
  11. function linkOrUnlink(accountLinked, providerName, email) {
  12. const action = accountLinked ? 'linked' : 'no longer linked'
  13. const actionDescribed = accountLinked ? 'was linked to' : 'was unlinked from'
  14. const indefiniteArticle = _getIndefiniteArticle(providerName)
  15. return {
  16. to: email,
  17. action: _actionBuilder(providerName, action, accountLinked),
  18. actionDescribed: `${indefiniteArticle} ${providerName} account ${actionDescribed} your account ${email}`,
  19. }
  20. }
  21. module.exports = {
  22. linkOrUnlink,
  23. }