File tree Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> extract</h3>
9696 < li class ="tsd-description ">
9797 < aside class ="tsd-sources ">
9898 < ul >
99- < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6c4b8b6 /index.ts#L91 "> index.ts:91 </ a > </ li >
99+ < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6f594dd /index.ts#L104 "> index.ts:104 </ a > </ li >
100100 </ ul >
101101 </ aside >
102102 < div class ="tsd-comment tsd-typography ">
@@ -130,7 +130,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> parse</h3>
130130 < li class ="tsd-description ">
131131 < aside class ="tsd-sources ">
132132 < ul >
133- < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6c4b8b6 /index.ts#L44 "> index.ts:44</ a > </ li >
133+ < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6f594dd /index.ts#L44 "> index.ts:44</ a > </ li >
134134 </ ul >
135135 </ aside >
136136 < div class ="tsd-comment tsd-typography ">
@@ -164,7 +164,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> stringify</h3>
164164 < li class ="tsd-description ">
165165 < aside class ="tsd-sources ">
166166 < ul >
167- < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6c4b8b6 /index.ts#L12 "> index.ts:12</ a > </ li >
167+ < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6f594dd /index.ts#L12 "> index.ts:12</ a > </ li >
168168 </ ul >
169169 </ aside >
170170 < div class ="tsd-comment tsd-typography ">
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ <h3>prefix</h3>
9595 < div class ="tsd-signature tsd-kind-icon "> prefix< span class ="tsd-signature-symbol "> :</ span > < span class ="tsd-signature-type "> string</ span > </ div >
9696 < aside class ="tsd-sources ">
9797 < ul >
98- < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6c4b8b6 /index.ts#L2 "> index.ts:2</ a > </ li >
98+ < li > Defined in < a href ="https://github.com/marcelorl/query-stringifier/blob/6f594dd /index.ts#L2 "> index.ts:2</ a > </ li >
9999 </ ul >
100100 </ aside >
101101 </ section >
Original file line number Diff line number Diff line change @@ -73,10 +73,23 @@ export const parse = (queryStr: string): object => {
7373 obj [ key ] [ indexOfArray ] = value ;
7474 } else {
7575 obj [ key ] = [ value ] ;
76- }
76+ }
7777 }
7878 } else {
79- obj [ key ] = value ;
79+ // Check if the key is already in the object
80+ if ( Object . keys ( obj ) . indexOf ( key ) > - 1 ) {
81+ if ( Array . isArray ( obj [ key ] ) ) {
82+ obj [ key ] . push ( value ) ;
83+ } else {
84+ let newArray : string [ ] = [ ] ;
85+ newArray . push ( obj [ key ] ) ;
86+ newArray . push ( value ) ;
87+ obj [ key ] = newArray ;
88+ }
89+
90+ } else {
91+ obj [ key ] = value ;
92+ }
8093 }
8194 } ) ;
8295
Original file line number Diff line number Diff line change @@ -64,6 +64,14 @@ describe('query-stringifier', () => {
6464 expect ( parsed ) . to . have . keys ( [ 'arr' ] ) ;
6565 expect ( parsed ) . to . deep . equal ( { arr : [ '2' , '3' , '1' ] } ) ;
6666 } ) ;
67+
68+ it ( 'converts query string with duplicate keys' , ( ) => {
69+ const parsed = qs . parse ( 'itemIds=1&itemIds=2' ) ;
70+
71+ expect ( parsed ) . to . be . an ( 'object' ) ;
72+ expect ( parsed ) . to . have . keys ( [ 'itemIds' ] ) ;
73+ expect ( parsed ) . to . deep . equal ( { itemIds : [ '1' , '2' ] } ) ;
74+ } ) ;
6775 } ) ;
6876
6977 describe ( '#extract' , ( ) => {
You can’t perform that action at this time.
0 commit comments