This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(jsonFilter): add optional arg to define custom indentation #9771
Closed
+16
−6
Closed
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a240e86
feat(jsonFilter): add optional arg to define custom indentation
doshprompt 534142c
tests(jsonFilter): fix typo
doshprompt beeadb5
test(toJson): missing new operator when invoking constructor
doshprompt 352e10a
test(jsonFilter): missing optional arg for new test
doshprompt 5029cd2
feat(toJson): don't allow pretty json formatting with 0 indentation
doshprompt 86a1ab7
feat(jsonFilter): don't rely on default spacing of toJson function
doshprompt f6f16d5
test(jsonFilter): add unit test for new functionality of custom inden…
doshprompt b1fac2b
fix(toJson): minification error
doshprompt 91878ae
fix(toJson): minification error
doshprompt 8a0bbfe
feat(toJson): cleanup spacing logic
doshprompt 22c6aac
feat(jsonFilter): new logic of toJson implemented
doshprompt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -503,25 +503,29 @@ 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) { | ||
if (isUndefined(spacing)) spacing = 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. if (isUndefined(spacing)) {
spacing = 2;
} |
||
return toJson(object, spacing); | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,9 @@ describe('filters', function() { | |
it('should do basic filter', function() { | ||
expect(filter('json')({a:"b"})).toEqual(toJson({a:"b"}, true)); | ||
}); | ||
it('should allow custom indentation', function() { | ||
expect(filter('json')({a:"b"}, 4)).toEqual(toJson({a:"b"}, 4)); | ||
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. I don't really like how we're using |
||
}); | ||
}); | ||
|
||
describe('lowercase', function() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this line isn't needed ---
JSON.stringify
will convert numbers into the right number of spaces on its own.