GithubHelp home page GithubHelp logo

joezo / node_perry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marcgreenstock/node_perry

0.0 2.0 0.0 104 KB

Multi-dimensional query string parser and generator

Home Page: http://github.com/marcgreenstock/node_perry

JavaScript 100.00%

node_perry's Introduction

Perry

Multi-dimensional query string parser and generator.

Install:

npm install perry

Require Perry:

var Perry = require('perry');

Perry.stringify usage:

Perry.stringify({
  foo: {
    first: {
      second: {
        third: 'bar'
      },
      another: [23,42]
    }
  }
});

Returned result:

foo[first][second][third]=bar&foo[first][another][0]=23&foo[first][another][1]=42

Perry.parse usage:

Perry.parse('foo[0][bar][0]=meh&foo[0][bar][1]=beh&foo[1][bar][0]=teh');

Returned result:

{
  foo: [{
    bar: ['meh','beh']
  },{
    bar: ['teh']
  }]
}

Perrry.parse a query string with empty braces will create an index array beginning with 0:

Perry.parse('foo[]=bar&foo[]=mah');

Returned result:

{
  foo: ['bar','meh']
}

Perry.parse a query strings with a numerical index will associate an array with identical indexes:

Perry.parse('foo[0]=bar&foo[2]=mah');

Returned result:

{
  foo: ['bar',undefined,'mah]
}

Notice the undefined at index 1, this is to keep the array indexes consistent since foo[1] isn't present in the query string. The alternative would be to create a numerically indexed object which may not be expected behaviour considering an array is expected.

Test:

node test/test-perry.js

node_perry's People

Contributors

shackpank 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.