Giter Site home page Giter Site logo

querystring's Introduction

##querystring Build Status

support object or array like php did: ?a[]=1&a[]=2 -> a=[1,2]

###Usage

install in shell

npm install query-string-object

in js file

qs = require('query-string-object')
qs('xx=yy&zz..') // just like what is pass to the native qs.parse
qs.stringify({
  fInt: 1,
  fString: 'string',
  fObject: {
    anobject: {a:1, b:2},
    anything: 'thing'
  },
  fArray: [1,2,"string"]
}) 
// fInt=1&fString=string&fObject[anobject][a]=1&fObject[anobject][b]=2&fObject[anything]=thing&fArray[]=1&fArray[]=2&fArray[]=string

###Tests

npm install
./node_modules/.bin/mocha --reporter tap test.js

###Expects

####a=1&b=2

output

{
  a:1,
  b:2 
}

####a=1&b[]=1&b[]=2&c=3

output

({
  a: 1,
  b: [1, 2],
  c: 3
});

####a=1&b[]=1&c=3

output

({
  a: 1,
  b: [1],
  c: 3
});

####a=1&b[1]=1&c[3]=2&c=3

output

({
  a: 1,
  b: {
    1: 1
  },
  c: {
    3: 2
  }
});

####a=1&b[eric]=dum&c[stive]=jobs&c=3

output
({
  a: 1,
  b: {
    eric: "dum"
  },
  c: {
    stive: "jobs"
  }
});

####a=1&b[eric]=dum&b[stive]=jobs&c=3

output

({
  a: 1,
  b: {
    eric: "dum",
    stive: "jobs"
  },
  c: 3
});

####a=1&b[eric][]=dum&b[stive][]=jobs&b[stive][]=fans&c=3

output

({
  a: 1,
  b: {
    eric: ["dum"],
    stive: ["jobs", "fans"]
  },
  c: 3
});

querystring's People

Contributors

ericdum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.