Add ability to do typechecking and conversion on the values of key-value options #1032
+77
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds optional type checking and conversion to the
keyvalueOptions()
function. Currently, theallowed
argument gives an object that says what keys are allowed (ones with non-zero values in that object). Here, we extend the use of theallowed
object to provide data for type checking and converting the values of the given keys.This is done through a new
KeyValueType
object that hasvalidate()
andconvert()
methods (and a name, for potential error reporting). There is aKeyValueTypeDefinition()
function that makes creating these objects easier, and aKeyValueTypes
object that holds predefined definitions for the standard types (boolean, number, string) and some variations (integer, dimen, andoneof()
that gives a collection of valid option for the string). These seem to be a good base set of definitions, but you can create your own custom types with more detailed checker and converter, as needed.We aren't currently using this feature now, but it would be useful in the siunitx extension that I am reviewing for PCC now.
A similar idea may also be useful for making the option checking more robust in the future (in
util/Options.ts
), where we only do key name checking, but not type checking currently.