Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
/ query Public archive

[DEPRECATED] A really small query string parser and builder, that converts from and to JSON, written as a js es6 module.

License

Notifications You must be signed in to change notification settings

marcodpt/query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[DEPRECATED]

This repository contains interesting ideas but has been replaced by wand, a project that carries the good ideas here.

If it is useful to you, fork it and continue development, it is kept here while I have software that depends on this repository.

Query js

An es6 module javascript query string parser and builder

Tests

Motivation

I needed an es6 module query string parser, but it need to be very simple and powerful.

There is only one function and you can transform objects in query string, query string in object, make merges and projections.

Usage

import query from 'https://cdn.jsdelivr.net/gh/marcodpt/query/index.js'

query({a: 5, b: 'dog'})                     //a=5&b=dog
query('a=5&b=dog')                          //{a: '5', b: 'dog'}
query({a: 5, b: 'dog'}, {b: 'cat'})         //{a: 5, b: 'cat'}
query({a: 5, b: 'dog'}, 'a=7&c=x')          //{a: '7', b: 'dog', c: 'x'}
query({a: 5, b: 'dog'}, {b: null})          //{a: 5}
query('a=5&b=dog', {b: 'cat'})              //a=5&b=cat
query('a=5&b=dog', 'a=7&c=x')               //a=7&b=dog&c=x
query('a=5&b=dog', {b: null})               //a=5
query('a=5&b=dog&c=cat&d=4', ['b', 'd'])    //b=dog&d=4
query(
  'a=5&b=dog&c=cat&d=4',
  {d: 3},
  'b=ball',
  ['a', 'b', 'd']
)                                           //a=5&b=ball&d=3
query(
  {a: 5, b: 'dog', c: 'cat', d: 4},
  ['b', 'd']
)                                           //{b: 'dog', d: 4}

query({
  a: {
    b: {
      c: 'ball',
      d: ['john', 'mary']
    }
  }
}) //a.b.c=ball&a.b.d%5B%5D=john&a.b.d%5B%5D=mary

query('a.b.c=ball&a.b.d[]=john&a.b.d%5B%5D=mary')
//{
//  a: {
//    b: {
//      c: 'ball',
//      d: ['john', 'mary']
//    }
//  }
//}

Contributing

Yes please! It is a very simple project with a single file, no guidelines, any contribution is greatly appreciated!