Skip to content

Commit

Permalink
feat: rename deepmerge to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Nov 18, 2024
1 parent 219607f commit 65e7a61
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/utils/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('should match expected exports', () => {
'callAll',
'callEventHandlers',
'dataAttr',
'deepmerge',
'merge',
'noop',
'once',
'runIfFn',
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('should match expected exports', () => {
'callAll',
'callEventHandlers',
'dataAttr',
'deepmerge',
'merge',
'noop',
'once',
'runIfFn',
Expand Down
22 changes: 11 additions & 11 deletions packages/utils/src/__tests__/shared.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
callAll,
callEventHandlers,
dataAttr,
deepmerge,
merge,
noop,
once,
runIfFn,
Expand Down Expand Up @@ -86,9 +86,9 @@ describe('dataAttr', () => {
});
});

describe('deepmerge', () => {
describe('merge', () => {
it('should not be subject to prototype pollution via __proto__', () => {
const result = deepmerge(
const result = merge(
{},
JSON.parse('{ "myProperty": "a", "__proto__" : { "isAdmin" : true } }'),
{
Expand All @@ -101,7 +101,7 @@ describe('deepmerge', () => {
});

it('should not be subject to prototype pollution via constructor', () => {
const result = deepmerge(
const result = merge(
{},
JSON.parse('{ "myProperty": "a", "constructor" : { "prototype": { "isAdmin" : true } } }'),
{
Expand All @@ -114,7 +114,7 @@ describe('deepmerge', () => {
});

it('should not be subject to prototype pollution via prototype', () => {
const result = deepmerge(
const result = merge(
{},
JSON.parse('{ "myProperty": "a", "prototype": { "isAdmin" : true } }'),
{
Expand All @@ -127,7 +127,7 @@ describe('deepmerge', () => {
});

it('should appropriately copy the fields without prototype pollution', () => {
const result = deepmerge(
const result = merge(
{},
JSON.parse('{ "myProperty": "a", "__proto__" : { "isAdmin" : true } }')
);
Expand All @@ -142,21 +142,21 @@ describe('deepmerge', () => {
}

const vmObject = runInNewContext('({hello: "realm"})');
const result = deepmerge({ hello: 'original' }, vmObject);
const result = merge({ hello: 'original' }, vmObject);
expect(result.hello).toBe('realm');
});

it('should not merge HTML elements', () => {
const element = document.createElement('div');
const element2 = document.createElement('div');

const result = deepmerge({ element }, { element: element2 });
const result = merge({ element }, { element: element2 });

expect(result.element).toBe(element2);
});

it('should reset source when target is undefined', () => {
const result = deepmerge(
const result = merge(
{
'&.disabled': {
color: 'red',
Expand All @@ -172,7 +172,7 @@ describe('deepmerge', () => {
});

it('should merge keys that do not exist in source', () => {
const result = deepmerge({ foo: { baz: 'test' } }, { foo: { bar: 'test' }, bar: 'test' });
const result = merge({ foo: { baz: 'test' } }, { foo: { bar: 'test' }, bar: 'test' });
expect(result).toEqual({
foo: { baz: 'test', bar: 'test' },
bar: 'test',
Expand All @@ -183,7 +183,7 @@ describe('deepmerge', () => {
const foo = { foo: { baz: 'test' } };
const bar = {};

const result = deepmerge(bar, foo);
const result = merge(bar, foo);

expect(result).toEqual({ foo: { baz: 'test' } });

Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const dataAttr = (condition) => {
return condition ? '' : undefined;
};

export const deepmerge = (target, source, options = { clone: true }) => {
export const merge = (target, source, options = { clone: true }) => {
const output = options.clone ? { ...target } : target;

if (isPlainObject(target) && isPlainObject(source)) {
Expand All @@ -64,7 +64,7 @@ export const deepmerge = (target, source, options = { clone: true }) => {
Object.prototype.hasOwnProperty.call(target, key) &&
isPlainObject(target[key])
) {
output[key] = deepmerge(target[key], source[key], options);
output[key] = merge(target[key], source[key], options);
} else if (options.clone) {
output[key] = isPlainObject(source[key]) ? _deepClone(source[key]) : source[key];
} else {
Expand Down

0 comments on commit 65e7a61

Please sign in to comment.