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

getrepos

Package Overview
Dependencies
Maintainers
2
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getrepos - npm Package Compare versions

Comparing version 4.0.2 to 4.0.3-next.1585263694.40cebba05df74f3fe35a2670eb1a46dac8facb6e

105

edition-browsers/index.js
/* eslint camelcase:0 */
import fetch from 'cross-fetch';
import githubAuthQueryString from 'githubauthquerystring';
const ghapi = process.env.GITHUB_API || 'https://api.github.com';
import fetch from 'cross-fetch'
import githubAuthQueryString, { redact } from 'githubauthquerystring'
const ghapi = process.env.GITHUB_API || 'https://api.github.com'
// =================================

@@ -12,19 +12,17 @@ // Fetch Repository

export async function getRepo(repoFullName) {
try {
const url = `${ghapi}/repos/${repoFullName}?${githubAuthQueryString.fetch()}`;
const resp = await fetch(url, {
headers: {
Accept: 'application/vnd.github.v3+json'
}
});
const data = (await resp.json());
if (data && data.message)
throw data.message;
if (!data || !data.full_name)
throw new Error('response was not a repository');
return data;
}
catch (err) {
return Promise.reject(githubAuthQueryString.redact(err.message));
}
try {
const url = `${ghapi}/repos/${repoFullName}?${githubAuthQueryString}`
const resp = await fetch(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
})
const data = await resp.json()
if (data && data.message) throw data.message
if (!data || !data.full_name)
throw new Error('response was not a repository')
return data
} catch (err) {
return Promise.reject(redact(err.message))
}
}

@@ -36,3 +34,5 @@ /**

export async function getRepos(repoFullNames) {
return await Promise.all(repoFullNames.map(repoFullName => getRepo(repoFullName)));
return await Promise.all(
repoFullNames.map((repoFullName) => getRepo(repoFullName))
)
}

@@ -46,31 +46,32 @@ // =================================

export async function getReposFromSearch(query, opts = {}) {
if (opts.page == null)
opts.page = 1;
if (opts.pages == null)
opts.pages = 10;
if (opts.size == null)
opts.size = 100;
try {
// fetch
const url = `${ghapi}/search/repositories?page=${opts.page}&per_page=${opts.size}&q=${encodeURIComponent(query)}&${githubAuthQueryString.fetch()}`;
const resp = await fetch(url, {
headers: {
Accept: 'application/vnd.github.v3+json'
}
});
const data = (await resp.json());
if (data && data.message)
throw data.message;
if (!data || !data.items || !Array.isArray(data.items))
throw new Error('response was not the format we expected');
if (data.items.length === 0)
return [];
const within = opts.pages === 0 || opts.page < opts.pages;
if (data.items.length === opts.size && within)
return data.items.concat(await getReposFromSearch(query, Object.assign({}, opts, { page: opts.page + 1 })));
return data.items;
}
catch (err) {
return Promise.reject(githubAuthQueryString.redact(err.message));
}
if (opts.page == null) opts.page = 1
if (opts.pages == null) opts.pages = 10
if (opts.size == null) opts.size = 100
try {
// fetch
const url = `${ghapi}/search/repositories?page=${opts.page}&per_page=${
opts.size
}&q=${encodeURIComponent(query)}&${githubAuthQueryString}`
const resp = await fetch(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
})
const data = await resp.json()
if (data && data.message) throw data.message
if (!data || !data.items || !Array.isArray(data.items))
throw new Error('response was not the format we expected')
if (data.items.length === 0) return []
const within = opts.pages === 0 || opts.page < opts.pages
if (data.items.length === opts.size && within)
return data.items.concat(
await getReposFromSearch(
query,
Object.assign({}, opts, { page: opts.page + 1 })
)
)
return data.items
} catch (err) {
return Promise.reject(redact(err.message))
}
}

@@ -82,4 +83,4 @@ /**

export async function getReposFromUsers(users, opts = {}) {
const query = users.map(name => `@${name}`).join('%20');
return await getReposFromSearch(query, opts);
const query = users.map((name) => `@${name}`).join('%20')
return await getReposFromSearch(query, opts)
}

@@ -1,10 +0,23 @@

"use strict";
'use strict'
/* eslint camelcase:0 */
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const githubauthquerystring_1 = __importDefault(require("githubauthquerystring"));
const ghapi = process.env.GITHUB_API || 'https://api.github.com';
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod }
}
var __importStar =
(this && this.__importStar) ||
function (mod) {
if (mod && mod.__esModule) return mod
var result = {}
if (mod != null)
for (var k in mod)
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]
result['default'] = mod
return result
}
Object.defineProperty(exports, '__esModule', { value: true })
const cross_fetch_1 = __importDefault(require('cross-fetch'))
const githubauthquerystring_1 = __importStar(require('githubauthquerystring'))
const ghapi = process.env.GITHUB_API || 'https://api.github.com'
// =================================

