blob: 6740572e65a6685dc0c7b5aca9532d7166bc954f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Created by km on 3/6/17.
*/
/**
* Creates and returns a shallow copy of a given object.
* @param object The object to create a shallow copy of.
* @returns The new copy of object.
*/
export function shallowCopyOf(object) {
if (object === null || object === undefined) {
return object;
}
const copy = Object.create(Object.getPrototypeOf(object));
Object.assign(copy, object);
return copy;
}
/**
* Returns whether or not a given object is an instance of
* a specified type, modifying the type of the object in
* TypeScript's type system.
*
* Prefer this function to using `instanceof` directly as it
* will retype the passed in object if the check succeeds.
*
* @param object The object whose nominal type will be checked.
* @param type The metatype that `object` is expected to be an instance of.
* @returns Whether object is an instance of type, updating the type of object accordingly.
*/
export function isTypeOf(object, type) {
return object instanceof type;
}
//# sourceMappingURL=objects.js.map
|