aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/misc/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/misc/utils.ts')
-rw-r--r--client/src/app/shared/misc/utils.ts24
1 files changed, 23 insertions, 1 deletions
diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts
index e6a697098..e2e4c5b36 100644
--- a/client/src/app/shared/misc/utils.ts
+++ b/client/src/app/shared/misc/utils.ts
@@ -67,6 +67,27 @@ function isInMobileView () {
67 return window.innerWidth < 500 67 return window.innerWidth < 500
68} 68}
69 69
70// Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34
71function objectToFormData (obj: any, form?: FormData, namespace?: string) {
72 let fd = form || new FormData()
73 let formKey
74
75 for (let key of Object.keys(obj)) {
76 if (namespace) formKey = `${namespace}[${key}]`
77 else formKey = key
78
79 if (obj[key] === undefined) continue
80
81 if (typeof obj[ key ] === 'object' && !(obj[ key ] instanceof File)) {
82 objectToFormData(obj[ key ], fd, key)
83 } else {
84 fd.append(formKey, obj[ key ])
85 }
86 }
87
88 return fd
89}
90
70export { 91export {
71 viewportHeight, 92 viewportHeight,
72 getParameterByName, 93 getParameterByName,
@@ -75,5 +96,6 @@ export {
75 dateToHuman, 96 dateToHuman,
76 isInSmallView, 97 isInSmallView,
77 isInMobileView, 98 isInMobileView,
78 immutableAssign 99 immutableAssign,
100 objectToFormData
79} 101}