diff options
Diffstat (limited to 'src/formatters.js')
| -rw-r--r-- | src/formatters.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/formatters.js b/src/formatters.js new file mode 100644 index 00000000..ee63c1a5 --- /dev/null +++ b/src/formatters.js @@ -0,0 +1,23 @@ +function formater(format, parse) {return {'format':format, 'parse':parse || format};} +function toString(obj) {return isDefined(obj) ? "" + obj : obj;} +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; + } + ), + + 'trim':formater( + function(obj) { return obj ? trim("" + obj) : ""; } + ) +}); |
