File

projects/ngx-linkifyjs/src/lib/service/ngx-linkifyjs.service.ts

Index

Methods

Constructor

constructor()

Methods

find
find(text: string)

Find any links in a given text as a string

Parameters :
Name Type Optional Description
text string No
  • the string to find some links
Returns : Array<Link>
linkify
linkify(text: string, options?: NgxLinkifyOptions)

Convert the passed text as a string to an appropriate url

Parameters :
Name Type Optional Description
text string No
  • the string to convert
options NgxLinkifyOptions Yes
  • options to pass it to the linkifyjs library
Returns : string
test
test(value: string | string[])

Test if a given value or array of values are links

Parameters :
Name Type Optional Description
value string | string[] No
  • the value to test
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);
  }

}

result-matching ""

    No results matching ""