Enforcing DataTypes

DataSchema supports a parser property that enforces type conversion on data as the schema is being applied. The parser property can point to one of the following types of parsing functions:

Basic example

Data
{
    "results":[
        {"string":"aardvark", "number":"1", "date":"Jan 1, 2001"},
        {"string":"bat", "number":"2", "date":"Feb 2, 2002"},
        {"string":"camel", "number":"3", "date":"March 3, 2003"}
    ]
}
    
Schema
{
    resultListLocator: "results",
    resultFields: [
        "string", // needs no parsing
        {key:"number", parser: "number"}, // point to built-in shortcut
        {key:"date", parser: Y.DataType.Date.parse}] // point to function
}
    
Normalized data