php-qs

brc-dd
esm cjs
php-qs JS library on GitHub php-qs JS library on npm Download php-qs JS library

PHP Query String Parser and Builder

Version 0.1.2 License MIT Vulnerabilities 0
php-qs has no homepage
php-qs JS library on GitHub
php-qs JS library on npm
Download php-qs JS library
Keywords
phpqueryparamsqsparse_strhttp_build_query
<script type="module"> import phpQs from 'https://cdn.jsdelivr.net/npm/php-qs@0.1.2/+esm' </script>
Learn more

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