Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
refactor(toJson): remove breaking change from previous CL
Browse files Browse the repository at this point in the history
Closes #10297
  • Loading branch information
caitp committed Dec 2, 2014
1 parent 7daf4e0 commit 9a616ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
4 changes: 3 additions & 1 deletion test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand All @@ -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}');
});


Expand Down

0 comments on commit 9a616ea

Please sign in to comment.