- if (isObject(init)) {
- iteratorMethod = getIteratorMethod(init);
- if (typeof iteratorMethod === 'function') {
- iterator = iteratorMethod.call(init);
- next = iterator.next;
- while (!(step = next.call(iterator)).done) {
- entryIterator = getIterator(anObject(step.value));
- entryNext = entryIterator.next;
- if (
- (first = entryNext.call(entryIterator)).done ||
- (second = entryNext.call(entryIterator)).done ||
- !entryNext.call(entryIterator).done
- ) throw TypeError('Expected sequence with length 2');
- entries.push({ key: first.value + '', value: second.value + '' });
+ if (isObject(init)) this.parseObject(init);
+ else this.parseQuery(typeof init == 'string' ? charAt(init, 0) === '?' ? stringSlice(init, 1) : init : $toString(init));
+ }
+};
+
+URLSearchParamsState.prototype = {
+ type: URL_SEARCH_PARAMS,
+ bindURL: function (url) {
+ this.url = url;
+ this.update();
+ },
+ parseObject: function (object) {
+ var iteratorMethod = getIteratorMethod(object);
+ var iterator, next, step, entryIterator, entryNext, first, second;
+
+ if (iteratorMethod) {
+ iterator = getIterator(object, iteratorMethod);
+ next = iterator.next;
+ while (!(step = call(next, iterator)).done) {
+ entryIterator = getIterator(anObject(step.value));
+ entryNext = entryIterator.next;
+ if (
+ (first = call(entryNext, entryIterator)).done ||
+ (second = call(entryNext, entryIterator)).done ||
+ !call(entryNext, entryIterator).done
+ ) throw TypeError('Expected sequence with length 2');
+ push(this.entries, { key: $toString(first.value), value: $toString(second.value) });
+ }
+ } else for (var key in object) if (hasOwn(object, key)) {
+ push(this.entries, { key: key, value: $toString(object[key]) });
+ }
+ },
+ parseQuery: function (query) {
+ if (query) {
+ var attributes = split(query, '&');
+ var index = 0;
+ var attribute, entry;
+ while (index < attributes.length) {
+ attribute = attributes[index++];
+ if (attribute.length) {
+ entry = split(attribute, '=');
+ push(this.entries, {
+ key: deserialize(shift(entry)),
+ value: deserialize(join(entry, '='))
+ });