rsuite / schema-typed

Schema for data modeling & validation
MIT License
198 stars 28 forks source link

Something like a "map" Datatype #47

Closed TheFive closed 2 years ago

TheFive commented 2 years ago

I would like to use your tool to check my config input for consistency with the expectation :-). They contain a lot of key value pairs (sometimes called maps), so i just want to check for that user type, that ALL key have one defined datatype.

Is there a little bit more sophistic solution than this

const model = SchemaModel({
  map: ObjectType().addRule((value, data) => {
    let result = true;
    for (const k in value) {
      if (typeof value[k] != "string") result = false; 
    }
    return result;
  },"must be a set of keys with strings as values")
});

What would be nice, to use your type checking possiblities, so not the native ones, and the error message is now for the complete map and not for the key. As i although have maps of config objects a recursion would be great.

TheFive commented 2 years ago

Sorry, missed rsuite is a user interface builder library, close my question