UNPKG

ngx-linkifyjs-v2

Version:

Angular wrapper for linkifyjs - library for finding links in plain text and converting them to HTML <a> tags via linkifyjs

123 lines (115 loc) 4.73 kB
import * as i0 from '@angular/core'; import { Pipe, Injectable, InjectionToken, Inject, NgModule } from '@angular/core'; import linkifyStr from 'linkify-string'; import * as linkify from 'linkifyjs'; import { CommonModule } from '@angular/common'; var LinkType; (function (LinkType) { LinkType["URL"] = "url"; LinkType["HASHTAG"] = "hashtag"; LinkType["MENTION"] = "mention"; LinkType["EMAIL"] = "email"; })(LinkType || (LinkType = {})); class NgxLinkifyjsPipe { transform(value, options) { return value ? linkifyStr(value, options) : value; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsPipe, isStandalone: false, name: "linkify" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsPipe, decorators: [{ type: Pipe, args: [{ name: 'linkify', standalone: false }] }] }); 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, options) { return linkifyStr(text, options); } /** * Find any links in a given text as a string * * @param text - the string to find some links */ find(text) { return linkify.find(text); } /** * Test if a given value is a link or an array of all links * * @param value - the value to test */ test(value) { if (typeof value === 'string') { return linkify.test(value); } return value.find(v => !linkify.test(v)) === undefined; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsService, decorators: [{ type: Injectable }], ctorParameters: () => [] }); const NgxLinkifyjsConfigToken = new InjectionToken('NgxLinkifyjsConfig'); const DEFAULT_CONFIG = { enableHash: true, enableMention: true }; class NgxLinkifyjsModule { config; static forRoot(config = DEFAULT_CONFIG) { return { ngModule: NgxLinkifyjsModule, providers: [ NgxLinkifyjsService, { provide: NgxLinkifyjsConfigToken, useValue: config }, ] }; } constructor(config) { this.config = config; // TODO REMOVE ME // if (config.enableHash) { // hashtag(linkify); // } // // if (config.enableMention) { // mention(linkify); // } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsModule, deps: [{ token: NgxLinkifyjsConfigToken }], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsModule, declarations: [NgxLinkifyjsPipe], imports: [CommonModule], exports: [NgxLinkifyjsPipe] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.11", ngImport: i0, type: NgxLinkifyjsModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule ], exports: [NgxLinkifyjsPipe], declarations: [NgxLinkifyjsPipe] }] }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [NgxLinkifyjsConfigToken] }] }] }); /* * Public API Surface of ngx-linkifyjs */ /** * Generated bundle index. Do not edit. */ export { DEFAULT_CONFIG, LinkType, NgxLinkifyjsConfigToken, NgxLinkifyjsModule, NgxLinkifyjsPipe, NgxLinkifyjsService }; //# sourceMappingURL=ngx-linkifyjs-v2.mjs.map