You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Background
Currently, minimist-options supports type: array. However, the values of the array are always parsed as 'string'. yargs/yargs-parser (which are minimist backwards compatible) have support for coercing values 'number' and 'boolean' as well (see opts.array under yargs-parser API).
Proposal
Therefore, I would like to see minimist-options supporting these types too.
Considerations
I have considered the following options for how that could look:
Add another property elementType: 'number'|'boolean' (potentially arrayElementType to tie it more to array). This would only be allowed when having type: array.
Extend type with support for ['number'] and ['boolean'].
Extend type with support for 'number-array' and 'boolean-array' (camelCasing possible if preferred).
Extend type with support for numbers and booleans. Note: plural.
Extend type with support for { type: 'array', elementType: 'number|boolean' }.
Note: Additionally, 'string' would of course be a valid element type.
#1 is explicit, but verbose, introduces an extra property which would only be valid under certain conditions (which is always a little "blah" and adds complexity).
#2 is a little magical, but I like how terse it is and find it quite expressive/intuitive when you look at it. ”Aha, it’s an array of (number|boolean)s”.
#3 would introduce magical (made-up) strings. Not very fond of.
#4 is probably the simplest of them all. My only concern is: is it distinct enough or too easy to mix up?
#5 Using an object is always neat, but having to specify type: 'array' again feels weird as it would be the only valid value, but leaving it out would be odd too.
I'm leaning towards #2 or #4.
Any other suggestions?
Backwards compatibility
To be backwards compatible and not break existing code bases, I suggest we still keep type: array and its behavior intact.
@vadimdemedes Went ahead and implemented it. Hope you get around to have a look sometime soon. Would be much appreciated to have this merged (in some form). Thanks!
Background
Currently,
minimist-options
supportstype: array
. However, the values of the array are always parsed as'string'
.yargs/yargs-parser
(which areminimist
backwards compatible) have support for coercing values'number'
and'boolean'
as well (seeopts.array
underyargs-parser
API).Proposal
Therefore, I would like to see
minimist-options
supporting these types too.Considerations
I have considered the following options for how that could look:
elementType: 'number'|'boolean'
(potentiallyarrayElementType
to tie it more toarray
). This would only be allowed when havingtype: array
.type
with support for['number']
and['boolean']
.type
with support for'number-array'
and'boolean-array'
(camelCasing possible if preferred).type
with support fornumbers
andbooleans
. Note: plural.type
with support for{ type: 'array', elementType: 'number|boolean' }
.Note: Additionally,
'string'
would of course be a valid element type.#1
is explicit, but verbose, introduces an extra property which would only be valid under certain conditions (which is always a little "blah" and adds complexity).#2
is a little magical, but I like how terse it is and find it quite expressive/intuitive when you look at it. ”Aha, it’s an array of (number|boolean)s”.#3
would introduce magical (made-up) strings. Not very fond of.#4
is probably the simplest of them all. My only concern is: is it distinct enough or too easy to mix up?#5
Using an object is always neat, but having to specifytype: 'array'
again feels weird as it would be the only valid value, but leaving it out would be odd too.I'm leaning towards
#2
or#4
.Any other suggestions?
Backwards compatibility
To be backwards compatible and not break existing code bases, I suggest we still keep
type: array
and its behavior intact.@vadimdemedes What say you?
The text was updated successfully, but these errors were encountered: