Skip to content

Instantly share code, notes, and snippets.

@ahtcx
Last active July 15, 2025 04:32
Show Gist options
  • Save ahtcx/0cd94e62691f539160b32ecda18af3d6 to your computer and use it in GitHub Desktop.
Save ahtcx/0cd94e62691f539160b32ecda18af3d6 to your computer and use it in GitHub Desktop.

Revisions

  1. ahtcx revised this gist Jan 12, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion deep-merge.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // ⚠ IMPORTANT: this is old and not doesn't work for many different edge cases but I'll keep it as-is for any of you who depend on it
    // ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
    // ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`

    // Merge a `source` object to a `target` recursively
  2. ahtcx revised this gist Sep 23, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions deep-merge.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    // ⚠ IMPORTANT: this is old and not doesn't work for many different edge cases but I'll keep it as-is for any of you who depend on it
    // ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`

    // Merge a `source` object to a `target` recursively
    const merge = (target, source) => {
    // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
  3. ahtcx revised this gist Sep 25, 2019. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion deep-merge.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // Merge a `source` object to a `target` recursively
    const merge = (target, source) => {
    // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
    for (let key of Object.keys(source)) {
    for (const key of Object.keys(source)) {
    if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
    }

    2 changes: 1 addition & 1 deletion deep-merge.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    const merge=(t,s)=>{let o=Object,a=o.assign;for(let k of o.keys(s))s[k]instanceof o&&a(s[k],merge(t[k],s[k]));return a(t||{},s),t}
    const merge=(t,s)=>{const o=Object,a=o.assign;for(const k of o.keys(s))s[k]instanceof o&&a(s[k],merge(t[k],s[k]));return a(t||{},s),t}
  4. ahtcx created this gist May 22, 2016.
    11 changes: 11 additions & 0 deletions deep-merge.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // Merge a `source` object to a `target` recursively
    const merge = (target, source) => {
    // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
    for (let key of Object.keys(source)) {
    if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
    }

    // Join `target` and modified `source`
    Object.assign(target || {}, source)
    return target
    }
    1 change: 1 addition & 0 deletions deep-merge.min.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    const merge=(t,s)=>{let o=Object,a=o.assign;for(let k of o.keys(s))s[k]instanceof o&&a(s[k],merge(t[k],s[k]));return a(t||{},s),t}