Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

list-github-dir-content

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

list-github-dir-content - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

index.d.ts

35

index.js

@@ -1,8 +0,6 @@

const fetch = require('node-fetch'); // Automatically excluded in browser bundles
async function api(endpoint, token) {
const response = await fetch(`https://api.github.com/repos/${endpoint}`, {
headers: token ? {
Authorization: `Bearer ${token}`
} : undefined
Authorization: `Bearer ${token}`,
} : undefined,
});

@@ -14,13 +12,13 @@ return response.json();

// Cons: many requests if the repo has a lot of nested dirs
async function viaContentsApi({
export async function getDirectoryContentViaContentsApi({
user,
repository,
ref = 'HEAD',
ref: reference = 'HEAD',
directory,
token,
getFullData = false
getFullData = false,
}) {
const files = [];
const requests = [];
const contents = await api(`${user}/${repository}/contents/${directory}?ref=${ref}`, token);
const contents = await api(`${user}/${repository}/contents/${directory}?ref=${reference}`, token);

@@ -39,9 +37,9 @@ if (contents.message === 'Not Found') {

} else if (item.type === 'dir') {
requests.push(viaContentsApi({
requests.push(getDirectoryContentViaContentsApi({
user,
repository,
ref,
ref: reference,
directory: item.path,
token,
getFullData
getFullData,
}));

@@ -51,3 +49,3 @@ }

return files.concat(...await Promise.all(requests));
return [...files, ...await Promise.all(requests)];
}

@@ -58,9 +56,9 @@

// Cons: huge on huge repos + may be truncated
async function viaTreesApi({
export async function getDirectoryContentViaTreesApi({
user,
repository,
ref = 'HEAD',
ref: reference = 'HEAD',
directory,
token,
getFullData = false
getFullData = false,
}) {

@@ -72,3 +70,3 @@ if (!directory.endsWith('/')) {

const files = [];
const contents = await api(`${user}/${repository}/git/trees/${ref}?recursive=1`, token);
const contents = await api(`${user}/${repository}/git/trees/${reference}?recursive=1`, token);
if (contents.message) {

@@ -87,6 +85,1 @@ throw new Error(contents.message);

}
module.exports.viaContentsApi = viaContentsApi;
module.exports.viaContentApi = viaContentsApi;
module.exports.viaTreesApi = viaTreesApi;
module.exports.viaTreeApi = viaTreesApi;

19

package.json
{
"name": "list-github-dir-content",
"version": "3.0.0",
"version": "4.0.0",
"description": "List all the files in a GitHub repo’s directory",

@@ -16,10 +16,9 @@ "keywords": [

"license": "MIT",
"author": "Federico Brigante <opensource@bfred.it> (bfred.it)",
"author": "Federico Brigante <me@fregante.com> (https://fregante.com)",
"type": "module",
"exports": "./index.js",
"files": [
"index.js",
"browser-fetch.js"
"index.d.ts"
],
"browser": {
"node-fetch": "./browser-fetch"
},
"scripts": {

@@ -34,8 +33,8 @@ "manual-test": "node tests.js",

},
"dependencies": {
"node-fetch": "^2.6.0"
"devDependencies": {
"xo": "^0.58.0"
},
"devDependencies": {
"xo": "^0.32.0"
"engines": {
"node": ">=18"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc