Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function createTranslatedComputedProperty(translationKey, options) {
const hash = options || new EmptyObject();
const [dynamicValues, staticValues] = partitionDynamicValuesAndStaticValues(hash);
const dependentKeys = Object.values(dynamicValues);
return intl(...dependentKeys, (intl, propertyKey, ctx) =>
intl.t(translationKey, assign({}, staticValues, mapPropertiesByHash(ctx, dynamicValues)))
);
}
function mapPropertiesByHash(object, hash) {
const result = new EmptyObject();
Object.keys(hash).forEach(key => {
result[key] = get(object, hash[key]);
});
return result;
}
function partitionDynamicValuesAndStaticValues(options) {
const dynamicValues = new EmptyObject();
const staticValues = new EmptyObject();
Object.keys(options).forEach(key => {
const value = options[key];
if (value instanceof Raw) {
staticValues[key] = value.valueOf();
} else {
dynamicValues[key] = value;
}
});
return [dynamicValues, staticValues];
}
function partitionDynamicValuesAndStaticValues(options) {
const dynamicValues = new EmptyObject();
const staticValues = new EmptyObject();
Object.keys(options).forEach(key => {
const value = options[key];
if (value instanceof Raw) {
staticValues[key] = value.valueOf();
} else {
dynamicValues[key] = value;
}
});
return [dynamicValues, staticValues];
}