From 206c7ac86f088ece105e4ef1cfc5533339aab97c Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Fri, 19 Aug 2022 10:46:31 +0800 Subject: [PATCH] refactor: get name initials --- .eslintrc.json | 1 + src/common/utils.tsx | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index e44d3743..d31dcb3c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -7,6 +7,7 @@ "react/react-in-jsx-scope": "off", "semi": 2, "no-console": "off", + "no-control-regex": "off", "react/prop-types": 0, "react/no-unescaped-entities": "off", "no-unused-vars": "off", diff --git a/src/common/utils.tsx b/src/common/utils.tsx index 17df4b35..b7ee8ae4 100644 --- a/src/common/utils.tsx +++ b/src/common/utils.tsx @@ -68,7 +68,12 @@ export const getImageSize = (url: string) => { }); }; export const getInitials = (name: string, length: number = 4) => { - const arr = name.split(" ").filter((n) => !!n); + const arr = name + .split( + // eslint-disable-next-line no-misleading-character-class + /[\u0009\u000a\u000b\u000c\u000d\u0020\u0085\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u200c\u200d\u2028\u2029\u202f\u205f\u2060\u3000\ufeff]/ + ) + .filter((n) => !!n); const initialArr = arr.map((t) => [...t][0]); initialArr.length = length; return initialArr.join("").toUpperCase();