-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
51 lines (40 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { isEmpty, forEach, get } from 'lodash'
import TrustpilotWidget from './widget.vue'
// implementation to prevent unnecessary logs in production
const logger = (msg) => {
// `get` is necessary as fallback for non ssr access.
const env = get(process, 'env.NODE_ENV')
if (env === 'prod' || env == 'production') {
return;
}
console.info(msg)
}
export default {
/**
* @param {Object} Vue Vue instance
* @param {Object} options.widgets Map of widgets with Trustpilot configuration
*/
install(Vue, options = {}) {
// widgets are required for run it
if (isEmpty(options) || isEmpty(options.widgets)) {
logger("'vue-trustpilot': Trustpilot widgets haven't been found")
return;
}
const { widgets } = options
// `templateId` and `businessunitId` are required but those could be set as html attributes too.
forEach(widgets, (value, key) => {
if (!value.hasOwnProperty('templateId')) {
logger(`'vue-trustpilot': ${key} widget doesn't have 'templateId' attribute`)
}
if (!value.hasOwnProperty('businessunitId')) {
logger(`'vue-trustpilot': ${key} widget doesn't have 'bussinessunitId' attribute`)
}
})
// method for access to the widgets information based on the widget identifier
Vue.prototype.$trustpilot = (identifier = '') => widgets[identifier] || null
// Available widget list
Vue.prototype.$trustpilotWidgetList = () => Object.keys(widgets)
// components to access to the widgets information.
Vue.component('vue-trustpilot', TrustpilotWidget)
}
}