From 63665e8bd1fa76c19f778c31e174fd94a727e9bd Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 4 Feb 2023 00:21:13 +0100 Subject: [PATCH] client: replace array concat with Array.prototype.flat --- packages/client/src/components/cw-button.vue | 5 ++--- packages/client/src/components/mfm.ts | 5 ++--- packages/client/src/scripts/array.ts | 9 +-------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/cw-button.vue b/packages/client/src/components/cw-button.vue index c162f759c..c68552ab0 100644 --- a/packages/client/src/components/cw-button.vue +++ b/packages/client/src/components/cw-button.vue @@ -9,7 +9,6 @@ import { computed } from 'vue'; import { length } from 'stringz'; import * as foundkey from 'foundkey-js'; -import { concat } from '@/scripts/array'; import { i18n } from '@/i18n'; const props = defineProps<{ @@ -22,12 +21,12 @@ const emit = defineEmits<{ }>(); const label = computed(() => { - return concat([ + return [ props.note.text ? [i18n.t('_cw.chars', { count: length(props.note.text) })] : [], props.note.files && props.note.files.length !== 0 ? [i18n.t('_cw.files', { count: props.note.files.length }) ] : [], props.note.poll != null ? [i18n.ts.poll] : [], props.note.renoteId != null ? [i18n.ts.quote] : [], - ] as string[][]).join(' / '); + ].flat().join(' / '); }); const toggle = () => { diff --git a/packages/client/src/components/mfm.ts b/packages/client/src/components/mfm.ts index 466fcbdb0..ef083eb4d 100644 --- a/packages/client/src/components/mfm.ts +++ b/packages/client/src/components/mfm.ts @@ -4,7 +4,6 @@ import MkUrl from '@/components/global/url.vue'; import MkLink from '@/components/link.vue'; import MkMention from '@/components/mention.vue'; import MkEmoji from '@/components/global/emoji.vue'; -import { concat } from '@/scripts/array'; import MkFormula from '@/components/formula.vue'; import MkCode from '@/components/code.vue'; import MkSearch from '@/components/mfm-search.vue'; @@ -50,7 +49,7 @@ export default defineComponent({ return t.match(/^[0-9.]+s$/) ? t : null; }; - const genEl = (ast: mfm.MfmNode[]) => concat(ast.map((token): VNode[] => { + const genEl = (ast: mfm.MfmNode[]) => ast.map((token): VNode[] => { switch (token.type) { case 'text': { const text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n'); @@ -314,7 +313,7 @@ export default defineComponent({ return []; } } - })); + }).flat(); // Parse ast to DOM return h('span', genEl(ast)); diff --git a/packages/client/src/scripts/array.ts b/packages/client/src/scripts/array.ts index 26c6195d6..e5b9016c0 100644 --- a/packages/client/src/scripts/array.ts +++ b/packages/client/src/scripts/array.ts @@ -15,19 +15,12 @@ export function count(a: T, xs: T[]): number { return countIf(x => x === a, xs); } -/** - * Concatenate an array of arrays - */ -export function concat(xss: T[][]): T[] { - return ([] as T[]).concat(...xss); -} - /** * Intersperse the element between the elements of the array * @param sep The element to be interspersed */ export function intersperse(sep: T, xs: T[]): T[] { - return concat(xs.map(x => [sep, x])).slice(1); + return xs.map(x => [sep, x]).flat().slice(1); } /**