Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{formatReferenceValue(attribute, truncateHash(value), value, onClickPrimaryKey)}
);
} else if (dataType === AttrbuteDataType.HASH) {
return (
{formatReferenceValue(attribute, truncateHash(value), value, onClickPrimaryKey)}
);
} else if (dataType === AttrbuteDataType.DECIMAL || dataType === AttrbuteDataType.INT || dataType === AttrbuteDataType.CURRENCY) {
return formatNumber(Number(value), attribute);
} else if (dataType === AttrbuteDataType.STRING && value.length > 100) {
return (
{value.substring(0, 100)}
);
} else if (dataType === AttrbuteDataType.STRING && value.length > 0 && attribute.cardinality && attribute.cardinality < 20) {
return value.split('_').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(' ');
} else {
return formatReferenceValue(attribute, value, value, onClickPrimaryKey);
}
};
);
} else if (dataType === AttrbuteDataType.HASH) {
const hash = formatReferenceValue(attribute, (truncate ? truncateHash(value) : value), value, onClickPrimaryKey);
return (
{hash}
);
} else if (dataType === AttrbuteDataType.DECIMAL || dataType === AttrbuteDataType.INT || dataType === AttrbuteDataType.CURRENCY) {
return formatNumber(Number(value), attribute, truncate);
} else if (dataType === AttrbuteDataType.STRING && value.length > 100) {
return (
{value.substring(0, 100)}
);
} else if (dataType === AttrbuteDataType.STRING && value.length > 0 && attribute.cardinality && attribute.cardinality < 20) {
return value.split('_').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(' ');
} else {
return formatReferenceValue(attribute, value, value, onClickPrimaryKey);
}
};
export const formatNumber = (value: number, attribute: AttributeDefinition, truncate: boolean = true) => {
if (value === undefined) { return ''; }
let t = '';
if (attribute.dataType === AttrbuteDataType.INT) {
t = (new Intl.NumberFormat(window.navigator.languages[0], { style: 'decimal', useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 1 })).format(value);
} else if (attribute.scale !== undefined && (attribute.dataType === AttrbuteDataType.DECIMAL || attribute.dataType === AttrbuteDataType.CURRENCY)) {
const d = value / Math.pow(10, attribute.scale);
let minimumFractionDigits = 0;
let maximumFractionDigits = 0;
if (!truncate) {
minimumFractionDigits = 6;
maximumFractionDigits = 6;
} else if (value < 10000) {
minimumFractionDigits = 6;
maximumFractionDigits = 6;
} else if (value < 100000) {
minimumFractionDigits = 4;
maximumFractionDigits = 4;
} else if (value < 1000000000) {
minimumFractionDigits = 2;
const formatAggregatedValue = (attribute: AttributeDefinition, value: any, aggregation: ConseilFunction) => {
let aggregationAttribute = { ...attribute };
switch (aggregation) {
case ConseilFunction.count:
aggregationAttribute.dataType = AttrbuteDataType.INT;
break;
default:
aggregationAttribute.dataType = attribute.dataType === AttrbuteDataType.CURRENCY ? AttrbuteDataType.CURRENCY : AttrbuteDataType.DECIMAL;
break;
}
return formatNumber(Number(value), aggregationAttribute);
}
const formatAggregatedValue = (attribute: AttributeDefinition, value: any, aggregation: ConseilFunction) => {
let aggregationAttribute = { ...attribute };
switch (aggregation) {
case ConseilFunction.count:
aggregationAttribute.dataType = AttrbuteDataType.INT;
break;
default:
aggregationAttribute.dataType = attribute.dataType === AttrbuteDataType.CURRENCY ? AttrbuteDataType.CURRENCY : AttrbuteDataType.DECIMAL;
break;
}
return formatNumber(Number(value), aggregationAttribute);
}