提交 18aa539b 编写于 作者: J Jake Champion

nice

上级 405ec5d4
// eslint-disable-next-line no-undef
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
}
}
{
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module"
},
"globals": {
"WHATWGFetch": true,
"ArrayBuffer": true,
"DataView": true,
"Promise": true,
"Symbol": true,
"Uint8Array": true,
"globalThis": true
},
"extends": [
"plugin:github/browser"
],
"rules": {
"object-shorthand": "off"
},
"overrides": [
{
"files": ["test/*.js"],
"env": {
"browser": true,
"mocha": true
},
"globals": {
"assert": true,
"chai": true,
"FileReaderSync": true,
"Mocha": true
}
},
{
"files": ["test/{karma,server}*.js"],
"env": {
"node": true
}
},
{
"files": ["test/worker.js"],
"env": {
"worker": true
}
}
]
}
.env
package-lock.json
bower_components/
node_modules/
sauce_connect/
sauce_connect.log
test: lint dist/fetch.umd.js
lint: node_modules/
./node_modules/.bin/eslint --report-unused-disable-directives *.js test/*.js
dist/fetch.umd.js: fetch.js rollup.config.js node_modules/
./node_modules/.bin/rollup -c
dist/fetch.umd.js.flow: fetch.js.flow
cp $< $@
node_modules/:
npm install
clean:
rm -rf ./bower_components ./node_modules ./dist
.PHONY: clean lint test make dist/fetch.umd.js dist/fetch.umd.js.flow
{
"name": "fetch",
"main": "fetch.js",
"ignore": [
".*",
"*.md",
"examples/",
"Makefile",
"package.json",
"script/",
"test/"
]
}
......@@ -23,7 +23,7 @@ var support = {
}
function isDataView(obj) {
return obj && DataView.prototype.isPrototypeOf(obj)
return obj && Object.prototype.isPrototypeOf.call(DataView, obj)
}
if (support.arrayBuffer) {
......@@ -81,7 +81,8 @@ function iteratorFor(items) {
return iterator
}
export function Headers(headers) {
// eslint-disable-next-line no-redeclare
function Headers(headers) {
this.map = {}
if (headers instanceof Headers) {
......@@ -116,7 +117,7 @@ Headers.prototype.get = function(name) {
}
Headers.prototype.has = function(name) {
return this.map.hasOwnProperty(normalizeName(name))
return Object.prototype.hasOwnProperty.call(this.map, normalizeName(name))
}
Headers.prototype.set = function(name, value) {
......@@ -125,7 +126,7 @@ Headers.prototype.set = function(name, value) {
Headers.prototype.forEach = function(callback, thisArg) {
for (var name in this.map) {
if (this.map.hasOwnProperty(name)) {
if (Object.prototype.hasOwnProperty.call(this.map, name)) {
callback.call(thisArg, this.map[name], name, this)
}
}
......@@ -225,23 +226,24 @@ function Body() {
semantic of setting Request.bodyUsed in the constructor before
_initBody is called.
*/
// eslint-disable-next-line no-self-assign
this.bodyUsed = this.bodyUsed
this._bodyInit = body
if (!body) {
this._bodyText = ''
} else if (typeof body === 'string') {
this._bodyText = body
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
} else if (support.blob && Object.prototype.isPrototypeOf.call(Blob, body)) {
this._bodyBlob = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
} else if (support.formData && Object.prototype.isPrototypeOf.call(FormData, body)) {
this._bodyFormData = body
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
} else if (support.searchParams && Object.prototype.isPrototypeOf.call(URLSearchParams, body)) {
this._bodyText = body.toString()
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
this._bodyArrayBuffer = bufferClone(body.buffer)
// IE 10-11 can't handle a DataView body.
this._bodyInit = new Blob([this._bodyArrayBuffer])
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
} else if (support.arrayBuffer && (Object.prototype.isPrototypeOf.call(ArrayBuffer, body) || isArrayBufferView(body))) {
this._bodyArrayBuffer = bufferClone(body)
} else {
this._bodyText = body = Object.prototype.toString.call(body)
......@@ -252,7 +254,7 @@ function Body() {
this.headers.set('content-type', 'text/plain;charset=UTF-8')
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type)
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
} else if (support.searchParams && Object.prototype.isPrototypeOf.call(URLSearchParams, body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
}
}
......@@ -336,7 +338,8 @@ function normalizeMethod(method) {
return methods.indexOf(upcased) > -1 ? upcased : method
}
export function Request(input, options) {
// eslint-disable-next-line no-redeclare
function Request(input, options) {
if (!(this instanceof Request)) {
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
}
......@@ -449,7 +452,8 @@ function parseHeaders(rawHeaders) {
Body.call(Request.prototype)
export function Response(bodyInit, options) {
// eslint-disable-next-line no-redeclare
function Response(bodyInit, options) {
if (!(this instanceof Response)) {
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
}
......@@ -493,10 +497,12 @@ Response.redirect = function(url, status) {
return new Response(null, {status: status, headers: {location: url}})
}
export var DOMException = global.DOMException
// eslint-disable-next-line no-redeclare
var DOMException = global.DOMException
try {
new DOMException()
} catch (err) {
// eslint-disable-next-line no-global-assign
DOMException = function(message, name) {
this.message = message
this.name = name
......@@ -507,7 +513,8 @@ try {
DOMException.prototype.constructor = DOMException
}
export function fetch(input, init) {
// eslint-disable-next-line no-redeclare
function fetch(input, init) {
return new Promise(function(resolve, reject) {
var request = new Request(input, init)
......
/* @flow strict */
type CredentialsType = 'omit' | 'same-origin' | 'include'
type ResponseType = 'default' | 'error'
type BodyInit = string | URLSearchParams | FormData | Blob | ArrayBuffer | $ArrayBufferView
type RequestInfo = Request | URL | string
type RequestOptions = {|
body?: ?BodyInit;
credentials?: CredentialsType;
headers?: HeadersInit;
method?: string;
mode?: string;
referrer?: string;
signal?: ?AbortSignal;
|}
type ResponseOptions = {|
status?: number;
statusText?: string;
headers?: HeadersInit;
|}
type HeadersInit = Headers | {[string]: string}
// https://github.com/facebook/flow/blob/f68b89a5012bd995ab3509e7a41b7325045c4045/lib/bom.js#L902-L914
declare class Headers {
@@iterator(): Iterator<[string, string]>;
constructor(init?: HeadersInit): void;
append(name: string, value: string): void;
delete(name: string): void;
entries(): Iterator<[string, string]>;
forEach((value: string, name: string, headers: Headers) => any, thisArg?: any): void;
get(name: string): null | string;
has(name: string): boolean;
keys(): Iterator<string>;
set(name: string, value: string): void;
values(): Iterator<string>;
}
// https://github.com/facebook/flow/pull/6548
interface AbortSignal {
aborted: boolean;
addEventListener(type: string, listener: (Event) => mixed, options?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: string, listener: (Event) => mixed, options?: EventListenerOptionsOrUseCapture): void;
}
// https://github.com/facebook/flow/blob/f68b89a5012bd995ab3509e7a41b7325045c4045/lib/bom.js#L994-L1018
// unsupported in polyfill:
// - cache
// - integrity
// - redirect
// - referrerPolicy
declare class Request {
constructor(input: RequestInfo, init?: RequestOptions): void;
clone(): Request;
url: string;
credentials: CredentialsType;
headers: Headers;
method: string;
mode: ModeType;
referrer: string;
signal: ?AbortSignal;
// Body methods and attributes
bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
json(): Promise<any>;
text(): Promise<string>;
}
// https://github.com/facebook/flow/blob/f68b89a5012bd995ab3509e7a41b7325045c4045/lib/bom.js#L968-L992
// unsupported in polyfill:
// - body
// - redirected
// - trailer
declare class Response {
constructor(input?: ?BodyInit, init?: ResponseOptions): void;
clone(): Response;
static error(): Response;
static redirect(url: string, status?: number): Response;
type: ResponseType;
url: string;
ok: boolean;
status: number;
statusText: string;
headers: Headers;
// Body methods and attributes
bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
json(): Promise<any>;
text(): Promise<string>;
}
declare class DOMException extends Error {
constructor(message?: string, name?: string): void;
}
declare module.exports: {
fetch(input: RequestInfo, init?: RequestOptions): Promise<Response>;
Headers: typeof Headers;
Request: typeof Request;
Response: typeof Response;
DOMException: typeof DOMException;
}
......@@ -2,40 +2,33 @@
"name": "whatwg-fetch",
"description": "A window.fetch polyfill.",
"version": "3.6.2",
"main": "./dist/fetch.umd.js",
"main": "./fetch.js",
"module": "./fetch.js",
"repository": "github/fetch",
"license": "MIT",
"devDependencies": {
"abortcontroller-polyfill": "^1.1.9",
"chai": "^4.1.2",
"eslint": "^7.20.0",
"eslint-plugin-github": "^4.1.1",
"karma": "^3.0.0",
"abortcontroller-polyfill": "^1.7.5",
"chai": "^4.3.7",
"eslint": "^8.45.0",
"karma": "^6.4.2",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-detect-browsers": "^2.3.2",
"karma-firefox-launcher": "^1.1.0",
"karma-mocha": "^1.3.0",
"karma-chrome-launcher": "^3.2.0",
"karma-detect-browsers": "^2.3.3",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-safari-launcher": "^1.0.0",
"karma-safaritechpreview-launcher": "0.0.6",
"mocha": "^4.0.1",
"prettier": "^1.19.1",
"promise-polyfill": "6.0.2",
"rollup": "^0.59.1",
"karma-safaritechpreview-launcher": "2.0.2",
"mocha": "^10.2.0",
"promise-polyfill": "8.3.0",
"url-search-params": "0.6.1"
},
"files": [
"LICENSE",
"dist/fetch.umd.js",
"dist/fetch.umd.js.flow",
"fetch.js",
"fetch.js.flow"
"fetch.js"
],
"scripts": {
"karma": "karma start ./test/karma.config.js --no-single-run --auto-watch",
"prepare": "make dist/fetch.umd.js dist/fetch.umd.js.flow",
"pretest": "make",
"lint": "eslint .",
"test": "karma start ./test/karma.config.js && karma start ./test/karma-worker.config.js"
}
}
module.exports = require('eslint-plugin-github/prettier.config')
export default {
input: 'fetch.js',
output: {
file: 'dist/fetch.umd.js',
format: 'umd',
name: 'WHATWGFetch'
}
}
// eslint-disable-next-line no-undef
const parentConfig = require('./karma.config')
// eslint-disable-next-line no-undef
module.exports = function(config) {
parentConfig(config)
config.set({
......
/* eslint-env node */
const serverEndpoints = require('./server')
module.exports = function(config) {
......
/* eslint-env node */
const url = require('url')
const querystring = require('querystring')
......@@ -121,14 +122,14 @@ const routes = {
})
res.end()
},
'/invalid-headers': function(res) {
res.writeHead(200, {
'Content-Type': 'text/plain',
'Invalid Header': 'valid value',
'Westworld-S01': "<3"
})
res.end()
}
// '/invalid-headers': function(res) {
// res.writeHead(200, {
// 'Content-Type': 'text/plain',
// 'Invalid Header': 'valid value',
// 'Westworld-S01': "<3"
// })
// res.end()
// }
}
module.exports = function(req, res, next) {
......
此差异已折叠。
/* eslint-env mocha */
/* globals Mocha */
var mochaRun = mocha.run
mocha.run = function() {}
......
/* eslint-env worker */
/* globals mocha chai */
importScripts('/base/node_modules/mocha/mocha.js')
importScripts('/base/node_modules/chai/chai.js')
......@@ -5,7 +7,7 @@ mocha.setup('tdd')
self.assert = chai.assert
importScripts('/base/node_modules/abortcontroller-polyfill/dist/abortcontroller-polyfill-only.js')
importScripts('/base/dist/fetch.umd.js')
importScripts('/base/fetch.js')
importScripts('/base/test/test.js')
function title(test) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册