0a70bbb1f99f6ebc0dd68b786e4e17a54f2874ebe1227246f5c6b83cf8a8dba6f46a325d82fbd96a5d65fc754b114eea3c4ee728dc6ecb8872ec0af8f0b161 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # querystringify
  2. [![Version npm](http://img.shields.io/npm/v/querystringify.svg?style=flat-square)](https://www.npmjs.com/package/querystringify)[![Build Status](http://img.shields.io/travis/unshiftio/querystringify/master.svg?style=flat-square)](https://travis-ci.org/unshiftio/querystringify)[![Dependencies](https://img.shields.io/david/unshiftio/querystringify.svg?style=flat-square)](https://david-dm.org/unshiftio/querystringify)[![Coverage Status](http://img.shields.io/coveralls/unshiftio/querystringify/master.svg?style=flat-square)](https://coveralls.io/r/unshiftio/querystringify?branch=master)
  3. A somewhat JSON compatible interface for query string parsing. This query string
  4. parser is dumb, don't expect to much from it as it only wants to parse simple
  5. query strings. If you want to parse complex, multi level and deeply nested
  6. query strings then you should ask your self. WTF am I doing?
  7. ## Installation
  8. This module is released in npm as `querystringify`. It's also compatible with
  9. `browserify` so it can be used on the server as well as on the client. To
  10. install it simply run the following command from your CLI:
  11. ```
  12. npm install --save querystringify
  13. ```
  14. ## Usage
  15. In the following examples we assume that you've already required the library as:
  16. ```js
  17. 'use strict';
  18. var qs = require('querystringify');
  19. ```
  20. ### qs.parse()
  21. The parse method transforms a given query string in to an object. Parameters
  22. without values are set to empty strings. It does not care if your query string
  23. is prefixed with a `?`, a `#`, or not prefixed. It just extracts the parts
  24. between the `=` and `&`:
  25. ```js
  26. qs.parse('?foo=bar'); // { foo: 'bar' }
  27. qs.parse('#foo=bar'); // { foo: 'bar' }
  28. qs.parse('foo=bar'); // { foo: 'bar' }
  29. qs.parse('foo=bar&bar=foo'); // { foo: 'bar', bar: 'foo' }
  30. qs.parse('foo&bar=foo'); // { foo: '', bar: 'foo' }
  31. ```
  32. ### qs.stringify()
  33. This transforms a given object in to a query string. By default we return the
  34. query string without a `?` prefix. If you want to prefix it by default simply
  35. supply `true` as second argument. If it should be prefixed by something else
  36. simply supply a string with the prefix value as second argument:
  37. ```js
  38. qs.stringify({ foo: bar }); // foo=bar
  39. qs.stringify({ foo: bar }, true); // ?foo=bar
  40. qs.stringify({ foo: bar }, '#'); // #foo=bar
  41. qs.stringify({ foo: '' }, '&'); // &foo=
  42. ```
  43. ## License
  44. MIT