Giter Club home page Giter Club logo

query-string's Introduction

query-string


https://github.com/sindresorhus/query-string

npm install query-string
const queryString = require('query-string');
console.log(location.search);

const parsed = queryString.parse(location.search);
console.log(parsed);

console.log(location.hash);

const parsedHash = queryString.parse(location.hash);
console.log(parsedHash);

parsed.foo = 'unicorn';
parsed.ilike = 'pizza';

const stringified = queryString.stringify(parsed);
location.search = stringified;
console.log(location.search);

queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});

queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});

queryString.parse('foo=1&foo=2&foo=3');

queryString.stringfy({foo: [1,2,3]}, {arrayFormat: 'bracket'});
qyeryString.stringify({foo: [1,2,3]}, {arrayFormat: 'index'});
queryString.stringify({foo: [1,2,3]});

const order = ['c', 'a', 'b'];
qyeryString.stringfy({a: 1, b: 2, c: 3}, {
  sort: (m, n) => order.indexOf(m) >= order.indexOf(n)
});
queryString.stringify({ b: 1, c: 2, a: 3}, {sort: false});

queryString.parseUrl('https://foo.bar?foo=bar');

queryString.stringfiry({
  foo: 'bar',
  nested: JSON.stringify({
    unicorn: 'cake'
  })
});

queryString.parse('likes=cake&name=bob&likes=icecream');
queryString.stringify({color: ['taupe', 'chartreuse'], id: '515'});

queryString.stringify({foo: false});
queryString.stringify({foo: null});
queryString.stringify({foo: undefined});
<form action="cgi-bin/test.cgi" method="get">
  <input type="text" name="first" />
  <input type="text" name="second" />
  <input type="submit" />
</from>

<a href="foo.html"></a>
<a href="bar.html"></a>

<a href="foo.html?e0a72cb2a2c7">see my page!</a>
<a href="bar.html?e0a72cb2a2c7">mine is better</a>

query-string's People

Contributors

takagotch avatar

Watchers

James Cloos 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.