Beside the built-in format methods, you can define your own format methods.
Also you can override existing format methods by providing one with the same name.
import { extend } from 'riot-format';
extend('yesno', function(value) {
return !!value ? 'yes' : 'no';
});
let's use this method
<app>
<p>should display yes: {format(1, 'yesno')}</p>
<p>should display no: {format(null, 'yesno')}</p>
<p>or use like this: {format(1).yesno()}</p>
</app>
Note: it should be easy to understand how it works if you are familiar with pipes.
define another method
import { extend } from 'riot-format';
extend('isToday', function(value) {
if (value) {
var date = (value instanceof Date) ? value : new Date(value);
if (!isNaN(date)) {
var now = new Date();
if (('' + date.getYear() + date.getMonth() + date.getDate()) === ('' + now.getYear() + now.getMonth() + now.getDate())) {
return true;
}
}
}
return false;
});
use it
<app>
<p>should display true: {format(new Date().toString()).date().isToday()}</p>
</app>