1 import { environment } from '../../../environments/environment'
3 // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
4 function getParameterByName (name: string, url: string) {
5 if (!url) url = window.location.href
6 name = name.replace(/[[\]]/g, '\\$&')
8 const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)')
9 const results = regex.exec(url)
11 if (!results) return null
12 if (!results[2]) return ''
14 return decodeURIComponent(results[2].replace(/\+/g, ' '))
17 function getAbsoluteAPIUrl () {
18 let absoluteAPIUrl = environment.hmr === true
19 ? 'http://localhost:9000'
22 if (!absoluteAPIUrl) {
23 // The API is on the same domain
24 absoluteAPIUrl = window.location.origin
30 function getAbsoluteEmbedUrl () {
31 let absoluteEmbedUrl = environment.originServerUrl
32 if (!absoluteEmbedUrl) {
33 // The Embed is on the same domain
34 absoluteEmbedUrl = window.location.origin
37 return absoluteEmbedUrl
40 // Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34
41 function objectToFormData (obj: any, form?: FormData, namespace?: string) {
42 const fd = form || new FormData()
45 for (const key of Object.keys(obj)) {
46 if (namespace) formKey = `${namespace}[${key}]`
49 if (obj[key] === undefined) continue
51 if (Array.isArray(obj[key]) && obj[key].length === 0) {
56 if (obj[key] !== null && typeof obj[key] === 'object' && !(obj[key] instanceof File)) {
57 objectToFormData(obj[key], fd, formKey)
59 fd.append(formKey, obj[key])