url-search-params-polyfill
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -125,3 +125,4 @@ /** | ||
*/ | ||
self.URLSearchParams = (nativeURLSearchParams && !isSupportObjectConstructor) ? | ||
self.URLSearchParams = (nativeURLSearchParams && !isSupportObjectConstructor && self.Proxy) ? | ||
// Safari 10.0 doesn't support Proxy, so it won't extend URLSearchParams on safari 10.0 | ||
new Proxy(nativeURLSearchParams, { | ||
@@ -128,0 +129,0 @@ construct: function(target, args) { |
{ | ||
"name": "url-search-params-polyfill", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "a simple polyfill for javascript URLSearchParams", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/jerrybendy/url-search-params-polyfill", |
@@ -7,3 +7,3 @@ # URLSearchParams polyfill [![](https://img.shields.io/npm/v/url-search-params-polyfill.svg)](https://www.npmjs.com/package/url-search-params-polyfill) | ||
Some browsers have native URLSearchParams class support, but not full. The new `2.x` version will detect if browsers have full feature support and extend it ([#9](https://github.com/jerrybendy/url-search-params-polyfill/pull/9)). | ||
Some browsers have native URLSearchParams class support, but not full. The new `2.x` version detects if browsers have full feature support and extends it. | ||
@@ -43,3 +43,3 @@ ## Installation | ||
```javascript | ||
// new a empty object | ||
// new an empty object | ||
var search1 = new URLSearchParams (); | ||
@@ -139,7 +139,34 @@ | ||
for (var item of search) { | ||
console.log('key: ' + item[0] + ', ' + 'value: ' + item[1]; | ||
console.log('key: ' + item[0] + ', ' + 'value: ' + item[1]); | ||
} | ||
``` | ||
## Known Issues | ||
#### Use with fetch ([#18](https://github.com/jerrybendy/url-search-params-polyfill/issues/18)) | ||
Via [fetch spec](https://fetch.spec.whatwg.org/#body-mixin), when passing an `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 but no `URLSearchParams` have no this behavior. | ||
Via the data of [caniuse](https://caniuse.com/#search=fetch), there are many browsers support `fetch` but `URLSearchParams`. They are: | ||
| Edge | Chrome | Opera | Sumsung Internet | QQ | 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, like below (just an example): | ||
```js | ||
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 | ||
}); | ||
} | ||
``` | ||
## LICENSE | ||
@@ -146,0 +173,0 @@ |
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
25298
625
174
7