-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(jsonFilter): add optional arg to define custom indentation #9771
Changes from 4 commits
a240e86
534142c
beeadb5
352e10a
5029cd2
86a1ab7
f6f16d5
b1fac2b
91878ae
8a0bbfe
22c6aac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -503,25 +503,28 @@ function dateFilter($locale) { | |
* the binding is automatically converted to JSON. | ||
* | ||
* @param {*} object Any JavaScript object (including arrays and primitive types) to filter. | ||
* @param {number=} the number of spaces to use per indentation, defaults to 2. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a param name (i.e. spacing) before the description. |
||
* @returns {string} JSON string. | ||
* | ||
* | ||
* @example | ||
<example> | ||
<file name="index.html"> | ||
<pre>{{ {'name':'value'} | json }}</pre> | ||
<pre id="default-spacing">{{ {'name':'value'} | json }}</pre> | ||
<pre id="custom-spacing">{{ {'name':'value'} | json:4 }}</pre> | ||
</file> | ||
<file name="protractor.js" type="protractor"> | ||
it('should jsonify filtered objects', function() { | ||
expect(element(by.binding("{'name':'value'}")).getText()).toMatch(/\{\n "name": ?"value"\n}/); | ||
expect(element(by.id('default-spacing')).getText()).toMatch(/\{\n "name": ?"value"\n}/); | ||
expect(element(by.id('custom-spacing')).getText()).toMatch(/\{\n "name": ?"value"\n}/); | ||
}); | ||
</file> | ||
</example> | ||
* | ||
*/ | ||
function jsonFilter() { | ||
return function(object) { | ||
return toJson(object, true); | ||
return function(object, spacing) { | ||
return toJson(object, spacing || true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No 0-space indentation here either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I'll fix that too now. |
||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little far-fetched, but you can't use pretty-printing with 0-space indentation.
Just saying...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right, I didn't think of that edge case, will push a slight refactor.