Skip to content

Instantly share code, notes, and snippets.

@just-leo
just-leo / deepMerge.js
Last active January 5, 2020 19:43
Deep merge js objects
/**
* Merge obj2: object into target: object recursivelly including array properties
*/
function deepMerge(target, obj2) {
Object.keys(obj2).forEach(key => {
const val = obj2[key];
if (!target[key]) {
target[key] = val;
} else if (Array.isArray(val)) {
val.forEach(item => target[key].indexOf(item) === -1 && target[key].push(item));
@just-leo
just-leo / apiclientUtilizingProxy.js
Last active January 6, 2020 17:43
Real world example of js Proxy usage
/**
* Makes some magic, for ex call like this
* api.postDonorAccount({id: 'ewqewq'}); -> leads to POST request to url: /donor/account with data: {id: '..'}
*/
const { METHODS } = require('http');
class ApiService {
/**
* Set uri of REST server
* @constructor