Shallow Object Clone. Will not clone nested objects.
name | type | description |
---|---|---|
obj | object |
The object to clone. |
A new object with the same properties as the input object.
Deep Copy the given object or array.
name | type | description |
---|---|---|
obj | object |
The object to deep copy. |
A deep copy of the original object.
This is a slightly modified version of http://api.jquery.com/jQuery.extend/
name | type | arguments | description |
---|---|---|---|
args | * | <optional> |
The objects that will be mixed. |
The extended object.
Retrieves a value from an object. Allows for more advanced selection options, including:
Allowed types:
Implicit { x: 4 }
From function { x: function () }
Randomly pick one element from the array { x: [a, b, c, d, e, f] }
Random integer between min and max: { x: { randInt: [min, max] } }
Random float between min and max: { x: { randFloat: [min, max] } }
name | type | description |
---|---|---|
source | object |
The object to retrieve the value from. |
key | string |
The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot ( |
defaultValue | * |
The value to return if the |
The value of the requested key.
Finds the key within the top level of the source object, or returns defaultValue
name | type | arguments | description |
---|---|---|---|
source | object |
The object to search |
|
key | string |
The key for the property on source. Must exist at the top level of the source object (no periods) |
|
defaultValue | * | <optional> |
The default value to use if the key does not exist. |
The value if found; otherwise, defaultValue (null if none provided)
Retrieves and clamps a numerical value from an object.
name | type | description |
---|---|---|
source | object |
The object to retrieve the value from. |
key | string |
The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot ( |
min | number |
The minimum value which can be returned. |
max | number |
The maximum value which can be returned. |
defaultValue | number |
The value to return if the property doesn't exist. It's also constrained to the given bounds. |
The clamped value from the source
object.
Retrieves a value from an object.
name | type | description |
---|---|---|
source | object |
The object to retrieve the value from. |
key | string |
The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot ( |
defaultValue | * |
The value to return if the |
The value of the requested key.
Verifies that an object contains all requested keys
name | type | description |
---|---|---|
source | object |
an object on which to check for key existence |
keys | Array.<string> |
an array of keys to ensure the source object contains |
true if the source object contains all keys, false otherwise.
Verifies that an object contains at least one of the requested keys
name | type | description |
---|---|---|
source | object |
an object on which to check for key existence |
keys | Array.<string> |
an array of keys to search the object for |
true if the source object contains at least one of the keys, false otherwise
Determine whether the source object has a property with the specified key.
name | type | description |
---|---|---|
source | object |
The source object to be checked. |
key | string |
The property to check for within the object |
true
if the provided key
exists on the source
object, otherwise false
.
This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].
name | type | description |
---|---|---|
obj | object |
The object to inspect. |
true
if the object is plain, otherwise false
.
Creates a new Object using all values from obj1 and obj2. If a value exists in both obj1 and obj2, the value in obj1 is used.
This is only a shallow copy. Deeply nested objects are not cloned, so be sure to only use this function on shallow objects.
name | type | description |
---|---|---|
obj1 | object |
The first object. |
obj2 | object |
The second object. |
A new object containing the union of obj1's and obj2's properties.
Creates a new Object using all values from obj1.
Then scans obj2. If a property is found in obj2 that also exists in obj1, the value from obj2 is used, otherwise the property is skipped.
name | type | description |
---|---|---|
obj1 | object |
The first object to merge. |
obj2 | object |
The second object to merge. Keys from this object which also exist in |
The merged object. obj1
and obj2
are not modified.
Returns a new object that only contains the keys
that were found on the object provided.
If no keys
are found, an empty object is returned.
name | type | description |
---|---|---|
object | object |
The object to pick the provided keys from. |
keys | array |
An array of properties to retrieve from the provided object. |
A new object that only contains the keys
that were found on the provided object. If no keys
were found, an empty object will be returned.
Sets a value in an object, allowing for dot notation to control the depth of the property.
For example:
var data = {
world: {
position: {
x: 200,
y: 100
}
}
};
SetValue(data, 'world.position.y', 300);
console.log(data.world.position.y); // 300
name | type | description |
---|---|---|
source | object |
The object to set the value in. |
key | string |
The name of the property in the object. If a property is nested, the names of its preceding properties should be separated by a dot ( |
value | any |
The value to set into the property, if found in the source object. |
true
if the property key was valid and the value was set, otherwise false
.