mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
refactor(toJson): remove breaking change from previous CL
Closes #10297
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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}');
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user