Sha256: decfd6601c95b7d39c83e19322646227acd943ced21af3da6d482f2dfa34c9d3

Contents?: true

Size: 1.15 KB

Versions: 50

Compression:

Stored size: 1.15 KB

Contents

const objectify = require('../utils/objectify')
const deepAssign = require('../utils/deep_assign')
const deepMerge = require('../utils/deep_merge')
const { isStrPath, prettyPrint } = require('../utils/helpers')

/**
  * @class
  * @extends { Object }
*/
class ConfigObject extends Object {
  constructor(props = {}) {
    super()
    this.merge(props)
  }

  get(key) {
    return isStrPath(key) ? objectify(key, this) : this[key]
  }

  set(key, value) {
    Object.assign(this, deepAssign(this, key, value))
    return this
  }

  delete(key) {
    let obj = this
    let propKey = key

    if (isStrPath(key)) {
      const keys = key.split('.')
      propKey = keys.pop()
      const parentObjPath = keys.join('.')
      obj = objectify(parentObjPath, this)
    }

    if (!obj) throw new Error(`Prop not found: ${key} in ${prettyPrint(obj)}`)
    delete obj[propKey]

    return this
  }

  toObject() {
    const object = {}
    /* eslint no-return-assign: 0 */
    Object.keys(this).forEach(key => (object[key] = this[key]))
    return object
  }

  merge(config) {
    Object.assign(this, deepMerge(this, config))
    return this
  }
}

module.exports = ConfigObject

Version data entries

50 entries across 50 versions & 7 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/@rails/webpacker/package/config_types/config_object.js
disco_app-0.18.2 test/dummy/node_modules/@rails/webpacker/package/config_types/config_object.js
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/config_types/config_object.js
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/config_types/config_object.js
jester-data-8.0.0 node_modules/@rails/webpacker/package/config_types/config_object.js
ezii-os-5.2.1 node_modules/@rails/webpacker/package/config_types/config_object.js
ezii-os-2.0.1 node_modules/@rails/webpacker/package/config_types/config_object.js
ezii-os-1.1.0 node_modules/@rails/webpacker/package/config_types/config_object.js
ezii-os-1.0.0 node_modules/@rails/webpacker/package/config_types/config_object.js
ezii-os-0.0.0.1.0 node_modules/@rails/webpacker/package/config_types/config_object.js
ezii-os-0.0.0.0.1 node_modules/@rails/webpacker/package/config_types/config_object.js
webpacker-4.0.7 package/config_types/config_object.js
webpacker-4.0.6 package/config_types/config_object.js
webpacker-4.0.5 package/config_types/config_object.js
webpacker-4.0.4 package/config_types/config_object.js
webpacker-4.0.3 package/config_types/config_object.js
webpacker-4.0.2 package/config_types/config_object.js
webpacker-3.6.0 package/config_types/config_object.js
webpacker-4.0.1 package/config_types/config_object.js
webpacker-4.0.0 package/config_types/config_object.js