@@ -17,21 +30,19 @@ // Fetch Repository

async function getRepo(repoFullName) {
try {
const url = `${ghapi}/repos/${repoFullName}?${githubauthquerystring_1.default.fetch()}`;
const resp = await cross_fetch_1.default(url, {
headers: {
Accept: 'application/vnd.github.v3+json'
}
});
const data = (await resp.json());
if (data && data.message)
throw data.message;
if (!data || !data.full_name)
throw new Error('response was not a repository');
return data;
}
catch (err) {
return Promise.reject(githubauthquerystring_1.default.redact(err.message));
}
try {
const url = `${ghapi}/repos/${repoFullName}?${githubauthquerystring_1.default}`
const resp = await cross_fetch_1.default(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
})
const data = await resp.json()
if (data && data.message) throw data.message
if (!data || !data.full_name)
throw new Error('response was not a repository')
return data
} catch (err) {
return Promise.reject(githubauthquerystring_1.redact(err.message))
}
}
exports.getRepo = getRepo;
exports.getRepo = getRepo
/**

@@ -42,5 +53,7 @@ * Fetch data for Repositories from Repository Names

async function getRepos(repoFullNames) {
return await Promise.all(repoFullNames.map(repoFullName => getRepo(repoFullName)));
return await Promise.all(
repoFullNames.map((repoFullName) => getRepo(repoFullName))
)
}
exports.getRepos = getRepos;
exports.getRepos = getRepos
// =================================

@@ -53,33 +66,34 @@ // Fetch from Search

async function getReposFromSearch(query, opts = {}) {
if (opts.page == null)
opts.page = 1;
if (opts.pages == null)
opts.pages = 10;
if (opts.size == null)
opts.size = 100;
try {
// fetch
const url = `${ghapi}/search/repositories?page=${opts.page}&per_page=${opts.size}&q=${encodeURIComponent(query)}&${githubauthquerystring_1.default.fetch()}`;
const resp = await cross_fetch_1.default(url, {
headers: {
Accept: 'application/vnd.github.v3+json'
}
});
const data = (await resp.json());
if (data && data.message)
throw data.message;
if (!data || !data.items || !Array.isArray(data.items))
throw new Error('response was not the format we expected');
if (data.items.length === 0)
return [];
const within = opts.pages === 0 || opts.page < opts.pages;
if (data.items.length === opts.size && within)
return data.items.concat(await getReposFromSearch(query, Object.assign({}, opts, { page: opts.page + 1 })));
return data.items;
}
catch (err) {
return Promise.reject(githubauthquerystring_1.default.redact(err.message));
}
if (opts.page == null) opts.page = 1
if (opts.pages == null) opts.pages = 10
if (opts.size == null) opts.size = 100
try {
// fetch
const url = `${ghapi}/search/repositories?page=${opts.page}&per_page=${
opts.size
}&q=${encodeURIComponent(query)}&${githubauthquerystring_1.default}`
const resp = await cross_fetch_1.default(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
})
const data = await resp.json()
if (data && data.message) throw data.message
if (!data || !data.items || !Array.isArray(data.items))
throw new Error('response was not the format we expected')
if (data.items.length === 0) return []
const within = opts.pages === 0 || opts.page < opts.pages
if (data.items.length === opts.size && within)
return data.items.concat(
await getReposFromSearch(
query,
Object.assign({}, opts, { page: opts.page + 1 })
)
)
return data.items
} catch (err) {
return Promise.reject(githubauthquerystring_1.redact(err.message))
}
}
exports.getReposFromSearch = getReposFromSearch;
exports.getReposFromSearch = getReposFromSearch
/**

@@ -90,5 +104,5 @@ * Fetch data for Repostiories from Users

async function getReposFromUsers(users, opts = {}) {
const query = users.map(name => `@${name}`).join('%20');
return await getReposFromSearch(query, opts);
const query = users.map((name) => `@${name}`).join('%20')
return await getReposFromSearch(query, opts)
}
exports.getReposFromUsers = getReposFromUsers;
exports.getReposFromUsers = getReposFromUsers
# History
## v4.0.3 2020 March 27
- Fixed for latest TypeScript
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation)
## v4.0.2 2019 December 16

@@ -4,0 +9,0 @@

{
"title": "Get Repositories",
"name": "getrepos",
"version": "4.0.2",
"version": "4.0.3-next.1585263694.40cebba05df74f3fe35a2670eb1a46dac8facb6e",
"description": "Fetch the specified repositories, or those that match a particular github user or search query",

@@ -9,18 +9,20 @@ "homepage": "https://github.com/bevry/getrepos",

"keywords": [
"all",
"all github repos",
"all github repositories",
"all-repos",
"all",
"allpublic",
"api",
"browser",
"cli",
"fetch",
"get",
"get-repos",
"get-repositories",
"get",
"gh",
"gh-repos",
"gh",
"ghapi",
"git",
"git-getter",
"git",
"github",
"github repos",

@@ -33,3 +35,2 @@ "github repositories",

"github-user-repos",
"github",
"list",

@@ -40,18 +41,18 @@ "maintainers",

"node",
"org",
"org-github-repositories",
"org-repos",
"org-repositories",
"org",
"organisation",
"organisation-github-repositories",
"organisation-repositories",
"organisation",
"organisations",
"organization",
"organization-github-repositories",
"organization-repositories",
"organization",
"organizations",
"orgs",
"owner",
"owner-github-repositories",
"owner-repositories",
"owner",
"owners",

@@ -75,6 +76,6 @@ "paginate",

"typescript",
"user",
"user-github-repositories",
"user-repos",
"user-repositories",
"user",
"users",

@@ -111,3 +112,4 @@ "util",

"paypalURL": "https://bevry.me/paypal",
"wishlistURL": "https://bevry.me/wishlist"
"wishlistURL": "https://bevry.me/wishlist",
"travisTLD": "com"
}

@@ -121,4 +123,3 @@ },

"contributors": [
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)",
"dependabot-preview[bot] (http://github.com/apps/dependabot-preview)"
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)"
],

@@ -137,3 +138,3 @@ "bugs": {

{
"description": "typescript source code with import for modules",
"description": "TypeScript source code with Import for modules",
"directory": "source",

@@ -148,3 +149,3 @@ "entry": "index.ts",

{
"description": "typescript compiled against ESNext for web browsers with import for modules",
"description": "TypeScript compiled against ESNext for web browsers with Import for modules",
"directory": "edition-browsers",

@@ -162,3 +163,3 @@ "entry": "index.js",

{
"description": "typescript compiled against ESNext for Node.js with require for modules",
"description": "TypeScript compiled against ESNext for Node.js with Require for modules",
"directory": "edition-esnext",

@@ -184,20 +185,21 @@ "entry": "index.js",

"cross-fetch": "^3.0.4",
"githubauthquerystring": "^2.3.0",
"githubauthquerystring": "^4.0.0",
"simplytyped": "^3.2.3"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"assert-helpers": "^5.8.0",
"eslint": "^6.7.2",
"eslint-config-bevry": "^2.3.0",
"eslint-config-prettier": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"assert-helpers": "^6.0.0",
"eslint": "^6.8.0",
"eslint-config-bevry": "^3.0.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
"kava": "^4.4.0",
"prettier": "^1.19.1",
"projectz": "^1.16.0",
"prettier": "^2.0.2",
"projectz": "^1.19.0",
"surge": "^0.21.3",
"typedoc": "^0.15.4",
"typescript": "^3.7.3",
"valid-directory": "^1.6.0"
"typedoc": "^0.17.3",
"typescript": "^3.8.3",
"valid-directory": "^1.6.0",
"valid-module": "^1.0.0"
},

@@ -223,6 +225,7 @@ "scripts": {

"our:test": "npm run our:verify && npm test",
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:prettier && npm run our:verify:typescript",
"our:verify:directory": "npx valid-directory",
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:module && npm run our:verify:prettier && npm run our:verify:typescript",
"our:verify:directory": "valid-directory",
"our:verify:eslint": "eslint --fix --ignore-pattern '**/*.d.ts' --ignore-pattern '**/vendor/' --ignore-pattern '**/node_modules/' --ext .mjs,.js,.jsx,.ts,.tsx ./source",
"our:verify:prettier": "prettier --write ./source/**",
"our:verify:module": "valid-module",
"our:verify:prettier": "prettier --write .",
"our:verify:typescript": "tsc --noEmit --project tsconfig.json",

