Methods
Object

Object Methods

import { object } from 'ajuda'

deepCopy

Description

Creates a deep copy of an object (where nested elements will not reference the original).

object.deepCopy(_object: any): any

Parameters

{Object} _object A plain old JavaScript object.

Returns

{Object} A new object.

Example

let alpha = { hello: "world" }
let bravo = object.deepCopy(alpha)
alpha.hello = "earth"
 
bravo.hello === "earth"
// false

isEmpty

Description

Checks whether an object is empty or not.

object.isEmpty(object: any): boolean

Parameters

{Object} object The object to check.

Returns

{boolean} true if the object is empty, false otherwise.

Example

let notEmpty = { name: "Alice" }
let empty = {}
 
object.isEmpty(notEmpty)
// false
 
object.isEmpty(empty)
// true

parse

Description

Returns safely parsed JSON.

object.parse(object: any): any

Parameters

{Object} object The JSON payload to be safely parsed.

Returns

{Object} Safely parsed JSON.

Example

let object = {
  alpha: "bravo",
  "charlie": "delta",
  1: 2
}
 
object.parse(object)
/*
{
  "1": 2,
  "alpha": "bravo",
  "charlie": "delta"
}
*/