normalize-package-data icon indicating copy to clipboard operation
normalize-package-data copied to clipboard

[FEATURE] some should-be-array fields are not guaranteed to be an array

Open myrne opened this issue 11 years ago • 6 comments

Not guaranteed to be array: keywords, contributors, authors, man. Guaranteed to be array (if set): files

myrne avatar Apr 29 '13 21:04 myrne

This is problematic when people call array functions on it. forEach, join, etc.

myrne avatar Apr 29 '13 21:04 myrne

@isaacs Are you ok with setting data.keywords to an empty array if it's anything else than a string (will be split) or an array (left alone)? I see no downsides.

myrne avatar May 02 '13 13:05 myrne

Same applies for data.man.

myrne avatar May 02 '13 14:05 myrne

Or maybe, rather than setting it to empty array, simply delete the property. For example, data.files is currently deleted if it exists and is not an array.

myrne avatar May 02 '13 14:05 myrne

The "people" fields (data.contributors and data.authors) are currently left alone if not an array.

myrne avatar May 02 '13 14:05 myrne

In general, there's a trade-off between "API simplicity" (i.e. does a consumer need to do .isArray() first?) and maintaining any ("malformed") data that's there.

I think a choice should be made. Either all fields get the same treatment, or some fields are excepted due to some kind of special status.

myrne avatar May 02 '13 14:05 myrne