ironwing
Version:
Ironwing is a lightweight front-end data library for model like data representations
75 lines (60 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.toCamel = toCamel;
exports.syncObjects = syncObjects;
exports.checkURL = checkURL;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _lodashStringCamelCase = require('lodash/string/camelCase');
var _lodashStringCamelCase2 = _interopRequireDefault(_lodashStringCamelCase);
/**
* Convert all object attrs to camelCase naming convetsion
* @param {Object} obj
* @return {Object}
*/
function toCamel(obj) {
var newObj = {};
for (var key in obj) {
if (typeof obj[key] === 'object') {
obj[key] = toCamel(obj[key]);
}
newObj[(0, _lodashStringCamelCase2['default'])(key)] = obj[key];
}
return newObj;
}
/**
* [__syncObjects description] draft
* @param {[type]} obj [description]
* @param {[type]} camledObj [description]
* @return {[type]} [description]
*/
function syncObjects(obj, newObj) {
for (var key in obj) {
if (typeof obj[key] === 'object') {
obj[key] = syncObjects(obj[key], newObj[(0, _lodashStringCamelCase2['default'])(key)]);
} else {
obj[key] = newObj[(0, _lodashStringCamelCase2['default'])(key)];
}
}
return obj;
}
/**
* Check if an URL starts and ends with /
* @param {String} string URL
* @return {String} The fixed URL string
*/
function checkURL(string) {
if (typeof string !== 'string') {
return '/';
}
if (string[string.length - 1] !== '/') {
string += '/';
}
if (/http/.test(string)) {
return string;
} else if (string[0] !== '/' && string[0] !== '.') {
string = '/' + string;
}
return string;
}