egirlskey/src/misc/extract-hashtags.ts

10 lines
383 B
TypeScript
Raw Normal View History

2019-01-30 05:51:30 +00:00
import { HashtagNode, MfmForest } from '../mfm/types';
import { preorderF } from '../prelude/tree';
import { unique } from '../prelude/array';
export default function(mfmForest: MfmForest): string[] {
const hashtagNodes = preorderF(mfmForest).filter(x => x.type === 'hashtag') as HashtagNode[];
const hashtags = hashtagNodes.map(x => x.props.hashtag);
return unique(hashtags);
}