0.1.2 • Published 7 months ago

php-qs v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

php-qs

A JS library for building and parsing query strings similar to PHP's http_build_query and parse_str functions.

Installation

npm add php-qs

Usage

import { parse, stringify } from 'php-qs'

console.log(stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: null }))
// => foo=bar&baz%5B0%5D=qux&baz%5B1%5D=quux&corge=

console.log(parse('foo=bar&baz%5B0%5D=qux&baz%5B1%5D=quux&corge='))
// => { foo: 'bar', baz: ['qux', 'quux'], corge: null }

Notes

  • Not battle-tested. Use at your own risk.
    • Although, the tests are taken from PHP's source code and are passing.
  • Not 100% compatible with PHP functions. For example,
    • parse might throw errors if the input is not a valid query string.
    • stringify uses RFC 3986, while PHP uses RFC 1738 by default.
    • some differences are there because of what Array means in JS vs PHP.

Credits

Copyright (c) 2007-2016 Kevin van Zonneveld (https://kvz.io)
and Contributors (https://locutus.io/authors)

MIT (https://github.com/locutusjs/locutus/blob/aa2751437a92cc1b33204b5e1252e8ef899206ad/LICENSE)

Sponsors

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago