angular.js/src/formatters.js

24 lines
684 B
JavaScript
Raw Normal View History

function formater(format, parse) {return {'format':format, 'parse':parse || format};}
2010-04-04 00:04:36 +00:00
function toString(obj) {return isDefined(obj) ? "" + obj : obj;}
2010-01-29 06:10:49 +00:00
extend(angularFormatter, {
'noop':formater(identity, identity),
'boolean':formater(toString, toBoolean),
'number':formater(toString, function(obj){return 1*obj;}),
'list':formater(
function(obj) { return obj ? obj.join(", ") : obj; },
function(value) {
var list = [];
foreach((value || '').split(','), function(item){
item = trim(item);
if (item) list.push(item);
});
return list;
2010-01-29 06:10:49 +00:00
}
),
'trim':formater(
function(obj) { return obj ? trim("" + obj) : ""; }
)
2010-01-29 06:10:49 +00:00
});