ljharb/qs

Is there an option to prevent value of the same key being populating into an array?

Open

#259 建立於 2018年5月13日

在 GitHub 查看
 (10 留言) (6 反應) (0 負責人)JavaScript (8,015 star) (744 fork)batch import
feature requesthelp wantedparse

描述

Hi there,

I'm trying to figure out if qs.parse allow us to update the query key value instead of collecting those as an array from the doc, but I can not find anything about that so I'm asking here.

By default,

qs.parse('?num=1&num=2') === { num: ['1', '2'] };

Instead, I just care about the last value assigned to num in the query. i.e.

qs.parse('?num=1&num=2', { some_option: true }) === { num: '2' };

Is there a some_option to do so?

I'm working on an API and want a consistent way to handle the value. It is annoying to check if the query value is an array for a given key every single time (and it can be an object sometimes)... and at this point I decided to ignore all other value but the latest bound to the key.

But I guess people may also want only the first key value is preserved?! (e.g. that is how StarkOverflow handled their duplicated query key.)

Thanks!

貢獻者指南