Coder Social home page Coder Social logo

funky-qs's Introduction

qs

Simple querystring parsing and construction.

Parse

The parse function will return an Object of the terms. Any leading '?' or '#' will be removed, so it's safe to use on both location.search and location.hash.

import qs from 'qs';

// Parse the querystring
params = qs.parse(window.location.search)

// Parse the hash
params = qs.parse(window.location.hash)

Any key that appears more than once in the query string will result in a list in the result, with the values in order of discovery.

You can pass in an intial state to be updated:

params = qs.parse(window.location.hash, defaults)

You can also use this to force some values to be always be lists:

params = qs.parse(..., {names: []})

Parsef

Additionally, there's parsef, which will parse a querystring into a FormData instance.

Differences from pares are as follows:

  • key order is retained
  • repeated keys result in repeated entries in the FormData instance.

Encode

Encodes values into a querystring. Can also be used to generate POST data.

Any values which are lists will be handled automatically.

Note: This library does NOT use the idiomatic PHP style of appending [] to fields that have multiple values.

import qs from 'qs'

// results in foo=1&bar=a&bar=b
qstring = qs.encode({foo: 1, bar: ["a", "b"]})

funky-qs's People

Contributors

funkybob avatar

Stargazers

 avatar

Watchers

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