Skip to content
This repository was archived by the owner on Sep 5, 2022. It is now read-only.
This repository was archived by the owner on Sep 5, 2022. It is now read-only.

Add urlEncode utility #31

@hdodov

Description

@hdodov

It can be handy to have a function like this:

function urlEncode(data: object) {
	let fields = [];

	for (let key in data) {
		let value = data[key];

		if (value && typeof value === "object") {
			value = JSON.stringify(value);
		}

		let encodedKey = encodeURIComponent(key);
		let encodedValue = encodeURIComponent(value);

		fields.push(encodedKey + "=" + encodedValue);
	}

	return fields.join("&");
}

...when dealing with application/x-www-form-urlencoded forms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions