abrs-translator
v1.0.1
Published
Translate the array or object to desired format.
Downloads
3
Readme
abrs-translator
Using for translate the objects into one structure another structure
Example
// Define the input object
const inputObject = {
name: "John Doe",
age: 30,
city: "New York",
};
// Define the configuration object
const config = {
nameTranslated: "name",
ageTranslated: "age",
cityTranslated: "city",
nameLookup: "name123",
};
// Define the callbacks object
const callbacks = {
nameTranslated: capitalizeFirstLetter,
};
// Define the specific callback function
function capitalizeFirstLetter(value) {
return value.charAt(0).toUpperCase() + value.slice(1);
}
// Call the translation function with the input object, configuration, and default callback
const outputObject = translate(inputObject, config, callbacks);
// Print the output object
console.log(outputObject);
// Deal with array of objects input
const inputArray = [
{
name: "John Doe",
age: 30,
city: "New York",
},
{
name: "Jane Doe",
age: 25,
city: "Los Angeles",
},
];
// Call the translation function with the input array, configuration, and default callback
const outputArray = translate(inputArray, config, callbacks, null, true);
// Print the output array
console.log(outputArray);