All files / src plugin.js

100% Statements 16/16
84.62% Branches 11/13
100% Functions 5/5
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  9x 1x     8x   8x         8x   8x 17x   17x 16x   16x     1x                     8x 8x         8x    
export function install(Vue, options = {}) {
  if (Vue.CldInstalled) {
    throw new Error("Cloudinary plugin already installed");
  }
 
  Vue.CldInstalled = true;
 
  initComponents(Vue, options);
}
 
function registerComponents(Vue, components = {}, defaultConfigurations = {}) {
  /* eslint-disable-next-line */
  if (!defaultConfigurations) { console.warn('🛑 There is no default configuration for Cloudinary found!') }
 
  for (let key in components) {
    const component = components[key];
 
    if (component) {
      const data = component.data ? component.data() : {}
 
      Vue.component(key, {
        ...component,
        data() {
          return {
            ...data,
            defaultConfigurations
          }
        }
      });
    }
  }
}
 
function initComponents(Vue, options) {
  const configuration = options.configuration;
  const components = Array.isArray(options.components) ? options.components.reduce((obj, component) => ({
    ...obj,
    [component.name]: component
  }), {}) : options.components;
 
  registerComponents(Vue, components, configuration);
}