Replaced all throw (e) calls with logError(). (#122)

Also removed  unused utility functions.

VAN-49
This commit is contained in:
Waheed Ahmed
2021-02-04 20:10:10 +05:00
committed by GitHub
parent c6d45a0fe1
commit 15d774819c
13 changed files with 30 additions and 278 deletions

View File

@@ -1,46 +1,9 @@
import camelCase from 'lodash.camelcase';
import snakeCase from 'lodash.snakecase';
// Utility functions
export function modifyObjectKeys(object, modify) {
// If the passed in object is not an object, return it.
if (
object === undefined
|| object === null
|| (typeof object !== 'object' && !Array.isArray(object))
) {
return object;
}
if (Array.isArray(object)) {
return object.map(value => modifyObjectKeys(value, modify));
}
// Otherwise, process all its keys.
const result = {};
Object.entries(object).forEach(([key, value]) => {
result[modify(key)] = modifyObjectKeys(value, modify);
});
return result;
}
export function camelCaseObject(object) {
return modifyObjectKeys(object, camelCase);
}
export function snakeCaseObject(object) {
return modifyObjectKeys(object, snakeCase);
}
export function convertKeyNames(object, nameMap) {
const transformer = key => (nameMap[key] === undefined ? key : nameMap[key]);
return modifyObjectKeys(object, transformer);
}
export const processLink = (link) => {
export default function processLink(link) {
let matches;
link.replace(/(.*?)<a href=["']([^"']*).*?>([^<]+)<\/a>(.*)/g, function () { // eslint-disable-line func-names
matches = Array.prototype.slice.call(arguments, 1, 5); // eslint-disable-line prefer-rest-params
});
return matches;
};
}