summaryrefslogtreecommitdiff
path: root/packages/backend/src/misc/extract-custom-emojis-from-mfm.ts
blob: 0b898d47e82e5a748cca14d5d96dd4d1dc2fb629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * SPDX-FileCopyrightText: syuilo and other misskey contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import * as mfm from 'mfm-js';
import { unique } from '@/misc/prelude/array.js';

export function extractCustomEmojisFromMfm(nodes: mfm.MfmNode[]): string[] {
	const emojiNodes = mfm.extract(nodes, (node) => {
		return (node.type === 'emojiCode' && node.props.name.length <= 100);
	}) as mfm.MfmEmojiCode[];

	return unique(emojiNodes.map(x => x.props.name));
}