aboutsummaryrefslogtreecommitdiffstats
path: root/src/JSON.js
diff options
context:
space:
mode:
authorVojta Jina2010-11-05 23:14:44 +0000
committerIgor Minar2010-11-05 21:39:00 -0700
commit5be325a0c1a660268d29541bc668d9cb7d641fcb (patch)
tree927c0672c68a1fcacf594d8acee8ffdf0f864940 /src/JSON.js
parentb7027b9d8755604799781313e9bbd8eee72fc4f4 (diff)
downloadangular.js-5be325a0c1a660268d29541bc668d9cb7d641fcb.tar.bz2
Refactored toJsonArray(), added isBoolean() function
Diffstat (limited to 'src/JSON.js')
-rw-r--r--src/JSON.js21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/JSON.js b/src/JSON.js
index 50f63dec..de718527 100644
--- a/src/JSON.js
+++ b/src/JSON.js
@@ -1,6 +1,6 @@
var array = [].constructor;
-function toJson(obj, pretty){
+function toJson(obj, pretty) {
var buf = [];
toJsonArray(buf, obj, pretty ? "\n " : _null, []);
return buf.join('');
@@ -35,37 +35,36 @@ function toJsonArray(buf, obj, pretty, stack) {
}
if (includes(stack, obj)) {
- buf.push("RECURSION");
+ buf.push('RECURSION');
return;
}
stack.push(obj);
}
- var type = typeof obj;
if (obj === _null) {
buf.push($null);
} else if (obj instanceof RegExp) {
buf.push(angular['String']['quoteUnicode'](obj.toString()));
- } else if (type === $function) {
+ } else if (isFunction(obj)) {
return;
- } else if (type === $boolean) {
+ } else if (isBoolean(obj)) {
buf.push('' + obj);
- } else if (type === $number) {
+ } else if (isNumber(obj)) {
if (isNaN(obj)) {
buf.push($null);
} else {
buf.push('' + obj);
}
- } else if (type === $string) {
+ } else if (isString(obj)) {
return buf.push(angular['String']['quoteUnicode'](obj));
- } else if (type === $object) {
- if (obj instanceof Array) {
+ } else if (isObject(obj)) {
+ if (isArray(obj)) {
buf.push("[");
var len = obj.length;
var sep = false;
for(var i=0; i<len; i++) {
var item = obj[i];
if (sep) buf.push(",");
- if (!(item instanceof RegExp) && (typeof item == $function || typeof item == $undefined)) {
+ if (!(item instanceof RegExp) && (isFunction(item) || isUndefined(item))) {
buf.push($null);
} else {
toJsonArray(buf, item, pretty, stack);
@@ -104,7 +103,7 @@ function toJsonArray(buf, obj, pretty, stack) {
buf.push("}");
}
}
- if (typeof obj == $object) {
+ if (isObject(obj)) {
stack.pop();
}
}