repos / neovimcraft

website that makes it easy to find neovim plugins
git clone https://github.com/neurosnap/neovimcraft.git

neovimcraft / src
Eric Bower · 27 Nov 22

plugin-data.ts

 1import type { Plugin, PluginData, PluginMap, TagMap } from "./types.ts";
 2
 3function getTagsDb(plist: Plugin[]): TagMap {
 4  const tagsDb: TagMap = {};
 5  plist.forEach((plugin) => {
 6    plugin.tags.forEach((tag) => {
 7      if (!tagsDb[tag]) {
 8        tagsDb[tag] = { id: tag, count: 0 };
 9      }
10      tagsDb[tag].count += 1;
11    });
12  });
13  return tagsDb;
14}
15
16export function derivePluginData(pluginDb: PluginMap): PluginData {
17  const plugins = Object.values(pluginDb).sort((a, b) => b.stars - a.stars);
18  const tagDb = getTagsDb(plugins);
19  const tags = Object.values(tagDb).sort((a, b) => b.count - a.count);
20  return { plugins, tags, tagDb };
21}