[whatwg/url] Convenience method to return an `Object` (#143)

People who write Javascript mostly manipulate key-value data via `Object` instances, using their enumerable properties as keys. See lodash (`_.mapKeys`, support in `_.map` etc), jQuery (`$.ajax({ url: "c2.com", method: "get" })`) etc.

Adding `toObject()` as below would make this feel like a natural part of the JS ecosystem:

```
class URLSearchParams {  
  toObject() {
    const o = {};
    for(const [k,v] of this.values()) o[k] = v;
    return o;
  }
}
```

This'd allow for idiomatic composition with other core JS APIs, matching the pleasant developer experience that people expect:

```
const queries = ["?name=grace","?name=sussman"]

const hackers = queries
  .map(s => new URLSearchParams(s).toObject())
  .map(q => q.name)
```

The alternative is everyone having to add this boiler-plate in their project, which'd be a shame.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/143

Received on Friday, 12 August 2016 14:10:09 UTC