Skip to content

Commit cccdd9d

Browse files
merge conflicts
1 parent 8dc429b commit cccdd9d

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/index.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,13 @@ const _hasOwn = Object.prototype.hasOwnProperty;
3131
* @returns {T}
3232
* @template T
3333
*/
34-
export const map = <T>(opt_initial: T | null | undefined): object => {
34+
export function map<T>(opt_initial: T | undefined) {
3535
const object = Object.create(null);
3636
if (opt_initial) {
37-
Object.assign(object, { ...opt_initial });
37+
Object.assign(object, opt_initial);
3838
}
39-
40-
// FIXME(@DerekNonGeneric): Should we be returning these newly-created
41-
// objects w/ `null` prototypes instead of `undefined` ones, (which is
42-
// what had previously been doing and are still currently testing for)?
4339
return object;
44-
};
40+
}
4541

4642
/**
4743
* Checks if the given key is a property in the map.
@@ -50,9 +46,9 @@ export const map = <T>(opt_initial: T | null | undefined): object => {
5046
* @returns {boolean}
5147
* @template T
5248
*/
53-
export const hasOwn = <T>(object: T, key: string): boolean => {
49+
export function hasOwn<T>(object: T, key: string) {
5450
return _hasOwn.call(object, key);
55-
};
51+
}
5652

5753
/**
5854
* Returns obj[key] iff key is obj's own property (is not inherited).
@@ -61,12 +57,12 @@ export const hasOwn = <T>(object: T, key: string): boolean => {
6157
* @param {string} key
6258
* @returns {unknown}
6359
*/
64-
export const ownProperty = (
60+
export function ownProperty(
6561
object: Record<string, number | RegExp>,
6662
key: string
67-
): unknown => {
68-
return hasOwn(object, key) ? Reflect.get(object, key) : undefined;
69-
};
63+
) {
64+
return hasOwn(object, key) ? object[key] : undefined;
65+
}
7066

7167
/** @typedef {{t: object, s: object, d: number}} DeepMergeTuple */
7268
interface DeepMergeTuple {
@@ -92,11 +88,10 @@ export const deepMerge = (
9288
depth = 10
9389
): object => {
9490
// Keep track of seen objects to detect recursive references.
95-
/** @type {!object[]} */
96-
const seen: object[] = [];
91+
const seen: Object[] = [];
9792

98-
/** @type {!DeepMergeTuple[]} */
99-
const queue: DeepMergeTuple[] = [];
93+
/** @type {!Array<ITargetSourceDepth>} */
94+
const queue: ITargetSourceDepth[] = [];
10095
queue.push({ t: target, s: source, d: 0 });
10196

10297
// BFS to ensure objects don't have recursive references at shallower depths.
@@ -116,7 +111,7 @@ export const deepMerge = (
116111
continue;
117112
}
118113
for (const key of Object.keys(s)) {
119-
const newValue = Reflect.get(s, key);
114+
const newValue = s[key];
120115
// Perform a deep merge IFF both target and source have the same key
121116
// whose corresponding values are objects.
122117
if (hasOwn(t, key)) {
@@ -126,7 +121,7 @@ export const deepMerge = (
126121
continue;
127122
}
128123
}
129-
Reflect.set(t, key, newValue);
124+
t[key] = newValue;
130125
}
131126
}
132127
return target;
@@ -140,7 +135,7 @@ export const deepMerge = (
140135
export const objectsEqualShallow = (
141136
o1: Record<string, number | RegExp> | null | undefined,
142137
o2: Record<string, number | RegExp> | null | undefined
143-
): boolean => {
138+
): boolean {
144139
if (o1 == undefined || o2 == undefined) {
145140
// Null is only equal to null, and undefined to undefined.
146141
return o1 === o2;
@@ -182,3 +177,18 @@ export const memo = <T extends object, P extends keyof T>(
182177
}
183178
return result;
184179
};
180+
/**
181+
* Check if a value is an object
182+
*
183+
* @param {object} source
184+
* @returns {Boolean}
185+
*/
186+
export function isPlainObject(source: Object): boolean {
187+
const typeofSource: string = typeof source;
188+
const sourcePrototype: string = Object.prototype.toString.call(source);
189+
return (
190+
typeofSource === 'object' &&
191+
source !== null &&
192+
sourcePrototype === '[object Object]'
193+
);
194+
}

0 commit comments

Comments
 (0)