2023-04-07 18:15:15 +03:00
|
|
|
import {countDownCharacters} from './gh-count-down-characters';
|
|
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
|
|
|
|
export default helper(function (params) {
|
|
|
|
let [content, maxCharacters] = params;
|
|
|
|
|
2023-04-11 18:49:00 +03:00
|
|
|
if (!content) {
|
|
|
|
// Protect against NULL content
|
|
|
|
content = '';
|
|
|
|
}
|
|
|
|
|
2023-04-07 18:15:15 +03:00
|
|
|
// Strip HTML-tags and characters from content so we have a reliable character count
|
|
|
|
content = content.replace(/<[^>]*>?/gm, '');
|
|
|
|
content = content.replace(/ /g, ' ');
|
|
|
|
content = content.replace(/&/g, '&');
|
|
|
|
content = content.replace(/"/g, '"');
|
|
|
|
content = content.replace(/</g, '<');
|
|
|
|
content = content.replace(/>/g, '>');
|
|
|
|
|
|
|
|
return countDownCharacters([content, maxCharacters]);
|
|
|
|
});
|