Use replace instead of replaceAll for browser compatibility (#222)

Also, moved the `replaced` outside of the find-loop so that we don't re-run it each time.
This commit is contained in:
infinite-persistence 2021-11-04 12:56:29 +08:00 committed by GitHub
parent 11d3f88654
commit 60a0d6d31a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,13 +98,8 @@ export const buildValidSticker = (sticker: string) => `<stkr>${sticker}<stkr>`;
export function parseSticker(comment: string) { export function parseSticker(comment: string) {
const matchSticker = comment.match(stickerRegex); const matchSticker = comment.match(stickerRegex);
const stickerValue = matchSticker && matchSticker[0]; const stickerValue = matchSticker && matchSticker[0];
const stickerName = stickerValue && stickerValue.replace(/<stkr>/g, '');
const commentIsSticker = stickerValue && stickerValue.length === comment.length; const commentIsSticker = stickerValue && stickerValue.length === comment.length;
return ( return commentIsSticker && ALL_VALID_STICKERS.find((sticker) => sticker.name === stickerName);
commentIsSticker &&
ALL_VALID_STICKERS.find((sticker) => {
// $FlowFixMe
return sticker.name === stickerValue.replaceAll('<stkr>', '');
})
);
} }