@dz-web/http-build-query

0.2.2 • Public • Published

httpBuildQuery()

NPM Version NPM Download License

Generate URL-encoded query string from the object (php's http_build_query() in js).

Installation:

$ npm install http-build-query

Usage:

var httpBuildQuery = require('http-build-query');

// Simple using
var obj = {
    message: 'hello',
    id: '777',
    token: 'x2s7d'
  };

httpBuildQuery(obj); // message=hello&id=777&token=x2s7d

// Example #3 http_build_query() with complex arrays
// from php documentation: http://php.net/manual/en/function.http-build-query.php
var obj2 = {
    user: {
      name: 'Bob Smith',
      age: 47,
      sex: 'M',
      dob: '5/12/1956'
    },
    pastimes: ['golf', 'opera', 'poker', 'rap'],
    children: {
      bobby: {
        age: 12,
        sex: 'M'
      },
      sally: {
        age: 8,
        sex: 'F'
      }
    },
    '+0': 'CEO'
  };

httpBuildQuery(obj2, 'flags_'); 

Readme

Keywords

Package Sidebar

Install

npm i @dz-web/http-build-query

Weekly Downloads

1

Version

0.2.2

License

MIT

Unpacked Size

9.16 kB

Total Files

11

Last publish

Collaborators

  • webpatch
  • moonlit