shortName stability

This commit is contained in:
tmshv committed 2017-05-26 18:41:26 +03:00
1 parent fcf45614a3
commit c5708a1ff2
1 file changed
+8 -4
+8 -4
View File
@@ -6,9 +6,13 @@
* @returns {string}
*/
export function shortName(name) {
const f = i => i.replace(/^(.).+/, '$1');
const [, first, middle, last] = splitName(name);
return `${f(first)}. ${f(middle)}. ${last}`;
try {
const f = i => i.replace(/^(.).+/, '$1')
const [, first, middle, last] = splitName(name)
return `${f(first)}. ${f(middle)}. ${last}`
} catch (e) {
return name
}
}
/**
@@ -19,5 +23,5 @@ export function shortName(name) {
* @returns {Array|{index: number, input: string}}
*/
export function splitName(name) {
return /(.+)\s(.+)\s(.+)/.exec(name);
return /(.+)\s(.+)\s(.+)/.exec(name)
}