projects/ngx-linkifyjs/src/lib/service/ngx-linkifyjs.service.ts
Methods |
constructor()
|
find | ||||||||
find(text: string)
|
||||||||
Find any links in a given text as a string
Parameters :
Returns :
Array<Link>
|
linkify | ||||||||||||
linkify(text: string, options?: NgxLinkifyOptions)
|
||||||||||||
Convert the passed text as a string to an appropriate url
Parameters :
Returns :
string
|
test | ||||||||
test(value: string | string[])
|
||||||||
Test if a given value or array of values are links
Parameters :
Returns :
boolean
|
import {Injectable} from '@angular/core';
// @ts-ignore
import * as linkify from 'linkifyjs';
// @ts-ignore
// import * as linkifyStr from 'linkifyjs/string';
import linkifyStr from 'linkifyjs/string';
// @ts-ignore
import {Link, NgxLinkifyOptions} from '../interfaces/ngx-linkifyjs.interface';
@Injectable()
export class NgxLinkifyjsService {
constructor() {
}
/**
* Convert the passed text as a string to an appropriate url
*
* @param text - the string to convert
* @param options - options to pass it to the linkifyjs library
*/
linkify(text: string, options?: NgxLinkifyOptions): string {
// @ts-ignore
return linkifyStr(text, options);
// return '';
}
/**
* Find any links in a given text as a string
*
* @param text - the string to find some links
*/
find(text: string): Array<Link> {
return linkify.find(text);
}
/**
* Test if a given value or array of values are links
*
* @param value - the value to test
*/
test(value: string | string[]): boolean {
if (typeof value === 'string') {
return linkify.test(value);
}
return linkify.test(...value);
}
}