Skip to content

Commit 018622c

Browse files
Updated JSDocs
1 parent 192abc2 commit 018622c

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/index.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const _hasOwn = Object.prototype.hasOwnProperty;
3232
* @template T
3333
*/
3434
export function map<T>(opt_initial: T | undefined) {
35-
const obj = Object.create(null);
35+
const object = Object.create(null);
3636
if (opt_initial) {
37-
Object.assign(obj, opt_initial);
37+
Object.assign(object, opt_initial);
3838
}
39-
return obj;
39+
return object;
4040
}
4141

4242
/**
@@ -46,8 +46,8 @@ export function map<T>(opt_initial: T | undefined) {
4646
* @returns {boolean}
4747
* @template T
4848
*/
49-
export function hasOwn<T>(obj: T, key: string) {
50-
return _hasOwn.call(obj, key);
49+
export function hasOwn<T>(object: T, key: string) {
50+
return _hasOwn.call(object, key);
5151
}
5252

5353
/**
@@ -57,12 +57,11 @@ export function hasOwn<T>(obj: T, key: string) {
5757
* @param {string} key
5858
* @returns {unknown}
5959
*/
60-
export function ownProperty(obj: Record<string, number | RegExp>, key: string) {
61-
if (hasOwn(obj, key)) {
62-
return obj[key];
63-
} else {
64-
return undefined;
65-
}
60+
export function ownProperty(
61+
object: Record<string, number | RegExp>,
62+
key: string
63+
) {
64+
return hasOwn(object, key) ? object[key] : undefined;
6665
}
6766

6867
interface ITargetSourceDepth {
@@ -84,10 +83,10 @@ interface ITargetSourceDepth {
8483
*/
8584
export function deepMerge(target: Object, source: Object, depth = 10): Object {
8685
// Keep track of seen objects to detect recursive references.
87-
const seen: Array<Object> = [];
86+
const seen: Object[] = [];
8887

8988
/** @type {!Array<ITargetSourceDepth>} */
90-
const queue: Array<ITargetSourceDepth> = [];
89+
const queue: ITargetSourceDepth[] = [];
9190
queue.push({ t: target, s: source, d: 0 });
9291

9392
// BFS to ensure objects don't have recursive references at shallower depths.
@@ -104,19 +103,19 @@ export function deepMerge(target: Object, source: Object, depth = 10): Object {
104103
Object.assign(t, s);
105104
continue;
106105
}
107-
Object.keys(s).forEach((key) => {
106+
for (const key of Object.keys(s)) {
108107
const newValue = s[key];
109108
// Perform a deep merge IFF both target and source have the same key
110109
// whose corresponding values are objects.
111110
if (hasOwn(t, key)) {
112111
const oldValue = t[key];
113112
if (isObject(newValue) && isObject(oldValue)) {
114113
queue.push({ t: oldValue, s: newValue, d: d + 1 });
115-
return;
114+
continue;
116115
}
117116
}
118117
t[key] = newValue;
119-
});
118+
}
120119
}
121120
return target;
122121
}
@@ -130,7 +129,7 @@ export function objectsEqualShallow(
130129
o1: Record<string, number | RegExp> | null | undefined,
131130
o2: Record<string, number | RegExp> | null | undefined
132131
): boolean {
133-
if (o1 == null || o2 == null) {
132+
if (o1 == undefined || o2 == undefined) {
134133
// Null is only equal to null, and undefined to undefined.
135134
return o1 === o2;
136135
}
@@ -160,20 +159,20 @@ export function objectsEqualShallow(
160159
* @template T,R
161160
*/
162161
export function memo<T, P extends keyof T>(
163-
obj: T,
164-
prop: P,
165-
factory: (arg0: T, arg1: P) => T[P]
162+
object: T,
163+
property: P,
164+
factory: (argument0: T, argument1: P) => T[P]
166165
): T[P] {
167-
let result = obj[prop];
166+
let result = object[property];
168167
if (result === undefined) {
169-
result = factory(obj, prop);
170-
obj[prop] = result;
168+
result = factory(object, property);
169+
object[property] = result;
171170
}
172171
return result;
173172
}
174173

175174
/**
176-
* Validate if a value is an object
175+
* Check if a value is an object
177176
*
178177
* @param {object} source
179178
* @returns {Boolean}
@@ -186,4 +185,4 @@ export function isPlainObject(source: Object): boolean {
186185
source !== null &&
187186
sourcePrototype === '[object Object]'
188187
);
189-
}
188+
}

0 commit comments

Comments
 (0)