Sha256: 4ec4784c9a924b9b31b42680d4600cbff8193cca71b20b6bb94a9f36144cc686

Contents?: true

Size: 656 Bytes

Versions: 76

Compression:

Stored size: 656 Bytes

Contents

const { canMerge, prettyPrint } = require('./helpers')
const deepMerge = require('./deep_merge')

const deepAssign = (obj, path, value) => {
  if (!value && value !== false) throw new Error(`Value can't be ${value}`)

  const keys = path.split('.')
  const key = keys.pop()

  const objRef = keys.reduce((acc, currentValue) => {
    /* eslint no-param-reassign: 0 */
    if (!acc[currentValue]) acc[currentValue] = {}
    return acc[currentValue]
  }, obj)

  if (!objRef) throw new Error(`Prop not found: ${path} in ${prettyPrint(obj)}`)

  objRef[key] = canMerge(value) ? deepMerge(objRef[key], value) : value
  return obj
}

module.exports = deepAssign

Version data entries

76 entries across 75 versions & 12 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/deep_assign.js
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/deep_assign.js
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/deep_assign.js
optimacms-0.1.61 spec/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
jetpacker-0.7.0 package/utils/deep_assign.js
webpacker-5.4.4 package/utils/deep_assign.js
jetpacker-0.6.0 package/utils/deep_assign.js
disco_app-0.18.0 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.18.2 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.16.1 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.15.2 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.18.4 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.18.1 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.14.0 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
webpacker-5.4.3 package/utils/deep_assign.js
webpacker-5.4.2 package/utils/deep_assign.js
webpacker-5.4.1 package/utils/deep_assign.js
webpacker-5.4.0 package/utils/deep_assign.js