aboutsummaryrefslogtreecommitdiffstats
path: root/src/formatters.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/formatters.js')
-rw-r--r--src/formatters.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/formatters.js b/src/formatters.js
index ee63c1a5..40462cf3 100644
--- a/src/formatters.js
+++ b/src/formatters.js
@@ -1,11 +1,20 @@
-function formater(format, parse) {return {'format':format, 'parse':parse || format};}
-function toString(obj) {return isDefined(obj) ? "" + obj : obj;}
+function formatter(format, parse) {return {'format':format, 'parse':parse || format};}
+function toString(obj) {return (isDefined(obj) && obj !== null) ? "" + obj : obj;}
+
+var NUMBER = /^\s*[-+]?\d*(\.\d*)?\s*$/;
+
extend(angularFormatter, {
- 'noop':formater(identity, identity),
- 'boolean':formater(toString, toBoolean),
- 'number':formater(toString, function(obj){return 1*obj;}),
+ 'noop':formatter(identity, identity),
+ 'boolean':formatter(toString, toBoolean),
+ 'number':formatter(toString,
+ function(obj){
+ if (isString(obj) && NUMBER.exec(obj)) {
+ return obj ? 1*obj : null;
+ }
+ throw "Not a number";
+ }),
- 'list':formater(
+ 'list':formatter(
function(obj) { return obj ? obj.join(", ") : obj; },
function(value) {
var list = [];
@@ -17,7 +26,7 @@ extend(angularFormatter, {
}
),
- 'trim':formater(
+ 'trim':formatter(
function(obj) { return obj ? trim("" + obj) : ""; }
)
});