You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
694 B

import {
Pipe,
PipeTransform
} from '@angular/core';
@Pipe({
name: 'splitmessage'
})
export class SplitMessagePipe implements PipeTransform {
transform(emotes: any[], message: string): any[] {
if (emotes.length == 0) {
return [];
}
let exps = emotes.map(
(emote: any) => emote.title.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
);
let regexp = RegExp('(' + exps.join('|') + ')');
let tokens = message.split(regexp);
return tokens.map((token: any) => {
let e = emotes.filter((emote: any) => emote.title == token);
return e.length > 0 ? e[0] : token;
});
}
}