Skip to content

Commit 47f1d28

Browse files
committed
feat: modern rewrite and refactoring
1 parent 076e55a commit 47f1d28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+20374
-4549
lines changed

.browserslistrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Browsers that we support
2+
3+
> 1%
4+
last 2 versions
5+
ie 9

.dist.babelrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
["@babel/env", {
4+
"targets": {
5+
"browsers": [ "> 1%", "last 2 versions", "ie 9" ]
6+
}
7+
}]
8+
],
9+
"plugins": [ "@babel/transform-runtime" ]
10+
}

.dist.eslintrc

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"extends": ["eslint:recommended"],
3+
"env": {
4+
"node": true,
5+
"browser": true,
6+
"amd": true,
7+
"es6": true
8+
},
9+
"plugins": ["compat"],
10+
"rules": {
11+
"compat/compat": "error",
12+
"no-console": "off",
13+
"no-empty": "off",
14+
"no-extra-semi": "off",
15+
"no-func-assign": "off",
16+
"no-undef": "off",
17+
"no-unused-vars": "off",
18+
"no-useless-escape": "off",
19+
"no-cond-assign": "off"
20+
},
21+
"globals": {
22+
"regeneratorRuntime": "writable"
23+
},
24+
"settings": {
25+
"polyfills": [
26+
"Promise",
27+
"Array.from",
28+
"Symbol",
29+
"Object.getOwnPropertySymbols",
30+
"Object.setPrototypeOf"
31+
]
32+
}
33+
}

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ components
99
test/node/fixtures/tmp.json
1010
.idea
1111
superagent.js
12-
package-lock.json
12+
package-lock.json
13+
*.log
14+
coverage
15+
.nyc_output
16+
lib
17+
dist

.lib.babelrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["@babel/env", {
4+
"targets": {
5+
"node": "6.4.0"
6+
}
7+
}]
8+
]
9+
}

.lib.eslintrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["eslint:recommended", "plugin:node/recommended"],
3+
"rules": {
4+
"node/no-deprecated-api": "off",
5+
"no-console": "off",
6+
"no-unused-vars": "off",
7+
"no-empty": "off"
8+
},
9+
"overrides": [
10+
{
11+
"files": [ "lib/client.js" ],
12+
"env": { "browser": true },
13+
"globals": {
14+
"ActiveXObject": "readable"
15+
}
16+
}
17+
]
18+
}

.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ examples
55
lib-cov
66
coverage.html
77
bower.json
8+
coverage
9+
src
10+
.travis.yml
11+
.nojekyll
12+
.nyc_output

.remarkignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONTRIBUTING.md
2+
HISTORY.md
3+
docs

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ node_js:
44
- "10"
55
- "8"
66
- "6"
7-
7+
after_success:
8+
npm run coverage
89
env:
910
global:
1011
- SAUCE_USERNAME='shtylman-superagent'
1112
- SAUCE_ACCESS_KEY='39a45464-cb1d-4b8d-aa1f-83c7c04fa673'
12-
1313
matrix:
1414
include:
1515
- node_js: "9"

.zuul.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ browsers:
1313
browserify:
1414
- transform:
1515
name: babelify
16-
presets:
17-
- [ babel-preset-es2015, { loose: true } ]
16+
configFile: './.dist.babelrc'
File renamed without changes.

History.md renamed to HISTORY.md

File renamed without changes.

README.md