@@ -229,0 +232,0 @@ "test": "node ./edition-esnext/test.js"

@@ -10,3 +10,3 @@ <!-- TITLE/ -->

<span class="badge-travisci"><a href="http://travis-ci.org/bevry/getrepos" title="Check this project's build status on TravisCI"><img src="https://img.shields.io/travis/bevry/getrepos/master.svg" alt="Travis CI Build Status" /></a></span>
<span class="badge-travisci"><a href="http://travis-ci.com/bevry/getrepos" title="Check this project's build status on TravisCI"><img src="https://img.shields.io/travis/com/bevry/getrepos/master.svg" alt="Travis CI Build Status" /></a></span>
<span class="badge-npmversion"><a href="https://npmjs.org/package/getrepos" title="View this project on NPM"><img src="https://img.shields.io/npm/v/getrepos.svg" alt="NPM version" /></a></span>

@@ -37,2 +37,27 @@ <span class="badge-npmdownloads"><a href="https://npmjs.org/package/getrepos" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/getrepos.svg" alt="NPM downloads" /></a></span>

## Usage
[Complete API Documentation.](http://master.getrepos.bevry.surge.sh/docs/globals.html)
```javascript
import {
getRepo,
getRepos,
getReposFromSearch,
getReposFromUsers,
} from 'getrepos'
// https://developer.github.com/v3/repos/#get
getRepo('bevry/getrepos').then(console.log).catch(console.error)
getRepos(['bevry/getrepos']).then(console.log).catch(console.error)
// https://developer.github.com/v3/search/#search-repositories
getReposFromSearch('@bevry', { pages: 0 })
.then(console.log)
.catch(console.error)
getReposFromUsers(['bevry'], { pages: 0 })
.then(console.log)
.catch(console.error)
```
<!-- INSTALL/ -->

@@ -45,5 +70,22 @@

<li>Install: <code>npm install --save getrepos</code></li>
<li>Require: <code>require('getrepos')</code></li>
<li>Import: <code>import * as pkg from ('getrepos')</code></li>
<li>Require: <code>const pkg = require('getrepos')</code></li>
</ul>
<a href="https://www.pika.dev/cdn" title="100% Native ES Modules CDN"><h3>pika</h3></a>
``` html
<script type="module">
import * as pkg from '//cdn.pika.dev/getrepos/^4.0.3'
</script>
```
<a href="https://unpkg.com" title="unpkg is a fast, global content delivery network for everything on npm"><h3>unpkg</h3></a>
``` html
<script type="module">
import * as pkg from '//unpkg.com/getrepos@^4.0.3'
</script>
```
<a href="https://jspm.io" title="Native ES Modules CDN"><h3>jspm</h3></a>

@@ -53,3 +95,3 @@

<script type="module">
import * as pkg from '//dev.jspm.io/getrepos'
import * as pkg from '//dev.jspm.io/getrepos@4.0.3'
</script>

@@ -62,41 +104,10 @@ ```

<ul><li><code>getrepos/source/index.ts</code> is typescript source code with import for modules</li>
<li><code>getrepos/edition-browsers/index.js</code> is typescript compiled against <a href="https://babeljs.io/docs/learn-es2015/" title="ECMAScript Next">ESNext</a> for web browsers with import for modules</li>
<ul><li><code>getrepos/source/index.ts</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> source code with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li>
<li><code>getrepos/edition-browsers/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> for web browsers with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li>
<li><code>getrepos</code> aliases <code>getrepos/edition-esnext/index.js</code></li>
<li><code>getrepos/edition-esnext/index.js</code> is typescript compiled against <a href="https://babeljs.io/docs/learn-es2015/" title="ECMAScript Next">ESNext</a> for Node.js with require for modules</li></ul>
<li><code>getrepos/edition-esnext/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li></ul>
<p>Environments older than Node.js v8 may need <a href="https://babeljs.io/docs/usage/polyfill/" title="A polyfill that emulates missing ECMAScript environment features">Babel's Polyfill</a> or something similar.</p>
<!-- /INSTALL -->
## Usage
[API Documentation.](http://master.getrepos.bevry.surge.sh/docs/)
```javascript
import {
getRepo,
getRepos,
getReposFromSearch,
getReposFromUsers
} from 'getrepos'
// https://developer.github.com/v3/repos/#get
getRepo('bevry/getrepos')
.then(console.log)
.catch(console.error)
getRepos(['bevry/getrepos'])
.then(console.log)
.catch(console.error)
// https://developer.github.com/v3/search/#search-repositories
getReposFromSearch('@bevry', { pages: 0 })
.then(console.log)
.catch(console.error)
getReposFromUsers(['bevry'], { pages: 0 })
.then(console.log)
.catch(console.error)
```
<!-- HISTORY/ -->

@@ -103,0 +114,0 @@

@@ -6,3 +6,3 @@ /* eslint camelcase:0 */

import fetch from 'cross-fetch'
import githubAuthQueryString from 'githubauthquerystring'
import githubAuthQueryString, { redact } from 'githubauthquerystring'
const ghapi = process.env.GITHUB_API || 'https://api.github.com'

@@ -224,7 +224,7 @@

try {
const url = `${ghapi}/repos/${repoFullName}?${githubAuthQueryString.fetch()}`
const url = `${ghapi}/repos/${repoFullName}?${githubAuthQueryString}`
const resp = await fetch(url, {
headers: {
Accept: 'application/vnd.github.v3+json'
}
Accept: 'application/vnd.github.v3+json',
},
})

@@ -237,3 +237,3 @@ const data = (await resp.json()) as RepositoryResponse

} catch (err) {
return Promise.reject(githubAuthQueryString.redact(err.message))
return Promise.reject(redact(err.message))
}

@@ -248,3 +248,3 @@ }

return await Promise.all(
repoFullNames.map(repoFullName => getRepo(repoFullName))
repoFullNames.map((repoFullName) => getRepo(repoFullName))
)

@@ -271,7 +271,7 @@ }

opts.size
}&q=${encodeURIComponent(query)}&${githubAuthQueryString.fetch()}`
}&q=${encodeURIComponent(query)}&${githubAuthQueryString}`
const resp = await fetch(url, {
headers: {
Accept: 'application/vnd.github.v3+json'
}
Accept: 'application/vnd.github.v3+json',
},
})

@@ -293,3 +293,3 @@ const data = (await resp.json()) as SearchResponse

} catch (err) {
return Promise.reject(githubAuthQueryString.redact(err.message))
return Promise.reject(redact(err.message))
}

@@ -306,4 +306,4 @@ }

): Promise<SearchRepository[]> {
const query = users.map(name => `@${name}`).join('%20')
const query = users.map((name) => `@${name}`).join('%20')
return await getReposFromSearch(query, opts)
}

@@ -11,5 +11,3 @@ {

},
"include": [
"source"
]
"include": ["source"]
}
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