@octokit/core
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -60,3 +60,3 @@ 'use strict'; | ||
const VERSION = "3.0.0"; | ||
const VERSION = "3.1.0"; | ||
@@ -142,2 +142,8 @@ class Octokit { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent ? { | ||
@@ -144,0 +150,0 @@ userAgent: `${options.userAgent} ${defaults.userAgent}` |
@@ -88,2 +88,6 @@ import { getUserAgent } from "universal-user-agent"; | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent | ||
@@ -90,0 +94,0 @@ ? { |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "3.0.0"; | ||
export const VERSION = "3.1.0"; |
@@ -7,3 +7,3 @@ import { HookCollection } from "before-after-hook"; | ||
static VERSION: string; | ||
static defaults<S extends Constructor<any>>(this: S, defaults: OctokitOptions): { | ||
static defaults<S extends Constructor<any>>(this: S, defaults: OctokitOptions | Function): { | ||
new (...args: any[]): { | ||
@@ -10,0 +10,0 @@ [x: string]: any; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "3.0.0"; | ||
export declare const VERSION = "3.1.0"; |
@@ -7,3 +7,3 @@ import { getUserAgent } from 'universal-user-agent'; | ||
const VERSION = "3.0.0"; | ||
const VERSION = "3.1.0"; | ||
@@ -91,2 +91,6 @@ class Octokit { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent | ||
@@ -93,0 +97,0 @@ ? { |
{ | ||
"name": "@octokit/core", | ||
"description": "Extendable client for GitHub's REST & GraphQL APIs", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -6,3 +6,3 @@ # core.js | ||
[![@latest](https://img.shields.io/npm/v/@octokit/core.svg)](https://www.npmjs.com/package/@octokit/core) | ||
[![Build Status](https://github.com/octokit/core.js/workflows/Test/badge.svg)](https://github.com/octokit/core.js/actions?query=workflow%3ATest) | ||
[![Build Status](https://github.com/octokit/core.js/workflows/Test/badge.svg)](https://github.com/octokit/core.js/actions?query=workflow%3ATest+branch%3Amaster) | ||
@@ -25,3 +25,3 @@ <!-- toc --> | ||
If you need a minimalistic library to utilize GitHub's [REST API](https://developer.github.com/v3/) and [GraphQL API](https://developer.github.com/v4/) which you can extend with plugins as needed, than `@octokit/core` is a great starting point. | ||
If you need a minimalistic library to utilize GitHub's [REST API](https://developer.github.com/v3/) and [GraphQL API](https://developer.github.com/v4/) which you can extend with plugins as needed, then `@octokit/core` is a great starting point. | ||
@@ -255,2 +255,36 @@ If you don't need the Plugin API then using [`@octokit/request`](https://github.com/octokit/request.js/) or [`@octokit/graphql`](https://github.com/octokit/graphql.js/) directly is a good alternative. | ||
If you pass additional options to your new constructor, the options will be merged shallowly. | ||
```js | ||
const MyOctokit = Octokit.defaults({ | ||
foo: { | ||
opt1: 1, | ||
}, | ||
}); | ||
const octokit = new MyOctokit({ | ||
foo: { | ||
opt2: 1, | ||
}, | ||
}); | ||
// options will be { foo: { opt2: 1 }} | ||
``` | ||
If you need a deep or conditional merge, you can pass a function instead. | ||
```js | ||
const MyOctokit = Octokit.defaults({ | ||
foo: { | ||
opt1: 1, | ||
}, | ||
}); | ||
const octokit = new MyOctokit((options) => { | ||
return { | ||
foo: Object.assign({}, options.foo, { opt2: 1 }), | ||
}; | ||
}); | ||
// options will be { foo: { opt1: 1, opt2: 1 }} | ||
``` | ||
Be careful about mutating the `options` object directly, as it can have unforeseen consequences. | ||
## Authentication | ||
@@ -257,0 +291,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48751
447
441