silfverorg / duns.js

Javascript schema validator
5 stars 2 forks source link

Add formatter methods #4

Open silfverstrom opened 9 years ago

silfverstrom commented 9 years ago

It would be convenient if Duns provides various formatting methods out of the box, that can be chained into a formatting method

var Schema = Duns.string().format(Duns.formatters().trim().proper().custom(function(val) {
return val + ' !!';
});
//Validates as string, formatts with trim/proper and custom.
silfverstrom commented 9 years ago

ping @br0r - what do you think? Include this in 0.1?

br0r commented 9 years ago

Not sure. I like the idea, but the functionality seems rather ambiguous. For strings it would be great to implement underscore.string. But don't really see any other types of standard formatting cases as of now.

Perhaps the main focus for 0.1, should be on validation with a basic formatting option, to verify the usability and use-cases of the transform property. That way we could have a more informed discussion about what to actually implement.

silfverstrom commented 9 years ago

Perhaps - lets focus on implementing a format method, and take it from there. I'll leave this as a idea-issue.

br0r commented 9 years ago

After further consideration I've realised that Typecasting formatters would be very useful. Therefore we should perhaps look into it, at least until a 0.2 release.

silfverstrom commented 9 years ago

I agree - also adding support for normal formatting of numbers, percentage/hextonumber etc would be nice. Tag this to 0.2?