Skip to content

Commit 90d922d

Browse files
committed
Merge pull request #25 from mollwe/master
Fixed functions displayed incorrectly when function definitions exists within function.
2 parents 87ac552 + 2f041ed commit 90d922d

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

dist/json-formatter.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* jsonformatter
33
*
4-
* Version: 0.2.7 - 2015-06-05T21:24:58.724Z
4+
* Version: 0.3.0 - 2015-07-09T13:22:11.385Z
55
* License: MIT
66
*/
77

dist/json-formatter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* jsonformatter
33
*
4-
* Version: 0.2.7 - 2015-06-05T21:37:16.993Z
4+
* Version: 0.3.0 - 2015-07-09T13:22:11.371Z
55
* License: MIT
66
*/
77

@@ -114,8 +114,8 @@ angular.module('jsonFormatter', ['RecursionHelper'])
114114

115115
// Remove content of the function
116116
return scope.json.toString()
117-
.replace(/\n/g, '')
118-
.replace(/\{.+?\}/, '') + '{ ... }';
117+
.replace(/[\r\n]/g, '')
118+
.replace(/\{.*\}/, '') + '{ ... }';
119119

120120
}
121121
return value;

dist/json-formatter.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/json-formatter.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/json-formatter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ angular.module('jsonFormatter', ['RecursionHelper'])
106106

107107
// Remove content of the function
108108
return scope.json.toString()
109-
.replace(/\n/g, '')
110-
.replace(/\{.+?\}/, '') + '{ ... }';
109+
.replace(/[\r\n]/g, '')
110+
.replace(/\{.*\}/, '') + '{ ... }';
111111

112112
}
113113
return value;

test/json-formatter.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ describe('json-formatter', function () {
1717
scope._function = function add(a, b) {
1818
return a + b;
1919
};
20+
scope.promiseFunction = function getAdd(service, a) {
21+
return service.get(a).then(function (b) {
22+
return a + b;
23+
});
24+
};
2025
scope.string = 'Hello world!';
2126
scope.date = (new Date(0)).toString(); // begging of Unix time
2227
scope.url = 'https://example.com';
@@ -68,6 +73,17 @@ describe('json-formatter', function () {
6873
expect(element.text()).toContain('function');
6974
expect(element.text()).toContain('add');
7075
expect(element.text()).toContain('(a, b)');
76+
expect(element.text().match(/function\s[^\(]*\([^\)]*\)\s*(.*)/)[1]).toBe('{ ... }');
77+
});
78+
});
79+
80+
describe('promiseFunction', function(){
81+
it('should render the function', function () {
82+
element = createDirective('promiseFunction');
83+
expect(element.text()).toContain('function');
84+
expect(element.text()).toContain('getAdd');
85+
expect(element.text()).toContain('(service, a)');
86+
expect(element.text().match(/function\s[^\(]*\([^\)]*\)\s*(.*)/)[1]).toBe('{ ... }');
7187
});
7288
});
7389

0 commit comments

Comments
 (0)