Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Fetch | 25,788 | 250,591 | 9,175 | 2 days ago | 37 | September 11, 2023 | 4 | mit | JavaScript | |
A window.fetch JavaScript polyfill. | ||||||||||
Isomorphic Fetch | 6,936 | 185,206 | 7,887 | 9 months ago | 23 | September 23, 2020 | 54 | mit | JavaScript | |
Isomorphic WHATWG Fetch API, for Node & Browserify | ||||||||||
Unfetch | 5,560 | 2,467 | 1,570 | 7 months ago | 10 | January 03, 2023 | 23 | mit | JavaScript | |
🐕 Bare minimum 500b fetch polyfill. | ||||||||||
Form To Google Sheets | 3,719 | 4 months ago | 53 | apache-2.0 | JavaScript | |||||
Store HTML form submissions in Google Sheets. | ||||||||||
Cross Fetch | 1,587 | 14,308 | 5,492 | 4 months ago | 49 | July 03, 2023 | 10 | mit | JavaScript | |
Universal WHATWG Fetch API for Node, Browsers and React Native. | ||||||||||
React Ie8 | 988 | 2 | 5 years ago | 7 | January 06, 2016 | 21 | ||||
Make your React app work in IE8 | ||||||||||
Fetch Jsonp | 981 | 1,400 | 993 | 5 months ago | 19 | July 06, 2023 | JavaScript | |||
Make JSONP request like window.fetch | ||||||||||
Svgxuse | 744 | 173 | 71 | a year ago | 26 | October 25, 2017 | 13 | mit | JavaScript | |
A simple polyfill that fetches external SVGs referenced in use elements when the browser itself fails to do so. Demo: https://icomoon.io/svgxuse-demo/ | ||||||||||
Url Search Params Polyfill | 586 | 540 | 384 | 3 months ago | 28 | September 05, 2023 | 5 | mit | JavaScript | |
a simple polyfill for javascript URLSearchParams | ||||||||||
Abortcontroller Polyfill | 313 | 1,408 | 394 | 9 months ago | 40 | October 08, 2022 | 12 | mit | JavaScript | |
Polyfill for the AbortController DOM API and abortable fetch (stub that calls catch, doesn't actually abort request). |
This is a polyfill library for JavaScript's URLSearchParams
class.
URLSearchParams
and extend itThis can also be installed with npm
.
$ npm install url-search-params-polyfill --save
For Babel and ES2015+, make sure to import the file:
import 'url-search-params-polyfill';
For ES5:
require('url-search-params-polyfill');
For browser, copy the index.js
file to your project, and add a script
tag in your html:
<script src="index.js"></script>
Use URLSearchParams
directly. You can instantiate a new instance of URLSearchParams
from a string or an object.
// new an empty object
var search1 = new URLSearchParams();
// from a string
var search2 = new URLSearchParams("id=1&from=home");
// from an object
var search3 = new URLSearchParams({ id: 1, from: "home" });
// from location.search, will remove first "?" automatically
var search4 = new URLSearchParams(window.location.search);
// from anther URLSearchParams object
var search5 = new URLSearchParams(search2);
// from a sequence
var search6 = new URLSearchParams([["foo", 1], ["bar", 2]]);
var search = new URLSearchParams();
search.append("id", 1);
search.delete("id");
search.get("id");
search.getAll("id");
search.has("id");
search.set("id", 2);
search.toString();
search.sort();
search.forEach(function (item) {
console.log(item);
});
for (var key of search.keys()) {
console.log(key);
}
for (var value of search.values()) {
console.log(value);
}
for (var item of search) {
console.log('key: ' + item[0] + ', ' + 'value: ' + item[1]);
}
console.log(search.size)
Via fetch spec, when passing a URLSearchParams
object as a request body, the request should add a header with Content-Type: application/x-www-form-urlencoded; charset=UTF-8
, but browsers which have fetch
support and not URLSearchParams
support do not have this behavior.
Via the data of caniuse, there are many browsers which support fetch
but not URLSearchParams
:
Edge | Chrome | Opera | Samsung Internet | Baidu | |
---|---|---|---|---|---|
14 - 16 | 40 - 48 | 27 - 35 | 4 | 1.2 | 7.12 |
If you want to be compatible with these browsers, you should add a Content-Type
header manually:
function myFetch(url, { headers = {}, body }) {
headers = headers instanceof Headers ? headers : new Headers(headers);
if (body instanceof URLSearchParams) {
headers.set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
}
fetch(url, {
headers,
body
});
}
MIT license