+243
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
# superagent
2+
3+
[![build status](https://img.shields.io/travis/visionmedia/superagent.svg)](https://travis-ci.org/visionmedia/superagent)
4+
[![code coverage](https://img.shields.io/codecov/c/github/visionmedia/superagent.svg)](https://codecov.io/gh/visionmedia/superagent)
5+
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
6+
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
7+
[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)
8+
[![license](https://img.shields.io/github/license/visionmedia/superagent.svg)](LICENSE)
9+
10+
> Small progressive client-side HTTP request library, and Node.js module with the same API, sporting many high-level HTTP client features
11+
12+
13+
## Table of Contents
14+
15+
* [Install](#install)
16+
* [Usage](#usage)
17+
* [Node](#node)
18+
* [Browser](#browser)
19+
* [Supported Platforms](#supported-platforms)
20+
* [Required Browser Features](#required-browser-features)
21+
* [Plugins](#plugins)
22+
* [Upgrading from previous versions](#upgrading-from-previous-versions)
23+
* [Contributors](#contributors)
24+
* [License](#license)
25+
26+
27+
## Install
28+
29+
[npm][]:
30+
31+
```sh
32+
npm install superagent
33+
```
34+
35+
[yarn][]:
36+
37+
```sh
38+
yarn add superagent
39+
```
40+
41+
42+
## Usage
43+
44+
### Node
45+
46+
```js
47+
const superagent = require('superagent');
48+
49+
superagent
50+
.post('/api/pet')
51+
.send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
52+
.set('X-API-Key', 'foobar')
53+
.set('accept', 'json')
54+
.end((err, res) => {
55+
// Calling the end function will send the request
56+
});
57+
```
58+
59+
### Browser
60+
61+
**The browser-ready, minified version of `superagent` is only 19 KB!**
62+
63+
Browser-ready versions of this module are available via [jsdelivr][], [unpkg][], and also in the `node_modules/superagent/dist` folder in downloads of the `superagent` package.
64+
65+
> Note that we also provide unminified versions with `.js` instead of `.min.js` file extensions.
66+
67+
#### VanillaJS
68+
69+
This is the solution for you if you're just using `<script>` tags everywhere!
70+
71+
```html
72+
<script src="https://cdn.jsdelivr.net/npm/superagent"></script>
73+
<!-- if you wish to use unpkg.com instead: -->
74+
<!-- <script src="https://unpkg.com/superagent"></script> -->
75+
<script type="text/javascript">
76+
(function() {
77+
// superagent is exposed as `window.superagent`
78+
// if you wish to use "request" instead please
79+
// uncomment the following line of code:
80+
// `window.request = superagent;`
81+
superagent
82+
.post('/api/pet')
83+
.send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
84+
.set('X-API-Key', 'foobar')
85+
.set('accept', 'json')
86+
.end((err, res) => {
87+
// Calling the end function will send the request
88+
});
89+
})();
90+
</script>
91+
```
92+
93+
#### Bundler
94+
95+
If you are using [browserify][], [webpack][], [rollup][], or another bundler, then you can follow the same usage as [Node](#node) above.
96+
97+
98+
## Supported Platforms
99+
100+
* Node: v6.x+
101+
* Browsers (see [.browserslistrc](.browserslistrc)):
102+
103+
```sh
104+
npx browserslist
105+
```
106+
107+
```sh
108+
and_chr 71
109+
and_ff 64
110+
and_qq 1.2
111+
and_uc 11.8
112+
android 67
113+
android 4.4.3-4.4.4
114+
baidu 7.12
115+
bb 10
116+
bb 7
117+
chrome 73
118+
chrome 72
119+
chrome 71
120+
edge 18
121+
edge 17
122+
firefox 66
123+
firefox 65
124+
ie 11
125+
ie 10
126+
ie 9
127+
ie_mob 11
128+
ie_mob 10
129+
ios_saf 12.0-12.1
130+
ios_saf 11.3-11.4
131+
op_mini all
132+
op_mob 46
133+
op_mob 12.1
134+
opera 58
135+
opera 57
136+
safari 12
137+
safari 11.1
138+
samsung 8.2
139+
samsung 7.2-7.4
140+
```
141+
142+
### Required Browser Features
143+
144+
* IE9 requires a polyfill for `window.FormData` (we recommend [formdata-polyfill][])
145+
146+
147+
## Plugins
148+
149+
SuperAgent is easily extended via plugins.
150+
151+
```js
152+
const nocache = require('superagent-no-cache');
153+
const superagent = require('superagent');
154+
const prefix = require('superagent-prefix')('/static');
155+
156+
superagent
157+
.get('/some-url')
158+
.query({ action: 'edit', city: 'London' }) // query string
159+
.use(prefix) // Prefixes *only* this request
160+
.use(nocache) // Prevents caching of *only* this request
161+
.end((err, res) => {
162+
// Do something
163+
});
164+
```
165+
166+
Existing plugins:
167+
168+
* [superagent-no-cache](https://github.com/johntron/superagent-no-cache) - prevents caching by including Cache-Control header
169+
* [superagent-prefix](https://github.com/johntron/superagent-prefix) - prefixes absolute URLs (useful in test environment)
170+
* [superagent-suffix](https://github.com/timneutkens1/superagent-suffix) - suffix URLs with a given path
171+
* [superagent-mock](https://github.com/M6Web/superagent-mock) - simulate HTTP calls by returning data fixtures based on the requested URL
172+
* [superagent-mocker](https://github.com/shuvalov-anton/superagent-mocker) — simulate REST API
173+
* [superagent-cache](https://github.com/jpodwys/superagent-cache) - A global SuperAgent patch with built-in, flexible caching
174+
* [superagent-cache-plugin](https://github.com/jpodwys/superagent-cache-plugin) - A SuperAgent plugin with built-in, flexible caching
175+
* [superagent-jsonapify](https://github.com/alex94puchades/superagent-jsonapify) - A lightweight [json-api](http://jsonapi.org/format/) client addon for superagent
176+
* [superagent-serializer](https://github.com/zzarcon/superagent-serializer) - Converts server payload into different cases
177+
* [superagent-httpbackend](https://www.npmjs.com/package/superagent-httpbackend) - stub out requests using AngularJS' $httpBackend syntax
178+
* [superagent-throttle](https://github.com/leviwheatcroft/superagent-throttle) - queues and intelligently throttles requests
179+
* [superagent-charset](https://github.com/magicdawn/superagent-charset) - add charset support for node's SuperAgent
180+
* [superagent-verbose-errors](https://github.com/jcoreio/superagent-verbose-errors) - include response body in error messages for failed requests
181+
182+
Please prefix your plugin with `superagent-*` so that it can easily be found by others.
183+
184+
For SuperAgent extensions such as couchdb and oauth visit the [wiki](https://github.com/visionmedia/superagent/wiki).
185+
186+
187+
## Upgrading from previous versions
188+
189+
Our breaking changes are mostly in rarely used functionality and from stricter error handling.
190+
191+
* [4.x to 5.x](https://github.com/visionmedia/superagent/releases/tag/v5.0.0):
192+
* Ensure you're running Node 8.8.1 or later.
193+
* We've implemented the build setup of [Lass](https://lass.js.org) to simplify our stack and linting
194+
* Browserified build size has been reduced from 48KB to 19KB (via `tinyify` and the latest version of Babel using `@babel/preset-env` and `.browserslistrc`)
195+
* Linting support has been added using `caniuse-lite` and `eslint-plugin-compat`
196+
* We can now target what versions of Node we wish to support more easily using `.babelrc`
197+
* [3.x to 4.x](https://github.com/visionmedia/superagent/releases/tag/v4.0.0-alpha.1):
198+
* Ensure you're running Node 6 or later. We've dropped support for Node 4.
199+
* We've started using ES6 and for compatibility with Internet Explorer you may need to use Babel.
200+
* We suggest migrating from `.end()` callbacks to `.then()` or `await`.
201+
* [2.x to 3.x](https://github.com/visionmedia/superagent/releases/tag/v3.0.0):
202+
* Ensure you're running Node 4 or later. We've dropped support for Node 0.x.
203+
* Test code that calls `.send()` multiple times. Invalid calls to `.send()` will now throw instead of sending garbage.
204+
* [1.x to 2.x](https://github.com/visionmedia/superagent/releases/tag/v2.0.0):
205+
* If you use `.parse()` in the _browser_ version, rename it to `.serialize()`.
206+
* If you rely on `undefined` in query-string values being sent literally as the text "undefined", switch to checking for missing value instead. `?key=undefined` is now `?key` (without a value).
207+
* If you use `.then()` in Internet Explorer, ensure that you have a polyfill that adds a global `Promise` object.
208+
* 0.x to 1.x:
209+
* Instead of 1-argument callback `.end(function(res){})` use `.then(res => {})`.
210+
211+
212+
## Contributors
213+
214+
| Name |
215+
| ------------------- |
216+
| **Kornel Lesiński** |
217+
| **Peter Lyons** |
218+
| **Hunter Loftis** |
219+
| **Nick Baugh** |
220+
221+
222+
## License
223+
224+
[MIT](LICENSE) © TJ Holowaychuk
225+
226+
227+
##
228+
229+
[npm]: https://www.npmjs.com/
230+
231+
[yarn]: https://yarnpkg.com/
232+
233+
[formdata-polyfill]: https://www.npmjs.com/package/formdata-polyfill
234+
235+
[jsdelivr]: https://www.jsdelivr.com/
236+
237+
[unpkg]: https://unpkg.com/
238+
239+
[browserify]: https://github.com/browserify/browserify
240+
241+
[webpack]: https://github.com/webpack/webpack
242+
243+
[rollup]: https://github.com/rollup/rollup

0 commit comments

Comments
 (0)