Description
🙋 feature request
Add support config schemas with ranges & restrictions to only integers for config schemas.
🤔 Expected Behavior
The feature would allow specifying optional number properties min
and max
values for a schema entity of type number
for restricting the range, as well as an optional boolean property integer
to indicate if it must be an integer (the default, undefined case is the same as false
).
😯 Current Behavior
Currently, the config schema only supports declaring a schema with a predefined set of numbers, via the enum
property:
parcel/packages/core/utils/src/schema.js
Lines 47 to 51 in 86bddb4
However, this property is not that useful, as all the possible values must be listed out manually.
💁 Possible Solution
I'm going to open a PR in a few which adds support, because it's not that many lines of change.
🔦 Context
An example usecase is the @parcel/transformer-image plugin:
parcel/packages/transformers/image/src/validateConfig.js
Lines 6 to 50 in 86bddb4
For many of these properties, there are range restrictions on them. However, there are too many values to realistically list all of them. Take quality
for example, it must be in the range of 1-100, however listing all integers from 1 to 100 would be rather tedious.
So, it would be much better if instead it could be specified as the following:
properties: {
quality: {
type: 'number',
min: 1,
max: 100,
integer: true,
},
...
}
This would restrict it to only integers in the range of 1-100.