Giter VIP home page Giter VIP logo

url-search-params's Introduction

url-search-params

build status CDNJS version donate

Deprecated

This polyfill has been improved, better tested, and moved under the ungap umbrella.

The new version is available as @ungap/url-search-params.


This is a polyfill for the URLSearchParams API.

It is possible to simply include build/url-search-params.js or grab it via npm.

npm install url-search-params

The function is exported directly.

var URLSearchParams = require('url-search-params');

MIT Style License

iOS 10 + other platforms bug

In case you'd like to replace the broken global native constructor, you can check some well known issue before including this polyfill on your project/page.

<script>
try { if (new URLSearchParams('q=%2B').get('q') !== '+') throw {}; }
catch (error) {
  window.URLSearchParams = void 0;
  document.write('<script src="/js/url-search-params.js"><'+'/script>');
}
</script>

About HTMLAnchorElement.prototype.searchParams

This property is already implemented in Firefox and polyfilled here only for browsers that exposes getters and setters through the HTMLAnchorElement.prototype.

In order to know if such property is supported, you must do the check as such:

if ('searchParams' in HTMLAnchorElement.prototype) {
  // polyfill for <a> links supported
}

If you do this check instead:

if (HTMLAnchorElement.prototype.searchParams) {
  // throws a TypeError
}

this polyfill will reflect native behavior, throwing a type error due access to a property in a non instance of HTMLAnchorElement.

Nothing new to learn here, just a reminder.

url-search-params's People

Contributors

anthony-redfox avatar dartess avatar daxlab avatar dgraham avatar extend1994 avatar jimmywarting avatar meltuhamy avatar mislav avatar mrjeffry avatar simevidas avatar webreflection avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

url-search-params's Issues

Unfortunally "delete" is a reserved word for older browser (eg. Safari 5.0.3)

If you want to use this polyfill on older browsers we need to change the way to access at some properties that are reserved word, unfortunately.

I fixed it on my local branch, so I will propose a pull request on this issue.

Eg.
on modern browser = a.delete
on older browser (eg. Safari 5.0.3) = a['delete']

Create a bower package

Would be nice to register this in the bower registry so we could bower install --save url-search-params. As far as I'm aware that package name is still available.

window variable

If use webpack entry built, it does not write variables on the window?

Option not to fall back to browser version?

On versions of Firefox from 29 to 43, there is partial support for URLSearchParams, but not complete support. The result for us is that when using this polyfill our site works on Firefox 28 and before, and 44 and after, but not on the versions in between, due to the fact that the library falls back to the browser version if it exists. For these cases, it would be nice to have a way to import this and override the browser implementation, rather than falling back.

https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams#Browser_compatibility

how i can build this

Hi. I found a flaw in your project. I was able to fix it, but I can not build the project on my computer. What do I need to do before sending the PR?

Sorry for my bad english.

.searchParams property

Firefox also implements a .searchParams property on anchors; demo. Maybe you can polyfill that via a HTMLAnchorElement.prototype.searchParams getter.

Btw, I wasnโ€™t able to find in the URL spec where it says that anchors implement that API.

Polyfill problem in Edge 41.16299.371.0

In Edge 41.16299.371.0, the polyfill seems to not create the global URLSearchParams object.

"URLSearchParams is not defined"

In Edge 42.17134.1.0 the problem does not occur.

Required files for running on browser

Hi
I am a member of CDNJS and in charge of adding this library to our CDN.
Could you please tell me which files do we need to let the library run on browser well?
Is url-search-params.js enough?
Thanks! ๐Ÿ˜„

URL.prototype.searchParams should be polyfilled

URL.prototype pretty much reflects HTMLAnchorElement.prototype on web platform, so, as a continuation of #1, FF implements not only HTMLAnchorElement.prototype.searchParams but also URL.prototype.searchParams, and I beleive this polyfill should shim it as well.

v0.10.1 exports empty {}

After updating to v0.10.1 I get:

import URLSearchParams from "url-search-params";
console.log(URLSearchParams);
// outputs: {}

Issue with half-supported native implementation

Some browser older versions include basic support for URLSearchParams but lack advanced features such as constructor USVString or init object support.

e.g. in Firefox v52 record as init object is not supported, but there is a native URLSearchParams constructor. This results in the polyfill not being used, but also the native implementation not working as intended.

URLSearchParams is not a constructor

Hi guys, unfortunately our shop (https://www.mytoys.de/) got an error after the last update 1 hour ago.

it seems that your last commit
14631ef#diff-b9cfc7f2cdf78a7f4b91a753d10865a2

results in an error that the constructor is not found, in our case it was like this

var URLSearchParams = require('url-search-params');
module.exports = {
var currentQuery = new URLSearchParams(window.location.search.length > 0 ? window.location.search.substr(1) : '');

JS-ERROR in Browser console: URLSearchParams is not a constructor

I think you couldn't see the side effects of your commit in package.json, but hopefully our feedback can help you to fix the bug in latest version 0.10.1

Greetings from Berlin

`URLSearchParams` isn't able to handle `FormData` object as input parameter

The native implementation of URLSearchParams is able to consume a FormData object as a constructor parameter, like:

const formData = new FormData();
formData.append('some-key', 'some-value');
const body = new URLSearchParamsConstructor(formData).toString();

I suggest doing a type check. And use FormData as it is supported.

const formDataToObject = (formData) => {
  const object = {};
  formData.forEach((value, key) => {
    object[key] = value;
  });
  return object;
};

function URLSearchParams(query) {
  if (typeof FormData !== 'undefined' && FormData.prototype.forEach) {
    if (query === instanceOf(FormData)) {
      formData = formDataToObject(formData)
    }
  }
 // etc

ES6 import?

Is there a way to do this via an ES6 import? e.g.

import 'url-search-params'
// Expect window.URLSearchParams to exist

umd support

Are we plan support umd?
and support webpack and babel?
seems we should add module field in package.json.

main file for bower package

after installing bower package, my build tool will include main file automatically, which is "build/url-search-params.node.js". however an error is thrown in browser:
Uncaught ReferenceError: module is not defined

main file for browser should be "build/url-search-params.js"

extending URL proto will fail in general

Typically fails on safari/webkit.
You will have much better luck replacing window.URL by a custom URL that inherits and overrides
the native URL implementation.

importing doesn't work anymore

When importing as
import URLSearchParams from 'url-search-params'
and using it further in the code as
const urlParams = new URLSearchParams(window.location.search)
I get the following error:
TypeError: _urlSearchParams2.default is not a constructor
This started after the version update from 0.10.0 -> 0.10.1

%2B parsed to space unexpected on iOS 10.3

new URLSearchParams('q=%2B').get('q') should return +(iOS 11 or Chrome or else), but it returns space ( ) on iOS Safari 10.3. It caused a bug on my project.

iOS Safari 10.3 support URLSearchParams however with this bug. I know it's not url-search-params' issue but it is a issue when i'm using URLSearchParams.

I resolved this by add string replace with + after I get q (see above). It's tricky.

Any idea to resolve this issue gracefully?

Thanks.

support for phantomjs

Hi,

I can t get it working in phantomjs.

It appears URL.prototype.search is not set, so at that line, the test won t jump in and the upgrade won t occur.

I m a bit loss in this prototype thing upgrade. Can you suggest something ?

thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.