All files Formulate.js

90.48% Statements 19/21
85.71% Branches 12/14
100% Functions 5/5
90.48% Lines 19/21

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92                                  3x                                   3x 3x 3x 21x   3x                 6x 6x 13x 4x       9x     6x 6x 2x     6x               49x 49x                   40x 40x              
import library from './libs/library'
import isPlainObject from 'is-plain-object'
import FormulateInput from './FormulateInput.vue'
import FormulateForm from './FormulateForm.vue'
import FormulateInputGroup from './FormulateInputGroup.vue'
import FormulateInputBox from './inputs/FormulateInputBox.vue'
import FormulateInputText from './inputs/FormulateInputText.vue'
import FormulateInputSelect from './inputs/FormulateInputSelect.vue'
import FormulateInputTextArea from './inputs/FormulateInputTextArea.vue'
/**
 * The base formulate library.
 */
class Formulate {
  /**
   * Instantiate our base options.
   */
  constructor () {
    this.defaults = {
      components: {
        FormulateForm,
        FormulateInput,
        FormulateInputBox,
        FormulateInputText,
        FormulateInputGroup,
        FormulateInputSelect,
        FormulateInputTextArea
      },
      library
    }
  }
 
  /**
   * Install vue formulate, and register it’s components.
   */
  install (Vue, options) {
    Vue.prototype.$formulate = this
    this.options = this.extend(this.defaults, options || {})
    for (var componentName in this.options.components) {
      Vue.component(componentName, this.options.components[componentName])
    }
    Object.freeze(this)
  }
 
  /**
   * Create a new object by copying properties of base and extendWith.
   * @param {Object} base
   * @param {Object} extendWith
   */
  extend (base, extendWith) {
    var merged = {}
    for (var key in base) {
      if (extendWith.hasOwnProperty(key)) {
        merged[key] = isPlainObject(extendWith[key]) && isPlainObject(base[key])
          ? this.extend(base[key], extendWith[key])
          : extendWith[key]
      } else {
        merged[key] = base[key]
      }
    }
    for (var prop in extendWith) {
      if (!merged.hasOwnProperty(prop)) {
        merged[prop] = extendWith[prop]
      }
    }
    return merged
  }
 
  /**
   * Determine what "class" of input this element is given the "type".
   * @param {string} type
   */
  classify (type) {
    Eif (this.options.library.hasOwnProperty(type)) {
      return this.options.library[type].classification
    }
    return 'unknown'
  }
 
  /**
   * Determine what type of component to render given the "type".
   * @param {string} type
   */
  component (type) {
    Eif (this.options.library.hasOwnProperty(type)) {
      return this.options.library[type].component
    }
    return false
  }
}
 
export default new Formulate()