ecency-mobile/src/utils/formatter.js

29 lines
795 B
JavaScript
Raw Normal View History

export const getPostSummary = (postBody, length, isQuote) => {
if (!postBody) {
return '';
}
postBody = postBody
.replace(/(<([^>]+)>)/gi, '') // Remove html tags
.replace(/\r?\n|\r/g, ' ') // Remove new lines
.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '') // Remove urls
.trim()
.replace(/ +(?= )/g, ''); // Remove all multiple spaces
if (length) {
// Truncate
postBody = postBody.substring(0, length);
}
return isQuote ? `"${postBody}..."` : `${postBody}...`;
};
export const makeCountFriendly = (value) => {
if (!value) return value;
if (value >= 1000000) return `${intlFormat(value / 1000000)}M`;
if (value >= 1000) return `${intlFormat(value / 1000)}K`;
return intlFormat(value);
};
2018-12-28 15:20:08 +03:00
const intlFormat = num => Math.round(num * 10) / 10;