UNPKG

1.12 kBPlain TextView Raw
1import { IHtmlEngineHelper } from './html-engine-helper.interface';
2import * as Handlebars from 'handlebars';
3
4export class ParsePropertyHelper implements IHtmlEngineHelper {
5 public helperFunc(context: any, text: string) {
6 let prop: any = text;
7
8 if (!!text && text.constructor === Object && text['url'] !== undefined) {
9 prop = text['url'];
10 }
11
12 if (!!text && text.constructor === Object && text['name'] !== undefined) {
13 prop = text['name'];
14 }
15
16 if (!!text && text.constructor === Object && Object.keys(text).length === 0) {
17 prop = '';
18 }
19
20 if (prop instanceof String && prop !== '' && prop.indexOf('https') !== -1) {
21 return `<a href="${prop}" target="_blank">${prop}</a>`;
22 } else if (prop !== '' && prop instanceof Array && prop.length > 0) {
23 prop = JSON.stringify(prop);
24 prop = prop.replace(/","/g, ', ');
25 prop = prop.replace(/\["/g, '');
26 prop = prop.replace(/"]/g, '');
27 return prop;
28 } else {
29 return prop;
30 }
31 }
32}