2.1.1 • Published 6 years ago

queryfetch v2.1.1

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 years ago

queryfetch

Dead simple JS module to parse/serialize HTTP query/params. Useful for Fetch API or AJAX requests.

Instalation

CDN

<script src="https://unpkg.com/queryfetch"></script>

NPM

npm i -S queryfetch

Yarn

yarn add queryfetch

Snipacks

snipacks add unpkg qf.js queryfetch

Usage

ES6

import queryfetch from 'queryfetch'

CommonJS

const queryfetch = require('queryfetch')

AMD

require(['queryfetch'], queryfetch => {
    //code go here
})

Global

If you include with script tag, queryfetch object will be available globally.

Instance

queryfetch is a function that returns a class object constructor.

It needs to receive a source argument which will be used at methods execution.

Examples:

const str = queryfetch('a=1&b=2&c=3'),
	obj = queryfetch({ a: 1, b: 2, c: 3 })

Methods

There are only 3 methods within queryfetch:

str.parse()

It converts a querystring to a literal Object.

const str = queryfetch('a=1&b=2&c=3') // with or without first '?' char

str.parse()   // returns { a: 1, b: 2, c: 3 }

obj.serialize()

Serializes a literal Object to a querystring.

const obj = queryfetch({ a: 1, b: 2, c: 3 })

obj.serialize()   // returns 'a=1&b=2&c=3'

qf.form()

This method is a bonus to build a FormData instance.

It can receive an entry as querystring, literal Object or HTMLFormElement.

let qf = queryfetch(any) // querystring, literal Object or HTMLFormElement

qf.form()   // returns FormData instance with fields/values
2.1.1

6 years ago

2.1.0

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago