feat(browser+lint): prep to make script-tag friendly
This commit is contained in:
parent
b4b55523d2
commit
91977b84e3
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
my_typedefs="$(
|
||||
grep typedef ./index.js | cut -d ' ' -f5
|
||||
)"
|
||||
|
||||
rm -f ./types.js
|
||||
{
|
||||
echo '/**'
|
||||
for my_type in $my_typedefs; do
|
||||
echo " * @typedef {import('./').${my_type}} ${my_type}"
|
||||
done
|
||||
echo ' */'
|
||||
} >> ./types.js
|
|
@ -71,6 +71,6 @@
|
|||
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
},
|
||||
"include": ["index.js", "browser.js", "./types.js", "./local-types.js", "lib/**/*.js", "bin/**/*.js"],
|
||||
"include": ["index.js", "urequest.js", "./types.js", "./local-types.js", "lib/**/*.js", "bin/**/*.js"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* @typedef {import('./types.js').RequestOptions} RequestOptions
|
||||
* @typedef {import('./types.js').Response} Response
|
||||
* @typedef {import('./types.js').Headers} Headers
|
||||
*/
|
|
@ -1,5 +1,13 @@
|
|||
{
|
||||
"name": "@root/request",
|
||||
"version": "1.9.1",
|
||||
"lockfileVersion": 1
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@root/request",
|
||||
"version": "1.9.1",
|
||||
"license": "(MIT OR Apache-2.0)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,22 +4,19 @@
|
|||
"description": "A lightweight, zero-dependency drop-in replacement for request",
|
||||
"main": "index.js",
|
||||
"browser": {
|
||||
"./request.js": "./browser.js"
|
||||
"./request.js": "./urequest.js"
|
||||
},
|
||||
"files": [
|
||||
"browser.js",
|
||||
"jsconfig.json",
|
||||
"lib",
|
||||
"local-types.js",
|
||||
"request.js",
|
||||
"types.js"
|
||||
"urequest.js"
|
||||
],
|
||||
"directories": {
|
||||
"example": "examples"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"prepublish": "./bin/localize-types"
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -4,9 +4,17 @@ var http = require('http');
|
|||
var https = require('https');
|
||||
var url = require('url');
|
||||
var os = require('os');
|
||||
//@ts-ignore
|
||||
var pkg = require('./package.json');
|
||||
var fs = require('fs'); // only for streams
|
||||
|
||||
/**
|
||||
* @typedef {import('./').Request} Request
|
||||
* @typedef {import('./').RequestOptions} RequestOptions
|
||||
* @typedef {import('./').Response} Response
|
||||
* @typedef {import('./').Headers} Headers
|
||||
*/
|
||||
|
||||
var _defaults = {
|
||||
sendImmediately: true,
|
||||
method: '',
|
||||
|
|
5
types.js
5
types.js
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* @typedef {import('./').RequestOptions} RequestOptions
|
||||
* @typedef {import('./').Response} Response
|
||||
* @typedef {import('./').Headers} Headers
|
||||
*/
|
|
@ -1,5 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* @typedef {import('./').Request} Request
|
||||
* @typedef {import('./').RequestOptions} RequestOptions
|
||||
* @typedef {import('./').Response} Response
|
||||
* @typedef {import('./').Headers} Headers
|
||||
*/
|
||||
|
||||
// `fetch` will be available for node and browsers as a global
|
||||
//var fetch = window.fetch;
|
||||
|
||||
|
@ -31,8 +38,15 @@ let _optionKeys = Object.keys(_fetchDefaults).concat([
|
|||
//'userAgent' // not allowed, non-standard for request.js
|
||||
]);
|
||||
|
||||
/**
|
||||
* @returns {Request>}
|
||||
*/
|
||||
function setDefaults(_defs) {
|
||||
return async function request(opts) {
|
||||
/**
|
||||
* @param {RequestOptions} opts
|
||||
* @returns {Promise<Response>}
|
||||
**/
|
||||
async function request(opts) {
|
||||
if ('string' === typeof opts) {
|
||||
opts = { url: opts };
|
||||
}
|
||||
|
@ -150,7 +164,9 @@ function setDefaults(_defs) {
|
|||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,7 +211,13 @@ function unicodeToBase64(utf8) {
|
|||
}
|
||||
|
||||
let defaultRequest = setDefaults({ mode: 'cors' });
|
||||
exports.request = defaultRequest;
|
||||
exports.defaults = setDefaults;
|
||||
module.exports = defaultRequest;
|
||||
module.exports.defaults = setDefaults;
|
||||
//@ts-ignore
|
||||
exports.urequest = defaultRequest;
|
||||
//@ts-ignore
|
||||
exports.urequest.defaults = setDefaults;
|
||||
|
||||
// for backwards compat
|
||||
if ('undefined' !== typeof module) {
|
||||
module.exports = defaultRequest;
|
||||
module.exports.defaults = setDefaults;
|
||||
}
|
Loading…
Reference in New Issue