Closed TheJaredWilcurt closed 1 month ago
The regex should match against all of these:
const obj = {
v: function v(value){
return ['234'].includes(value);
},
w(value) {
return [
'asd',
'wer'
].includes(value);
},
x: function (value) {
return [123, true, 'yui'].includes(value);
},
y: (value) => {
return ['3gf', 'cf'].includes(value);
},
z: v => ['oiu', 'gfd', 'dfg'].includes(v)
};
It is a pretty common pattern for props that only allow specific values to have a validator function like this:
We can access the props and validator programmatically with
component.props.myProp.validator
.We can convert the validator to a string with
'' + fn
.Then we could write some regex to check to see if the validator follows this predictable pattern, and if so extract the part of the string representing the array, then parse it to JSON and use it on the
allowed
part of the Props Documentation.The code for this should probably live in the
/lib/components/PropsDocumentation.vue
file.