JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 533304
  • Score
    100M100P100Q188574F
  • License MIT

a simple polyfill for javascript URLSearchParams

Package Exports

  • url-search-params-polyfill
  • url-search-params-polyfill/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (url-search-params-polyfill) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

URLSearchParams polyfill

This is a polyfill library for javascript's URLSearchParams class. This library has implemented all features from MDN document.

Installation

This 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>

Usage

Use URLSearchParams directly. You can new an object from a string or an object.

// new a 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);

append

var search = new URLSearchParams ();

search.append("id", 1);

delete

search.delete("id");

get

search.get("id");

getAll

search.getAll("id");

has

search.has("id");

set

search.set("id", 2);

toString

search.toString();

sort

search.sort();

forEach

search.forEach(function (item) {
  console.log(item);
});

keys

for (var key of search.keys()) {
  console.log(key);
}

values

for (var value of search.values()){
  console.log(value);
}

for...of

for (var item of search) {
  console.log('key: ' + item[0] + ', ' + 'value: ' + item[1];
}

LICENSE

MIT license