Skip to content

Return value should be an array, not an objectΒ #181

@bartveneman

Description

@bartveneman

The current data structure isn't very useful without any form of metadata for each metric. It should be an Array, or something that's easily tranformed into an array that makes sense.

Idea credit: Parker.js (🎩 @katiefenn)

❌ Current structure

const result = {
  'stylesheets.size': 1,
  'declarations.total': 2
}

βœ… Proposed structure

const FORMATS = {
  STRING: 'string',
  RATIO: 'ratio',
  FILESIZE: 'filesize',
  COUNT: 'integer',
}

const AGGREGATES = {
	SUM: 'sum',
	AVERAGE: 'average',
	MAX: 'max',
	MIN: 'min',
	LIST: 'list',
}

const result = {
  'stylesheets.size': {
    id: 'stylesheets.size', // duplication, but very convenient
    name: 'Filesize (bytes)',
    aggregate: AGGREGATES.SUM,
    format: FORMATS.FILESIZE,
    value: 2376, // The actual value that we're interested in
  },
}

🎁 Advantages

  1. Easy to see how to interpret or consume a metric. Especially for other services that rely on these metrics.
  2. Easy to turn into an array with Object.values(result). Also easy to get back the 'old' style result with Object.entries.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions