summaryrefslogtreecommitdiffstats
path: root/converter.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2013-08-09 17:18:12 +0200
committerMatěj Cepl <mcepl@redhat.com>2013-08-09 17:18:12 +0200
commited16c0a0744c811c0e6182cf9d96941cc397b1eb (patch)
tree0aa142b0d4b869ebf46ae417e56cdad9f235209d /converter.js
parent73ba5a57e48f1d4316eabef201183342be5e41ad (diff)
downloadLDIF2Contact-ed16c0a0744c811c0e6182cf9d96941cc397b1eb.tar.gz
Clean phone numbers, don’t leave them formatted.HEADmaster
Diffstat (limited to 'converter.js')
-rw-r--r--converter.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/converter.js b/converter.js
index 1c8ae81..f90fe59 100644
--- a/converter.js
+++ b/converter.js
@@ -32,6 +32,8 @@ function translateObjectToContact(inRec) {
ValueError.prototype = new Error();
ValueError.prototype.constructor = ValueError;
+ const cleanPhoneNoRE = /[^0-9+]*/g;
+
/**
* Find the proper record (or create new one) in the multi-value
* attribute
@@ -117,6 +119,14 @@ function translateObjectToContact(inRec) {
}
}
+ /**
+ * Firefox OS doesn’t recognize well formatted phone numbers, and
+ * works best with the plain number-only ones.
+ */
+ function cleanPhoneNumber(inNo) {
+ return inNo.replace(cleanPhoneNoRE, "");
+ }
+
for (var key in inRec) {
if (["birthyear", "birthmonth", "birthday"].indexOf(key) !== -1) {
// We have alternatively either whole date in birthyear field,
@@ -159,14 +169,14 @@ function translateObjectToContact(inRec) {
}
else if (key === "facsimiletelephonenumber") {
curRec = findSubElement("tel", "fax");
- curRec.value = inRec[key];
+ curRec.value = cleanPhoneNumber(inRec[key]);
}
else if (key === "givenName") {
contact.givenName = [inRec[key]];
}
else if (key === "homePhone") {
curRec = findSubElement("tel", "home");
- curRec.value = inRec[key];
+ curRec.value = cleanPhoneNumber(inRec[key]);
}
else if (key === "l") {
curRec = findSubElement("adr", "work");
@@ -182,7 +192,7 @@ function translateObjectToContact(inRec) {
}
else if (key === "mobile") {
curRec = findSubElement("tel", "mobile");
- curRec.value = inRec[key];
+ curRec.value = cleanPhoneNumber(inRec[key]);
}
else if (key === "mozillaHomeCountryName") {
curRec = findSubElement("adr", "home");
@@ -275,7 +285,7 @@ function translateObjectToContact(inRec) {
}
else if (key === "telephoneNumber") {
curRec = findSubElement("tel", "work");
- curRec.value = inRec[key];
+ curRec.value = cleanPhoneNumber(inRec[key]);
}
else if (key === "title") {
contact.jobTitle = [inRec[key]];