normalize-package-data
normalize-package-data copied to clipboard
[FEATURE] some should-be-array fields are not guaranteed to be an array
Not guaranteed to be array: keywords, contributors, authors, man. Guaranteed to be array (if set): files
This is problematic when people call array functions on it. forEach
, join
, etc.
@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.
Same applies for data.man
.
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.
The "people" fields (data.contributors
and data.authors
) are currently left alone if not an array.
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.