Skip to content

Instantly share code, notes, and snippets.

Last active February 22, 2023 21:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A Deno script that fetches the mostly commonly used folder names in popular NPM packages. Read the blog post:
import packages from "./packages.json" assert { type: "json" };
const GITHUB_API_URL = "";
const fallbackRepoURL = {
yarn: ''
const directories = new Map();
console.log('Fetching packages information...');
const pkgs = await Promise.all( =>
.then(res => res.json())
console.log('Fetching repositories information...');
const repos = await Promise.all( => {
// Parse the repo URL for every package, fallback to a predefined
// map when a URL is unavailable
const githubUrl = new URL(pkg.repository.url ?? fallbackRepoURL[]);
const repoNamespace = githubUrl.pathname.replace(/\.git$/i, "");
return fetch(`${GITHUB_API_URL}/repos${repoNamespace}/contents`)
.then(res => res.json())
.filter(file => file.type === 'dir')
.map(dir =>
.forEach(dir => {
let count = directories.get(dir);
directories.set(dir, count ? ++count : 1);
const dirs = Array.from(directories.entries())
// Filter out the directories that appear only once
.filter(v => v[1] > 1)
// Sort desc by their count
.sort((a, b) => b[1] - a[1]);
// Print out the result
for (let [dir, count] of dirs) {
console.log(dir, ':', count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment