diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-06 09:44:39 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-06 09:44:42 +0100 |
commit | d34f8750dd4a7ac99c91fdfdcfcc67bb60215cac (patch) | |
tree | dd5d7d049cd7528b8dcf2cb1a04928b371a1e08c /src/services/checks | |
parent | 55a30db2e75c416c1139ee938eaea18c70bb0807 (diff) |
Gender auto fix
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/services/checks')
-rw-r--r-- | src/services/checks/badGenderType.js | 44 | ||||
-rw-r--r-- | src/services/checks/index.js | 2 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/services/checks/badGenderType.js b/src/services/checks/badGenderType.js new file mode 100644 index 00000000..a113ad8e --- /dev/null +++ b/src/services/checks/badGenderType.js @@ -0,0 +1,44 @@ +/** + * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com> + * + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +import rfcProps from 'Models/rfcProps' + +// https://tools.ietf.org/html/rfc6350#section-6.2.7 + +export default { + name: 'bad gender type', + run: contact => { + return contact.vCard.hasProperty('gender') + && contact.vCard.getFirstProperty('gender').getFirstParameter('type') + }, + fix: contact => { + const gender = contact.vCard.getFirstProperty('gender') + const type = gender.getFirstParameter('type') + const option = Object.values(rfcProps.properties({}).gender.options).find(opt => opt.id === type) + if (option) { + gender.removeParameter('type') + gender.setValue(option.id) + return true + } + return false + } +} diff --git a/src/services/checks/index.js b/src/services/checks/index.js index 4a72ce09..de67af19 100644 --- a/src/services/checks/index.js +++ b/src/services/checks/index.js @@ -20,8 +20,10 @@ * */ +import badGenderType from './badGenderType' import missingFN from './missingFN' export default [ + badGenderType, missingFN ] |