From 19a6bd8826e7ce1f4a94e9756766dfed4d555807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Wed, 27 Jan 2021 16:46:54 +0900 Subject: [PATCH] feat: added form data function --- utils/Tools.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/utils/Tools.ts b/utils/Tools.ts index 23cb763..3ecc57b 100644 --- a/utils/Tools.ts +++ b/utils/Tools.ts @@ -33,7 +33,7 @@ export function supportsWebP() { return false } -export function checkBrowser(){ +export function checkBrowser() { const ua = navigator.userAgent let tem let M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+(\.\d+)?(\.\d+)?)/i) || [] @@ -54,7 +54,18 @@ export function generateOauthURL(provider: 'discord', clientID: string, scope: s return Oauth[provider](clientID, scope) } -export default function bufferToStream(binary: Buffer) { +export function formData(details: { [key: string]: string | number | boolean }) { + const formBody = [] + for (const property in details) { + const encodedKey = encodeURIComponent(property) + const encodedValue = encodeURIComponent(details[property]) + formBody.push(encodedKey + '=' + encodedValue) + } + return formBody.join('&') + +} + +export function bufferToStream(binary: Buffer) { const readableInstanceStream = new Readable({ read() { @@ -66,5 +77,4 @@ export default function bufferToStream(binary: Buffer) { return readableInstanceStream } - export { anchorHeader } from './ShowdownExtensions' \ No newline at end of file