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

Create URLSearchParams from a JavaScript object.

Notifications You must be signed in to change notification settings

travishorn/searchparamify

Repository files navigation

searchparamify

Create URLSearchParams from a JavaScript object.

Installation

Method 1: CDN

Include the script on your page via UNPKG.

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

Method 2: Download

Download dist/searchparamify.js.

Include it on your page.

<script src="searchparamify.js"></script>

Method 3: ES6 Module using npm and webpack (or similar)

Install via npm.

> npm install searchparamify

Include it in your scripts.

import searchparamify from "searchparamify";

Usage

Create URLSearchParams from a JavaScript object.

const params = searchparamify({
  name: "Jimmy",
  favoriteAnimal: "cat"
});

The result of the code above is identical to...

const params = new URLSearchParams();
params.append("name", "Jimmy");
params.append("favoriteAnimal", "cat");

In both cases, params.toString() would return

"name=Jimmy&favoriteAnimal=cat"