Skip to content

Commit

Permalink
docs(apimock): add comments on serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
seriema committed Oct 18, 2015
1 parent 9252f71 commit d213af2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/scripts/angular-apimock.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,23 @@ angular.module('apiMock', [])

function serialize(toSerialize, prefix, topLevel) {
if (angular.isArray(toSerialize)) {
// Serialize arrays.
angular.forEach(toSerialize, function (value, index) {
serialize(value, prefix + '[' + (angular.isObject(value) ? index : '') + ']');
});
} else if (angular.isObject(toSerialize) && !angular.isDate(toSerialize)) {
// Serialize objects (not dates, because that's covered by the default case).
forEachSorted(toSerialize, function (value, key) {
serialize(value, prefix +
(topLevel ? '' : '[') +
key +
(topLevel ? '' : ']'));
});
} else if (toSerialize === undefined || toSerialize === '') {
// Keep empty parameters as it still affects the mock file path.
parts.push(encodeUriQuery(prefix));
} else {
// Serialize everything else (including dates).
parts.push(encodeUriQuery(prefix) + '=' + encodeUriQuery(serializeValue(toSerialize)));
}
}
Expand Down

0 comments on commit d213af2

Please sign in to comment.