Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Last active August 21, 2020 06:37
Show Gist options
  • Save velotiotech/972ee9dc0cfbcae341c1dab4ab794442 to your computer and use it in GitHub Desktop.
Save velotiotech/972ee9dc0cfbcae341c1dab4ab794442 to your computer and use it in GitHub Desktop.
// API Response
[{
symbol: 'SIC DIVISION',
exchange: 'Agricultural services',
volume: 42232,
}]
// Required format
[{
category: 'Agricultural services',
name: 'SIC DIVISION',
y: 42232,
}]
const mapping = {
symbol: 'category',
exchange: 'name',
volume: 'y',
};
const highchartsAdapter = (response, mapping) => {
return response.map(item => {
const normalized = {};
// Normalize each response's item key, according to the mapping
Object.keys(item).forEach(key => (normalized[mapping[key]] = item[key]));
return normalized;
});
};
highchartsAdapter(response, mapping);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment