Skip to content

Commit

Permalink
Merge pull request #25 from mollwe/master
Browse files Browse the repository at this point in the history
Fixed functions displayed incorrectly when function definitions exists within function.
  • Loading branch information
mohsen1 committed Jul 9, 2015
2 parents 87ac552 + 2f041ed commit 90d922d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/json-formatter.css
@@ -1,7 +1,7 @@
/*!
* jsonformatter
*
* Version: 0.2.7 - 2015-06-05T21:24:58.724Z
* Version: 0.3.0 - 2015-07-09T13:22:11.385Z
* License: MIT
*/

Expand Down
6 changes: 3 additions & 3 deletions dist/json-formatter.js
@@ -1,7 +1,7 @@
/*!
* jsonformatter
*
* Version: 0.2.7 - 2015-06-05T21:37:16.993Z
* Version: 0.3.0 - 2015-07-09T13:22:11.371Z
* License: MIT
*/

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

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

}
return value;
Expand Down
2 changes: 1 addition & 1 deletion dist/json-formatter.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/json-formatter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/json-formatter.js
Expand Up @@ -106,8 +106,8 @@ angular.module('jsonFormatter', ['RecursionHelper'])

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

}
return value;
Expand Down
16 changes: 16 additions & 0 deletions test/json-formatter.spec.js
Expand Up @@ -17,6 +17,11 @@ describe('json-formatter', function () {
scope._function = function add(a, b) {
return a + b;
};
scope.promiseFunction = function getAdd(service, a) {
return service.get(a).then(function (b) {
return a + b;
});
};
scope.string = 'Hello world!';
scope.date = (new Date(0)).toString(); // begging of Unix time
scope.url = 'https://example.com';
Expand Down Expand Up @@ -68,6 +73,17 @@ describe('json-formatter', function () {
expect(element.text()).toContain('function');
expect(element.text()).toContain('add');
expect(element.text()).toContain('(a, b)');
expect(element.text().match(/function\s[^\(]*\([^\)]*\)\s*(.*)/)[1]).toBe('{ ... }');
});
});

describe('promiseFunction', function(){
it('should render the function', function () {
element = createDirective('promiseFunction');
expect(element.text()).toContain('function');
expect(element.text()).toContain('getAdd');
expect(element.text()).toContain('(service, a)');
expect(element.text().match(/function\s[^\(]*\([^\)]*\)\s*(.*)/)[1]).toBe('{ ... }');
});
});

Expand Down

0 comments on commit 90d922d

Please sign in to comment.