ObjectUtils

Object Util Functions

Description:
  • Object Util Functions

Methods

(static) deepCloneObject(userObject) → {Object|undefined}

Deep clone an object (JSON-based)

.

Description:
  • Deep clone an object (JSON-based)

Example
getObjectValues(undefined)  => undefined

getObjectValues(null)  => undefined

getObjectValues("phane")  => undefined

getObjectValues(12)  => undefined

const obj = { a: 1, b: { c: 2 } };
const copy = deepCloneObject(obj);
copy.b.c = 99;
console.log(obj.b.c); // 2

deepCloneObject({ name: "phane" }) => { name: "phane" }

deepCloneObject(null) => undefined
Parameters:
Name Type Description
userObject Object

The object to deep clone

Returns:

Returns a deep-cloned object, or undefined if the input is not a valid object

Type
Object | undefined

(static) getObjectKeys(userObject) → {Array|undefined}

Get the keys of the Object

.

Description:
  • Get the keys of the Object

Example
getObjectKeys({ a: 1}) => return [a]

getObjectKeys(undefined)  => undefined

getObjectKeys(null)  => undefined

getObjectKeys("phane")  => undefined

getObjectKeys(12)  => undefined

getObjectKeys({ label: "phane" })  => [label]

getObjectKeys({ label: "phane", title: "Full Stack Developer" })  => [label, title]

getObjectKeys({ label: "phane", title: "Full Stack Developer", active: true })  => [label, title, active]
Parameters:
Name Type Description
userObject Object

The object to get the keys

Returns:

Returns Array of keys, or undefined if the input is not a valid object

Type
Array | undefined

(static) getObjectValues(userObject) → {Array|undefined}

Get the keys of the Object

.

Description:
  • Get the keys of the Object

Example
getObjectValues({ a: 1}) => return [a]

getObjectValues(undefined)  => undefined

getObjectValues(null)  => undefined

getObjectValues("phane")  => undefined

getObjectValues(12)  => undefined

getObjectValues({ label: "phane" })  => [label]

getObjectValues({ label: "phane", title: "Full Stack Developer" })  => [label, title]

getObjectValues({ label: "phane", title: "Full Stack Developer", active: true })  => [label, title, active]
Parameters:
Name Type Description
userObject Object

The object to get the values

Returns:

Returns Array of values, or undefined if the input is not a valid object

Type
Array | undefined

(static) hasObjectKey(userObject, key) → {boolean|undefined}

Check whether an object has a specific own property

.

Description:
  • Check whether an object has a specific own property

Example
hasObjectKey(undefined)  => undefined

hasObjectKey(null)  => undefined

hasObjectKey("phane")  => undefined

hasObjectKey(12)  => undefined

hasObjectKey({ a: 1 }, "a") => true

hasObjectKey({ a: 1 }, "b") =>  false

hasObjectKey(Object.create(null), "a") => false

hasObjectKey([], "length") => undefined

hasObjectKey(null, "a"); => undefined
Parameters:
Name Type Description
userObject Object

The object to check

key string

The key to check for

Returns:

Returns true if the key exists, false if it does not exist, or undefined if inputs are invalid

Type
boolean | undefined

(static) isEmptyObject(userObject) → {boolean|undefined}

Check whether an object is empty

.

Description:
  • Check whether an object is empty

Example
isEmptyObject({}) => true

isEmptyObject(undefined) => undefined

isEmptyObject(null) => undefined

isEmptyObject("phane") => undefined

isEmptyObject(12) => undefined

isEmptyObject({ label: "phane" }) => false

isEmptyObject({ label: "phane", title: "Full Stack Developer" }) => false

isEmptyObject({ label: "phane", title: "Full Stack Developer", active: true }) => false
Parameters:
Name Type Description
userObject Object

The object to check

Returns:

Returns true if the object is empty, false if it has properties, or undefined if the input is not a valid object

Type
boolean | undefined