2018-03-13 09:14:55 +08:00
|
|
|
|
2018-05-04 04:07:16 +08:00
|
|
|
const rivets = require('rivets');
|
2018-03-13 09:14:55 +08:00
|
|
|
|
2018-05-04 04:07:16 +08:00
|
|
|
/**
|
|
|
|
* Generic formatter to prepend
|
2019-11-19 23:06:07 +08:00
|
|
|
*
|
2018-05-04 04:07:16 +08:00
|
|
|
* @param value
|
|
|
|
* @param prepend
|
2019-11-19 23:06:07 +08:00
|
|
|
*
|
2018-05-04 04:07:16 +08:00
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
rivets.formatters.prepend = function (value, prepend) {
|
2019-08-30 20:08:00 +08:00
|
|
|
return prepend + value;
|
2018-05-04 04:07:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format minutes into HHh MMm
|
2019-11-19 23:06:07 +08:00
|
|
|
*
|
2018-05-04 04:07:16 +08:00
|
|
|
* @param value
|
2019-11-19 23:06:07 +08:00
|
|
|
*
|
2018-05-04 04:07:16 +08:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
rivets.formatters.time_hm = function (value) {
|
|
|
|
const hours = Math.floor(value / 60);
|
|
|
|
const mins = value % 60;
|
|
|
|
return `${hours}h ${mins}m`;
|
2018-05-04 04:07:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param value
|
|
|
|
* @param len
|
2019-11-19 23:06:07 +08:00
|
|
|
*
|
2018-05-04 04:07:16 +08:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
rivets.formatters.gt = (value, len) => value.length > len;
|
2018-05-04 04:07:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param value
|
|
|
|
* @param len
|
2019-11-19 23:06:07 +08:00
|
|
|
*
|
2018-05-04 04:07:16 +08:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
rivets.formatters.lt = (value, len) => value.length < len;
|
2018-05-04 04:07:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param value
|
|
|
|
* @param len
|
2019-11-19 23:06:07 +08:00
|
|
|
*
|
2018-05-04 04:07:16 +08:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
rivets.formatters.eq = (value, len) => value.length > len;
|
2019-11-19 23:06:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use a default value if value is null or blank
|
|
|
|
*
|
|
|
|
* @param value Value to use
|
|
|
|
* @param def Default value to use if value is null
|
|
|
|
*/
|
|
|
|
rivets.formatters.fallback = (value, def) => value || def;
|