Class: MetaSerializer

MetaSerializer()

Serializer for converting SubstanceMetadata objects to CSV format. This class handles the conversion of SubstanceMetadata arrays to CSV-compatible Maps and generates data URIs for browser downloads. The CSV format follows the specification defined in the import_export_meta task.

Constructor

new MetaSerializer()

Source:

Methods

deserialize(arrayOfMaps) → {SubstanceMetadataParseResult}

Convert array of Maps to structured result with SubstanceMetadata for CSV import. Each Map represents a CSV row with column names as keys and string values. Boolean fields are converted from string representation to boolean values. Empty or missing values are handled gracefully with defaults. Parsing errors are collected and returned in the result rather than throwing exceptions.
Parameters:
Name Type Description
arrayOfMaps Array.<Map.<string, string>> Array of Maps with CSV data
Source:
Returns:
Result containing parsed metadata and errors
Type
SubstanceMetadataParseResult

deserializeMetaFromCsvString(csvString) → {SubstanceMetadataParseResult}

Convert CSV string to structured result with SubstanceMetadataUpdate for import. Uses Papa Parse to parse CSV string with headers into objects, then converts to SubstanceMetadataUpdate instances. The CSV key column is used as the oldName to identify existing substances for updates. Parsing errors are collected and returned in the result rather than throwing exceptions.
Parameters:
Name Type Description
csvString string CSV content string with headers
Source:
Returns:
Result containing parsed updates and errors
Type
SubstanceMetadataParseResult

renderMetaToCsvUri(metadataArray) → {string}

Create data URI with CSV content for download. This method serializes the metadata array to CSV format and wraps it in a data URI that can be used for browser downloads. The CSV format includes proper header row and RFC 4180 compliant escaping.
Parameters:
Name Type Description
metadataArray Array.<SubstanceMetadata> Array of metadata objects
Source:
Returns:
Data URI string (data:text/csv;charset=utf-8,...)
Type
string

serialize(metadataArray) → {Array.<Map.<string, string>>}

Convert array of SubstanceMetadata to array of Maps for CSV export. Each Map represents a CSV row with column names as keys and string values. The column structure matches the specification: substance, equipment, application, ghg, hasDomestic, hasImport, hasExport, energy, initialChargeDomestic, initialChargeImport, initialChargeExport, retirement, key.
Parameters:
Name Type Description
metadataArray Array.<SubstanceMetadata> Array of metadata objects
Source:
Returns:
Array of Maps with CSV column mappings
Type
Array.<Map.<string, string>>