summaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-01-25 15:35:23 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-01-25 15:35:23 +0100
commita256674c723936ac169238138b0131414f1d1499 (patch)
treeeada3d1428c084ac705e9a4b41b5a7027f8b223f /src/models
parent37434efc8ab1bc615c64d267c5a7b4296164a9d2 (diff)
Fix n & org detection in contatc model
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/models')
-rw-r--r--src/models/contact.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/models/contact.js b/src/models/contact.js
index f12cef50..6510edb8 100644
--- a/src/models/contact.js
+++ b/src/models/contact.js
@@ -25,6 +25,16 @@ import ICAL from 'ical.js'
import store from '../store'
+/**
+ * Check if the given value is an empty array or an empty string
+ *
+ * @param {string|Array} value the value to check
+ * @returns {boolean}
+ */
+const isEmpty = value => {
+ return (Array.isArray(value) && value.join('') === '') || (!Array.isArray(value) && value === '')
+}
+
export default class Contact {
/**
@@ -288,7 +298,7 @@ export default class Contact {
// ! by checking the property we check for null AND empty string
// ! that means we can then check for empty array and be safe not to have
// ! 'xxxx'.join('') !== ''
- if (orderKey && n && n.join('') !== '') {
+ if (orderKey && n && !isEmpty(n)) {
switch (orderKey) {
case 'firstName':
// Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.
@@ -306,13 +316,13 @@ export default class Contact {
return fn
}
// BUT if no FN property use the N anyway
- if (n && n.join('') !== '') {
+ if (n && !isEmpty(n)) {
// Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.
// -> John Stevenson
return n.slice(0, 2).reverse().join(' ')
}
// LAST chance, use the org ir that's the only thing we have
- if (org && org.join('') !== '') {
+ if (org && !isEmpty(org)) {
// org is supposed to be an array but is also used as plain string
return Array.isArray(org) ? org[0] : org
}