unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
28 lines • 1.01 kB
JavaScript
const camelToSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
const snakeToCamelCase = (str) => str.replace(/(_\w)/g, (letter) => letter[1].toUpperCase());
/**
* This helper function turns all fields in the item object from camelCase to snake_case
*
* @param item is the input object
* @returns a modified version of item with all fields in snake_case
*/
export const defaultToRow = (item) => {
const row = {};
Object.entries(item).forEach(([key, value]) => {
row[camelToSnakeCase(key)] = value;
});
return row;
};
/**
* This helper function turns all fields in the row object from snake_case to camelCase
* @param row is the input object
* @returns a modified version of row with all fields in camelCase
*/
export const defaultFromRow = (row) => {
const model = {};
Object.entries(row).forEach(([key, value]) => {
model[snakeToCamelCase(key)] = value;
});
return model;
};
//# sourceMappingURL=default-mappings.js.map