Repository: neet/masto.js (ts)

Issue:
Unable to upload media attachments
It appears that uploading media attachments is broken. I get the below error with both my own code and the original example form inside the project.


```
(node:19274) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of null
    at FormData._getContentDisposition (/mnt/dev/bot/node_modules/form-data/lib/form_data.js:226:40)
    at FormData._multiPartHeader (/mnt/dev/bot/node_modules/form-data/lib/form_data.js:177:33)
    at FormData.append (/mnt/dev/bot/node_modules/form-data/lib/form_data.js:70:21)
    at createFormData (/mnt/dev/bot/node_modules/masto/dist/index.js:1:4494)
    at /mnt/dev/bot/node_modules/masto/dist/index.js:1:4447
    at Array.forEach (<anonymous>)
    at createFormData (/mnt/dev/bot/node_modules/masto/dist/index.js:1:4409)
    at /mnt/dev/bot/node_modules/masto/dist/index.js:1:4447
    at Array.forEach (<anonymous>)
    at createFormData (/mnt/dev/bot/node_modules/masto/dist/index.js:1:4409)
(node:19274) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:19274) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```

Pull request:
Fix transformer for multipart/form-data
closes #97 

Patch:
diff --git a/src/gateway/create-form-data.ts b/src/gateway/create-form-data.ts
index 32efcef7..7116a817 100644
--- a/src/gateway/create-form-data.ts
+++ b/src/gateway/create-form-data.ts
@@ -1,10 +1,10 @@
 // tslint:disable-next-line no-import-side-effect
 import 'isomorphic-form-data';
 
-export const isArray = (x: any): x is any[] =>
-  Object.prototype.toString.call(x) === '[object Array]';
-export const isObject = (x: any): x is { [key: string]: any } =>
-  Object.prototype.toString.call(x) === '[object Object]';
+export const isArray = (x: unknown): x is any[] =>
+  typeof x === 'object' && x !== null && x.constructor === Array;
+export const isObject = (x: unknown): x is { [key: string]: any } =>
+  typeof x === 'object' && x !== null && x.constructor === Object;
 
 /**
  * Encode nested object to form-data compatible flat object


Test patch:
diff --git a/src/gateway/__tests__/create-form-data.spec.ts b/src/gateway/__tests__/create-form-data.spec.ts
index 4679d15f..1f8e6237 100644
--- a/src/gateway/__tests__/create-form-data.spec.ts
+++ b/src/gateway/__tests__/create-form-data.spec.ts
@@ -1,3 +1,5 @@
+// tslint:disable-next-line no-import-side-effect
+import 'isomorphic-form-data';
 import { createFormData, isArray, isObject } from '../create-form-data';
 
 /**
@@ -42,11 +44,13 @@ test('typed isObject', () => {
   const r2 = isObject([1, 2]);
   const r3 = isObject({});
   const r4 = isObject({ a: 'a' });
+  const r5 = isObject(new FormData());
 
   expect(r1).toBe(false);
   expect(r2).toBe(false);
   expect(r3).toBe(true);
   expect(r4).toBe(true);
+  expect(r5).toBe(false);
 });
 
 test('flat value', () => {