`qs library` vs `querystring library`

kim·2022년 3월 6일

When extended property is set to true, the URL-encoded data

On the contrary

when extended property is set to false, the URL-encoded data will instead be parsed with the querystring library.

  • qs library allows you to create a nested object from your query string.
var qs = require("qs")
var result = qs.parse("person[name]=bobby&person[age]=3")
console.log(result) // {person: { name: 'bobby', age: '3'}}
  • query-string library does not support creating a nested object from your query string.
var queryString = require("query-string")
var result = queryString.parse("person[name]=bobby&person[age]=3")
console.log(result) // { 'person[age]': '3', 'person[name]': 'bobby' }
  • qs library will not filter out '?' from the query string.
var qs = require("qs")
var result = qs.parse("?a=b")
console.log(result) // { '?a': 'b' }
  • query-string library will filter out '?' from the query string.
var queryString = require("query-string")
var result = queryString.parse("?a=b")
console.log(result) // { a: 'b' }

Reference
https://stackoverflow.com/questions/29960764/what-does-extended-mean-in-express-4-0/45690436#45690436

0개의 댓글