Improve code quality

This commit is contained in:
Fawad Mirzad
2021-02-13 19:09:37 +01:00
parent 62595c2421
commit 6cb357d41e
6 changed files with 52 additions and 78 deletions

View File

@@ -0,0 +1,32 @@
export function createMapScript(options) {
const googleMapScript = document.createElement('SCRIPT')
// Allow options to be an object.
// This is to support more esoteric means of loading Google Maps,
// such as Google for business
// https://developers.google.com/maps/documentation/javascript/get-api-key#premium-auth
if (typeof options !== 'object') {
throw new Error('options should be an object')
}
// libraries
/* eslint-disable no-prototype-builtins */
if (Array.prototype.isPrototypeOf(options.libraries)) {
options.libraries = options.libraries.join(',')
}
options['callback'] = 'vueGoogleMapsInit'
let baseUrl = 'https://maps.googleapis.com/'
let url =
baseUrl +
'maps/api/js?' +
Object.keys(options)
.map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(options[key]))
.join('&')
googleMapScript.setAttribute('src', url)
googleMapScript.setAttribute('async', '')
googleMapScript.setAttribute('defer', '')
return googleMapScript;
}

5
src/utils/env.js Normal file
View File

@@ -0,0 +1,5 @@
export class Env {
static isServer() {
return typeof document === 'undefined';
}
}

3
src/utils/event.js Normal file
View File

@@ -0,0 +1,3 @@
export class eventUtils {
}