Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
fix: fix a bug about class Query
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Dec 30, 2016
1 parent ed941f6 commit bd1505d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/query.ts
Expand Up @@ -5,29 +5,29 @@
export default class Query {
object: any = {};

constructor(public queryStr: String) {
constructor(public queryStr: String = '') {
this.object = this.toObject(queryStr.replace(/^\?+/, ''));
}

toObject(queryStr: String) {
private toObject(queryStr: String) {
let obj = {};
queryStr.split('&').forEach((item)=> {
let arr = item.split('=') || [];
let key = arr[0] || '';
obj[key] = arr[1] || '';
key && (obj[key] = arr[1] || '');
});
return obj;
}

public toString(): String {
let arr = [];
let arr: string[] = [];
for (let key in this.object) {
if (this.object.hasOwnProperty(key)) {
let value = this.object[key];
arr.push(key + '=' + value);
}
}
return '?' + arr.join('&');
return arr.length ? '?' + arr.join('&') : '';
}

}

0 comments on commit bd1505d

Please sign in to comment.