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
webpacker-5.3.0 package/utils/deep_assign.js
webpacker-5.2.2 package/utils/deep_assign.js
tang-0.2.1 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_assign.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@rails/webpacker/package/utils/deep_assign.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@rails/webpacker/package/utils/deep_assign.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@rails/webpacker/package/utils/deep_assign.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@rails/webpacker/package/utils/deep_assign.js
jetpacker-0.5.0 package/utils/deep_assign.js
tang-0.2.0 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_assign.js
tang-0.1.0 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_assign.js
tang-0.0.9 spec/tang_app/node_modules/@rails/webpacker/package/utils/deep_assign.js
webpacker-5.2.1 package/utils/deep_assign.js
webpacker-4.3.0 package/utils/deep_assign.js
webpacker-5.2.0 package/utils/deep_assign.js
enju_library-0.3.8 spec/dummy/node_modules/@rails/webpacker/package/utils/deep_assign.js
webpacker-5.1.1 package/utils/deep_assign.js
webpacker-5.1.0 package/utils/deep_assign.js
webpacker-5.0.1 package/utils/deep_assign.js
webpacker-5.0.0 package/utils/deep_assign.js
jetpacker-0.4.2 package/utils/deep_assign.js