MODULES Uize.Data
SEARCHEXAMPLESSOURCETEST

1. Introduction

The Uize.Data module provides methods for working with data, including comparing complex data structures, finding records, getting keys and values, etc.

DEVELOPERS: Chris van Rensburg

1.1. Examples

There are no dedicated showcase example pages for the Uize.Data module.

SEARCH FOR EXAMPLES

Use the link below to search for example pages on the UIZE Web site that reference the Uize.Data module...

SEARCH

1.2. Implementation Info

The Uize.Data module defines the Uize.Data package under the Uize namespace.

1.2.1. Features Introduced in This Module

1.2.2. Features Overridden in This Module

No features have been overridden in this module.

1.2.3. Features Inherited From Other Modules

This module has no inherited features.

1.2.4. Modules Directly Under This Namespace

1.2.5. Unit Tests

The Uize.Data module is unit tested by the Uize.Test.Uize.Data test module.

2. Static Methods

2.1. Uize.Data.clones

Returns a boolean, indicating whether or not the two specified objects are identical clones of one another.

SYNTAX

areClonesBOOL = Uize.Data.clones (object1OBJ,object2OBJ);

Identical clones have identical structure, possess all the same values for corresponding simple valued properties, but may not share objects (so, object type properties' values may not be shared, either at a corresponding place in their structure, or at different places in their structure).

NOTES

Uize.Data.clones (myObjectOBJ,myObjectOBJ) will return false, since they are one and the same and not clones.

IMPLEMENTATION INFO

this feature was introduced in this module

2.2. Uize.Data.conjoined

Returns a boolean, indicating whether or not the two specified objects share any object references.

SYNTAX

areConjoinedBOOL = Uize.Data.conjoined (object1OBJ,object2OBJ);

NOTES

Uize.Data.conjoined (myObjectOBJ,myObjectOBJ) will return true, since they are one and the same (ie. conjoined at the root).

IMPLEMENTATION INFO

this feature was introduced in this module

2.3. Uize.Data.emptyOut

IMPLEMENTATION INFO

this feature was introduced in this module

2.4. Uize.Data.filter

Returns an object with only the properties of the source object that are specified by an array of property names.

SYNTAX

filteredOBJ = Uize.Data.filter (sourceObjectOBJ,propertyNamesARRAY);

This method can be useful when receiving an info package of which only a subset needs to be stored or passed on to a subsequent process.

EXAMPLE

var someNodeStyle = {
  color:'#fff',
  left:'10px',
  top:'-50px',
  position:'absolute',
  display:'none',
  width:'200px',
  height:'300px',
  overflow:'hidden'
};
Uize.Node.setStyle (
  'someOtherNode',Uize.Data.filter (someNodeStyle,['left','top','width','height'])
);

In this example, a node style object that is being used for some node is being filtered for just its dimensions and positioning properties, to then be applied to some other node.

Without this method, the setStyle method call would look like...

Uize.Node.setStyle (
  'someOtherNode',
  {
    left:someNodeStyle.left,
    top:someNodeStyle.top,
    width:someNodeStyle.width,
    height:someNodeStyle.height
  }
);

IMPLEMENTATION INFO

this feature was introduced in this module

2.5. Uize.Data.findRecords

Returns an array of records from the specified record set that match the specified criteria.

SYNTAX

matchingRecordsARRAY = Uize.Data.findRecords (recordsARRAY,matchOBJ);

EXAMPLE

var
  employees = [
    {firstName:'John',lastName:'Wilkey',department:'engineering'},
    {firstName:'Marie',lastName:'Stevenson',department:'finance'},
    {firstName:'Craig',lastName:'Pollack',department:'finance'},
    {firstName:'Nick',lastName:'Arendsen',department:'engineering'},
    {firstName:'Mark',lastName:'Strathley',department:'engineering'}
  ],
  financeEmployees = Uize.Data.findRecords (employees,{department:'finance'})
;

In the above example, the variable financeEmployees would be an array with the value...

[
  {firstName:'Marie',lastName:'Stevenson',department:'finance'},
  {firstName:'Craig',lastName:'Pollack',department:'finance'}
]

If the records in your record set are arrays, rather than objects, then you can specify a match object where the keys are numerical indexes representing the array element index / column index, as in...

EXAMPLE

var
  employees = [
    ['John','Wilkey','engineering'],
    ['Marie','Stevenson','finance'],
    ['Craig','Pollack','finance'],
    ['Nick','Arendsen','engineering'],
    ['Mark','Strathley','engineering']
  ],
  financeEmployees = Uize.Data.findRecords (employees,{2:'finance'})
;

In the above example, the financeEmployees variable would have the same value as in the previous example.

NOTES

see also the Uize.findRecord, Uize.findRecordNo, and Uize.recordMatches static methods of the Uize.Class base class

IMPLEMENTATION INFO

this feature was introduced in this module

2.6. Uize.Data.getColumn

Returns an array of the values for the specified column of the specified record set.

SYNTAX

columnValuesARRAY = Uize.Data.getColumn (rowsARRAY,columnNameSTR);

EXAMPLE

var
  peopleNames = [
    {first:'John',last:'Wilkey'},
    {first:'Marie',last:'Stevenson'},
    {first:'Craig',last:'Pollack'}
  ],
  firstNames = Uize.Data.getColumn (peopleNames,'first'),
  lastNames = Uize.Data.getColumn (peopleNames,'last')
;

In the above example, the variable firstNames would be an array with the value ['John','Marie','Craig'] and the variable lastNames would be an array with the value ['Wilkey','Stevenson','Pollack'].

The records / rows in the record set do not need to be objects - they can also be arrays.

EXAMPLE

var
  peopleNames = [
    ['John','Wilkey'],
    ['Marie','Stevenson'],
    ['Craig','Pollack']
  ],
  firstNames = Uize.Data.getColumn (peopleNames,0),
  lastNames = Uize.Data.getColumn (peopleNames,1)
;

In the above example, the firstNames and lastNames variables would have the same values as in the previous example.

VARIATION

columnValuesARRAY = Uize.Data.getColumn (rowsARRAY,columnNameSTR,onlyUniquesBOOL);

When the value true is specified for the optional onlyUniquesBOOL parameter, then this method will only return the unique values for the specified column.

EXAMPLE

var
  employees = [
    {firstName:'John',lastName:'Wilkey',department:'engineering'},
    {firstName:'Marie',lastName:'Stevenson',department:'finance'},
    {firstName:'Craig',lastName:'Pollack',department:'finance'},
    {firstName:'Nick',lastName:'Arendsen',department:'engineering'},
    {firstName:'Mark',lastName:'Strathley',department:'engineering'}
  ],
  departments = Uize.Data.getColumn (employees,'department',true)
;

In the above example, the variable departments would be an array with the value ['engineering','finance'].

IMPLEMENTATION INFO

this feature was introduced in this module

2.7. Uize.Data.getKeys

IMPLEMENTATION INFO

this feature was introduced in this module

2.8. Uize.Data.getLookup

IMPLEMENTATION INFO

this feature was introduced in this module

2.9. Uize.Data.getReverseLookup

IMPLEMENTATION INFO

this feature was introduced in this module

2.10. Uize.Data.getTotalKeys

IMPLEMENTATION INFO

this feature was introduced in this module

2.11. Uize.Data.getValues

IMPLEMENTATION INFO

this feature was introduced in this module

2.12. Uize.Data.identical

Returns a boolean, indicating whether or not the two specified objects are identical in their contents.

SYNTAX

areIdenticalBOOL = Uize.Data.identical (object1OBJ,object2OBJ);

This method recurses through the two objects specified by the object1OBJ and object2OBJ parameters, testing that they have the same structure and property values. The two parameters can be arbitrarily complex data trees, or simple type values (ie. string, number, boolean). In order to be considered identical, the two objects must have the same structure and the same values at all levels of their structure.

VARIATION

areIdenticalBOOL = Uize.Data.identical (object1OBJ,object2OBJ,optionsOBJ);

When the optional optionsOBJ parameter is specified, comparison options can be specified to determine the criteria this method uses when comparing the two objects.

2.12.1. optionsOBJ

An object, with multiple optional properties, specifying the criteria this method should use when comparing the two objects.

The value of the optionsOBJ parameter should be an object of the form...

{
  equality : equalitySTR,             // 'type' | 'loose' | 'strict' (default)
  allowConjoined : allowConjoinedBOOL // false | true (default)
}

2.12.1.1. equality

A string, specifying how the values of properties at any level of the objects' structure should be tested for equality.

The optional equality property of the optionsOBJ parameter can have the following values...

'type' - When the value 'type' is specified, the values of properties do not need to be equal - only be of the same type. This setting is useful when merely trying to determine if two objects have the same structure, but not that their values match. This could be used to determine if an object being interrogated conforms to some reference structure that might indicate the type of data it contains, but where the specific values are not important.
'loose' - When the value 'loose' is specified, then the values of all properties must be equal only according to a loose equality comparison, where strict type matching is not performed. According to this setting, the number value 1 would equal the string value '1', or the number value 0 would equal the string value '' (empty string) and the boolean value false.
'strict' - When the value 'strict' is specified (or when no value is specified for the equality property, or when no optionsOBJ parameter is specified), then the values of all properties must be equal according to a strict equality comparison, where strict type matching is performed. According to this setting, the number value 1 would NOT equal the string value '1', the number value 0 would NOT equal the string value '' (empty string), and so on.

2.12.1.2. allowConjoined

A boolean, specifying whether or not the two objects being compared may reference the same shared sub-object at any level of their structure.

By default (when no value is specified for the allowConjoined property, or when no optionsOBJ parameter is specified), two objects being compared will be considered identical even if they are conjoined and reference the same shared sub-object at some level of their structure. Therefore, the statement Uize.Data.identical (myObjectOBJ,myObjectOBJ) will return the value true.

Specifying the value false for this property will require that object references at any level of the structure of the two objects being compared are unique to each object. So, the statement Uize.Data.identical (myObjectOBJ,myObjectOBJ,{allowConjoined:false}) would produce the result false.

IMPORTANT

It should be noted that the two objects being compared could still have references to shared objects at different levels in their structure. To reliably test that two objects are identical and yet completely discrete, one can use the Uize.Data.clones static method.

NOTES

see also the Uize.Data.clones and Uize.Data.conjoined static methods

IMPLEMENTATION INFO

this feature was introduced in this module

2.13. Uize.Data.intersection

Returns an object that represents the key-value intersection / commonality between the two specified objects.

SYNTAX

intersectionOBJ = Uize.Data.intersection (object1OBJ,object2OBJ);

EXAMPLE

var
  employee1 = {
    firstName:'John',
    lastName:'Wilkey',
    startYear:'2008',
    department:'engineering'
  },
  employee2 = {
    firstName:'John',
    lastName:'Henderson',
    startYear:'2008',
    department:'finance'
  },
  employeeInCommon = Uize.Data.intersection (employee1,employee2)
;

In the above example, the variable employeeInCommon would have the value {firstName:'John',startYear:'2008'}.

IMPLEMENTATION INFO

this feature was introduced in this module

2.14. Uize.Data.isEmpty

IMPLEMENTATION INFO

this feature was introduced in this module

2.15. Uize.Data.map

IMPLEMENTATION INFO

this feature was introduced in this module

2.16. Uize.Data.max

IMPLEMENTATION INFO

this feature was introduced in this module

2.17. Uize.Data.min

IMPLEMENTATION INFO

this feature was introduced in this module

3. Deprecated Features

3.1. Uize.Data.emptyOut -- DEPRECATED 2011-11-13

The Uize.Data.emptyOut static method has been deprecated in favor of the newly added Uize.emptyOut static method of the Uize base module.

Uize.Data.emptyOut >> BECOMES >> Uize.emptyOut

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.2. Uize.Data.getKeys -- DEPRECATED 2011-11-13

The Uize.Data.getKeys static method has been deprecated in favor of the newly added Uize.keys static method of the Uize base module.

Uize.Data.getKeys >> BECOMES >> Uize.keys

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.3. Uize.Data.getLookup -- DEPRECATED 2011-11-13

The Uize.Data.getLookup static method has been deprecated in favor of the newly added Uize.lookup static method of the Uize base module.

Uize.Data.getLookup >> BECOMES >> Uize.lookup

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.4. Uize.Data.getReverseLookup -- DEPRECATED 2011-11-13

The Uize.Data.getReverseLookup static method has been deprecated in favor of the newly added Uize.reverseLookup static method of the Uize base module.

Uize.Data.getReverseLookup >> BECOMES >> Uize.reverseLookup

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.5. Uize.Data.getTotalKeys -- DEPRECATED 2011-11-13

The Uize.Data.getTotalKeys static method has been deprecated in favor of the newly added Uize.totalKeys static method of the Uize base module.

Uize.Data.getTotalKeys >> BECOMES >> Uize.totalKeys

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.6. Uize.Data.getValues -- DEPRECATED 2011-11-13

The Uize.Data.getValues static method has been deprecated in favor of the newly added Uize.values static method of the Uize base module.

Uize.Data.getValues >> BECOMES >> Uize.values

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.7. Uize.Data.isEmpty -- DEPRECATED 2011-11-13

The Uize.Data.isEmpty static method has been deprecated in favor of the newly added Uize.isEmpty static method of the Uize base module.

Uize.Data.isEmpty >> BECOMES >> Uize.isEmpty

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.8. Uize.Data.map -- DEPRECATED 2011-11-27

The Uize.Data.map static method has been deprecated in favor of the newly added Uize.map static method of the Uize base module.

This method has been promoted to the Uize base module, but the arguments signature has been changed. While the deprecated Uize.Data.map method accepts a mapper expression or function as its first argument and an array, object, or number as its second argument, these two arguments are swapped around in the Uize.map method. This is the more conventional signature for map type methods.

INSTEAD OF...

mappedARRAYorOBJ = Uize.Data.map (mapperSTRorFUNC,sourceARRAYorOBJorINT);

USE...

mappedARRAYorOBJ = Uize.map (sourceARRAYorOBJorINT,mapperSTRorFUNC);

Other than the change in its arguments signature, the Uize.map behaves in exactly the same way as the deprecated Uize.Data.map method. Because the Uize.Data.map method has been deprecated, it will live on for about another year, continuing to behave in the same way and using the same signature as before.

3.9. Uize.Data.max -- DEPRECATED 2011-11-13

The Uize.Data.max static method has been deprecated in favor of the newly added Uize.max static method of the Uize base module.

Uize.Data.max >> BECOMES >> Uize.max

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

3.10. Uize.Data.min -- DEPRECATED 2011-11-13

The Uize.Data.min static method has been deprecated in favor of the newly added Uize.min static method of the Uize base module.

Uize.Data.min >> BECOMES >> Uize.min

This method has been promoted to the Uize base module, retaining exactly the same arguments signature and behavior.

4. Static Properties

4.1. Uize.Data.moduleName

IMPLEMENTATION INFO

this feature was introduced in this module