Registering a type or structure instead of just a format
Closed this issue · 3 comments
damienleroux commented
Hi gcanti,
I begin using tcomb-json-format. what do you think about registering a type or structure instead of just a format
Here is my use case:
/**
* Generate a tComb string type with a format limiting maxlength
* @param {tComb.Num} maxLength
*/
function stringDynamic(maxLength: tComb.Num){
return tComb.subtype(tComb.Str, function (s) {
return s.length < maxLength;
}, 'STRING' + maxLength);
}
//example
transform.registerType('string10', stringDynamic(10));
var TcombType = transform({
"type": "object",
"properties": {
"Name": {
"type": "string10"
}
});
Actually this allows the user to define is own types and structures and there then is no need to define the data "format" that might be redundant with the data "type".
Thank you
gcanti commented
Hi @damienleroux,
Seems a good idea, thanks.
Do you want to submit a PR or I go for it?
damienleroux commented
I'll submit a PR asap. Thank you
gcanti commented