trim events' location, change variable name

This commit is contained in:
Daniel Waxweiler 2022-01-09 12:54:58 +01:00
parent ec12889815
commit 184d5627a3
3 changed files with 14 additions and 8 deletions

View File

@ -8,6 +8,7 @@
#### Removed #### Removed
#### Fixed #### Fixed
- Use ES modules correctly - Use ES modules correctly
- Trim events' location
#### Security #### Security
### [0.7.0] - 2021-12-23 ### [0.7.0] - 2021-12-23

View File

@ -53,16 +53,21 @@ test('#formatDate second date is null with short offset name', (t) => {
}) })
test('#formatLocation both parameters', (t) => { test('#formatLocation both parameters', (t) => {
const date = Formatter.formatLocation({ description: 'a', locality: 'b' }) const location = Formatter.formatLocation({ description: 'a', locality: 'b' })
t.is(date, 'a, b') t.is(location, 'a, b')
}) })
test('#formatLocation description only', (t) => { test('#formatLocation description only', (t) => {
const date = Formatter.formatLocation({ description: 'a' }) const location = Formatter.formatLocation({ description: 'a' })
t.is(date, 'a') t.is(location, 'a')
})
test('#formatLocation description with space only', (t) => {
const location = Formatter.formatLocation({ description: ' ' })
t.is(location, '')
}) })
test('#formatLocation locality only', (t) => { test('#formatLocation locality only', (t) => {
const date = Formatter.formatLocation({ locality: 'a' }) const location = Formatter.formatLocation({ locality: 'a' })
t.is(date, 'a') t.is(location, 'a')
}) })

View File

@ -31,8 +31,8 @@ export default class Formatter {
static formatLocation({ description, locality }) { static formatLocation({ description, locality }) {
let location = '' let location = ''
if (description) { if (description && description.trim()) {
location += description location += description.trim()
} }
if (location && locality) { if (location && locality) {
location += ', ' location += ', '