refactor(toJson): remove breaking change from previous CL

Closes #10297
This commit is contained in:
Caitlin Potter
2014-12-02 15:43:03 -05:00
parent 7daf4e0125
commit 9a616eade4
2 changed files with 7 additions and 2 deletions

View File

@@ -970,7 +970,10 @@ function toJsonReplacer(key, value) {
*/
function toJson(obj, pretty) {
if (typeof obj === 'undefined') return undefined;
return JSON.stringify(obj, toJsonReplacer, pretty === true ? 2 : pretty);
if (!isNumber(pretty)) {
pretty = pretty ? 2 : null;
}
return JSON.stringify(obj, toJsonReplacer, pretty);
}

View File

@@ -1189,7 +1189,7 @@ describe('angular', function() {
});
iit('should format objects pretty', function() {
it('should format objects pretty', function() {
expect(toJson({a: 1, b: 2}, true)).
toBe('{\n "a": 1,\n "b": 2\n}');
expect(toJson({a: {b: 2}}, true)).
@@ -1200,6 +1200,8 @@ describe('angular', function() {
toBe('{"a":1,"b":2}');
expect(toJson({a: 1, b: 2}, 1)).
toBe('{\n "a": 1,\n "b": 2\n}');
expect(toJson({a: 1, b: 2}, {})).
toBe('{\n "a": 1,\n "b": 2\n}');
});