Gathering detailed insights and metrics for url-search-params-polyfill
Gathering detailed insights and metrics for url-search-params-polyfill
Gathering detailed insights and metrics for url-search-params-polyfill
Gathering detailed insights and metrics for url-search-params-polyfill
a simple polyfill for javascript URLSearchParams
npm install url-search-params-polyfill
99.9
Supply Chain
100
Quality
76
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
599 Stars
72 Commits
89 Forks
9 Watching
1 Branches
14 Contributors
Updated on 21 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-21.2%
76,754
Compared to previous day
Last week
-5.7%
479,280
Compared to previous week
Last month
9.3%
2,116,746
Compared to previous month
Last year
-0.7%
23,820,817
Compared to previous year
This is a polyfill library for JavaScript's URLSearchParams
class.
URLSearchParams
and extend itThis can also be installed with npm
.
1$ npm install url-search-params-polyfill --save
For Babel and ES2015+, make sure to import the file:
1import 'url-search-params-polyfill';
For ES5:
1require('url-search-params-polyfill');
For browser, copy the index.js
file to your project, and add a script
tag in your html:
1<script src="index.js"></script>
Use URLSearchParams
directly. You can instantiate a new instance of URLSearchParams
from a string or an object.
1// new an empty object 2var search1 = new URLSearchParams(); 3 4// from a string 5var search2 = new URLSearchParams("id=1&from=home"); 6 7// from an object 8var search3 = new URLSearchParams({ id: 1, from: "home" }); 9 10// from location.search, will remove first "?" automatically 11var search4 = new URLSearchParams(window.location.search); 12 13// from anther URLSearchParams object 14var search5 = new URLSearchParams(search2); 15 16// from a sequence 17var search6 = new URLSearchParams([["foo", 1], ["bar", 2]]);
1var search = new URLSearchParams(); 2 3search.append("id", 1);
1search.delete("id");
1search.get("id");
1search.getAll("id");
1search.has("id");
1search.set("id", 2);
1search.toString();
1search.sort();
1search.forEach(function (item) { 2 console.log(item); 3});
1for (var key of search.keys()) { 2 console.log(key); 3}
1for (var value of search.values()) { 2 console.log(value); 3}
1for (var item of search) { 2 console.log('key: ' + item[0] + ', ' + 'value: ' + item[1]); 3}
1console.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:
1function myFetch(url, { headers = {}, body }) { 2 headers = headers instanceof Headers ? headers : new Headers(headers); 3 4 if (body instanceof URLSearchParams) { 5 headers.set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 6 } 7 8 fetch(url, { 9 headers, 10 body 11 }); 12}
MIT license
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 6/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More