2018-12-02 15:32:45 +03:00
|
|
|
export const getPostSummary = (postBody, length, isQuote) => {
|
2018-09-30 03:37:26 +03:00
|
|
|
if (!postBody) {
|
2018-10-04 05:18:36 +03:00
|
|
|
return '';
|
2018-09-30 03:37:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
postBody = postBody
|
2018-10-04 05:18:36 +03:00
|
|
|
.replace(/(<([^>]+)>)/gi, '') // Remove html tags
|
|
|
|
.replace(/\r?\n|\r/g, ' ') // Remove new lines
|
|
|
|
.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '') // Remove urls
|
2018-09-30 03:37:26 +03:00
|
|
|
.trim()
|
2018-10-04 05:18:36 +03:00
|
|
|
.replace(/ +(?= )/g, ''); // Remove all multiple spaces
|
2018-09-30 03:37:26 +03:00
|
|
|
|
|
|
|
if (length) {
|
|
|
|
// Truncate
|
|
|
|
postBody = postBody.substring(0, length);
|
|
|
|
}
|
2018-12-02 15:32:45 +03:00
|
|
|
return isQuote ? `"${postBody}..."` : `${postBody}...`;
|
2018-09-30 03:37:26 +03:00
|
|
|
};
|
2018-12-26 14:49:21 +03:00
|
|
|
|
|
|
|
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;
|