var define = require('amdefine')(module)
}
-define([], function () {
+define(['lodash'], function (_) {
function handleNestedFields(object, key, params, paramType) {
var attributes = key.split('.');
return result
}
+ function tryParsingAsType(object, path, type) {
+ var val = _.get(object, path);
+ if (val !== undefined) {
+ if (type === 'Boolean') {
+ if (val === 'true') {
+ _.set(object, path, true);
+ } else if (val === 'false') {
+ _.set(object, path, false);
+ } else {
+ console.warn('Failed to parse object value at path [' + path + ']. Value: (' + val + '). Type: (' + type + ')');
+ }
+ } else if (type === 'Number') {
+ var parsedInt = parseInt(val, 10);
+ if (!_.isNaN(parsedInt)) {
+ _.set(object, path, parsedInt);
+ } else {
+ console.warn('Failed to parse object value at path [' + path + ']. Value: (' + val + '). Type: (' + type + ')');
+ }
+ }
+ }
+ }
+
function handleNestedAndParsingFields(param, paramType) {
var result = handleArraysAndObjectFields(param, paramType);
result = handleNestedFieldsForAllParams(result, paramType);
return result;
}
- return {handleNestedAndParsingFields};
+ function tryParsingWithTypes(param, paramType) {
+ var result = Object.assign({}, param);
+ Object.keys(paramType).forEach(function (key) {
+ tryParsingAsType(result, key, paramType[key]);
+ });
+ return result;
+ }
+
+ // Converts path params in the {param} format to the accepted :param format, used before inserting the URL params.
+ function convertPathParams(url) {
+ return url.replace(/{(.+?)}/g, ':$1');
+ }
+
+ return {handleNestedAndParsingFields,convertPathParams,tryParsingWithTypes};
});