silfverorg / duns.js

Javascript schema validator
5 stars 2 forks source link

array().format() should return whole array - not single items #27

Closed silfverstrom closed 9 years ago

silfverstrom commented 9 years ago

This allows for more powerful expressions, returning part of a array etc. There should also be a formatter that returns single values,

br0r commented 9 years ago

Started implementing a formatter for returning singleValues but then I realized that it would be pretty weird.

What will happen when you have a .returns and a .itemsReturns. Something needs to be run first? Won't that be more confusing than useful? If you want to reuse some formatter that is implemented on singleValues you could simply do something like:

var schema = Duns.string().returns((val) => val + '!');
Duns.array().returns((val) => {
  return schema.init(val).format();
}).format();
silfverstrom commented 9 years ago

Alternatively you could do something like,

Duns.array().returns(Duns.item().string());
/// Where .item wraps everything in a map function?

@br0r

br0r commented 9 years ago

Realized that my example won't actually work. Perhaps .item could be a solution. Would be kind of nice to use it with formatters later on. Perhaps should wait with this functionality until we deal with the default formatters?