@code-name-jack/ngx-linkifyjs 20.0.1 → 20.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,24 +1,587 @@
1
- # NgxLinkifyjs
1
+ # ngx-linkifyjs
2
2
 
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.
3
+ [![npm version](https://badge.fury.io/js/ngx-linkifyjs.svg)](https://badge.fury.io/js/ngx-linkifyjs)
4
+ [![license](https://img.shields.io/github/license/anthonynahas/ngx-linkifyjs.svg?style=flat-square)](https://github.com/AnthonyNahas/ngx-linkifyjs/blob/master/LICENSE)
4
5
 
5
- ## Code scaffolding
6
+ > **Angular 20+ wrapper for linkifyjs** - Automatically find and convert URLs, emails, hashtags, and mentions in text to HTML links.
6
7
 
7
- Run `ng generate component component-name --project ngx-linkifyjs-v2` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-linkifyjs-v2`.
8
- > Note: Don't forget to add `--project ngx-linkifyjs-v2` or else it will be added to the default project in your `angular.json` file.
8
+ <p align="center">
9
+ <img alt="ngx-linkifyjs demo" width="320px" style="text-align: center;"
10
+ src="https://cdn.jsdelivr.net/gh/anthonynahas/ngx-linkifyjs@master/assets/demo.gif">
11
+ </p>
9
12
 
10
- ## Build
13
+ ## ✨ Features
11
14
 
12
- Run `ng build ngx-linkifyjs-v2` to build the project. The build artifacts will be stored in the `dist/` directory.
15
+ - 🔗 **Auto-detect URLs** - Finds and linkifies URLs (with or without protocol)
16
+ - 📧 **Email addresses** - Converts emails to `mailto:` links
17
+ - #️⃣ **Hashtags** - Linkify hashtags for social media content
18
+ - @ **Mentions** - Convert @mentions to links
19
+ - 🎨 **Customizable** - Full control over link styling and behavior
20
+ - 🚀 **Angular 20+** - Built for modern Angular with standalone-first architecture
21
+ - 📦 **Tree-shakeable** - Optimized bundle size
22
+ - 🔧 **TypeScript** - Full type safety
13
23
 
14
- ## Publishing
24
+ ## 🎮 Live Demo
15
25
 
16
- After building your library with `ng build ngx-linkifyjs-v2`, go to the dist folder `cd dist/ngx-linkifyjs-v2` and run `npm publish --access=public`.
26
+ A comprehensive demo application is available in the [repository](https://github.com/code-name-jack/ngx-linkifyjs-v2) showcasing:
27
+ - 🎨 Interactive examples with live editing
28
+ - 🔧 Service API demonstrations
29
+ - ⚙️ Configuration options showcase
30
+ - 📝 Copy-paste code examples
17
31
 
18
- ## Running unit tests
32
+ ---
19
33
 
20
- Run `ng test ngx-linkifyjs-v2` to execute the unit tests via [Karma](https://karma-runner.github.io).
34
+ ## 📦 Installation
21
35
 
22
- ## Further help
36
+ ### Option 1: Using Angular Schematics (Recommended)
23
37
 
24
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
38
+ ```bash
39
+ ng add @code-name-jack/ngx-linkifyjs
40
+ ```
41
+
42
+ ### Option 2: Using npm
43
+
44
+ ```bash
45
+ npm install @code-name-jack/ngx-linkifyjs
46
+ ```
47
+
48
+ ---
49
+
50
+ ## 🚀 Quick Start
51
+
52
+ **1. Configure in your app (app.config.ts):**
53
+
54
+ ```typescript
55
+ import { ApplicationConfig } from '@angular/core';
56
+ import { provideNgxLinkifyjs } from '@code-name-jack/ngx-linkifyjs';
57
+
58
+ export const appConfig: ApplicationConfig = {
59
+ providers: [
60
+ provideNgxLinkifyjs({
61
+ enableHash: true, // Enable hashtag detection
62
+ enableMention: true // Enable @mention detection
63
+ })
64
+ ]
65
+ };
66
+ ```
67
+
68
+ **2. Import the pipe in your component:**
69
+
70
+ ```typescript
71
+ import { Component } from '@angular/core';
72
+ import { NgxLinkifyjsPipe } from '@code-name-jack/ngx-linkifyjs';
73
+
74
+ @Component({
75
+ selector: 'app-example',
76
+ standalone: true,
77
+ imports: [NgxLinkifyjsPipe],
78
+ template: `
79
+ <div [innerHTML]="text | linkify"></div>
80
+ `
81
+ })
82
+ export class ExampleComponent {
83
+ text = 'Visit https://github.com or email info@example.com';
84
+ }
85
+ ```
86
+
87
+ **3. Using the service:**
88
+
89
+ ```typescript
90
+ import { Component, inject } from '@angular/core';
91
+ import { NgxLinkifyjsService } from '@code-name-jack/ngx-linkifyjs';
92
+
93
+ @Component({
94
+ selector: 'app-example',
95
+ standalone: true
96
+ })
97
+ export class ExampleComponent {
98
+ private linkifyService = inject(NgxLinkifyjsService);
99
+
100
+ constructor() {
101
+ // Find all links
102
+ const links = this.linkifyService.find('Visit github.com');
103
+ // Output: [{ type: 'url', value: 'github.com', href: 'http://github.com' }]
104
+
105
+ // Test if text contains links
106
+ const hasLinks = this.linkifyService.test('example.com'); // true
107
+
108
+ // Convert text to HTML
109
+ const html = this.linkifyService.linkify('Visit example.com');
110
+ }
111
+ }
112
+ ```
113
+
114
+ > **Note:** Since `NgxLinkifyjsService` uses `providedIn: 'root'`, it's automatically available once you add `provideNgxLinkifyjs()` to your app config. The `provideNgxLinkifyjs()` function is only needed to configure plugin options (hashtags/mentions).
115
+
116
+ ---
117
+
118
+ ## 📖 Usage Guide
119
+
120
+ ### Using the Pipe
121
+
122
+ The `linkify` pipe transforms text into linkified HTML:
123
+
124
+ ```html
125
+ <!-- Basic usage -->
126
+ <p [innerHTML]="'Visit https://example.com' | linkify"></p>
127
+
128
+ <!-- With custom options -->
129
+ <p [innerHTML]="text | linkify:options"></p>
130
+ ```
131
+
132
+ ```typescript
133
+ import { NgxLinkifyOptions } from '@code-name-jack/ngx-linkifyjs';
134
+
135
+ export class MyComponent {
136
+ text = 'Check out github.com and follow @angular!';
137
+
138
+ options: NgxLinkifyOptions = {
139
+ className: 'custom-link',
140
+ target: { url: '_blank' },
141
+ defaultProtocol: 'https'
142
+ };
143
+ }
144
+ ```
145
+
146
+ ### Using the Service
147
+
148
+ The `NgxLinkifyjsService` provides programmatic access to linkify functionality:
149
+
150
+ #### 1️⃣ `linkify(text: string, options?: NgxLinkifyOptions): string`
151
+
152
+ Converts text to linkified HTML string.
153
+
154
+ ```typescript
155
+ const html = this.linkifyService.linkify(
156
+ 'Visit github.com or email support@example.com',
157
+ {
158
+ className: 'my-link',
159
+ target: { url: '_blank' }
160
+ }
161
+ );
162
+ // Output: 'Visit <a href="http://github.com" class="my-link" target="_blank">github.com</a> or email <a href="mailto:support@example.com" class="my-link">support@example.com</a>'
163
+ ```
164
+
165
+ #### 2️⃣ `find(text: string): Link[]`
166
+
167
+ Finds all links in text and returns an array of link objects.
168
+
169
+ ```typescript
170
+ const links = this.linkifyService.find(
171
+ 'Visit github.com or email test@example.com #angular'
172
+ );
173
+ // Output:
174
+ // [
175
+ // { type: 'url', value: 'github.com', href: 'http://github.com' },
176
+ // { type: 'email', value: 'test@example.com', href: 'mailto:test@example.com' },
177
+ // { type: 'hashtag', value: '#angular', href: '#angular' }
178
+ // ]
179
+ ```
180
+
181
+ #### 3️⃣ `test(value: string | string[]): boolean`
182
+
183
+ Tests if a string (or all strings in an array) contains valid links.
184
+
185
+ ```typescript
186
+ this.linkifyService.test('github.com'); // true
187
+ this.linkifyService.test('hello world'); // false
188
+ this.linkifyService.test(['github.com', 'test.com']); // true
189
+ this.linkifyService.test(['github.com', 'hello']); // false
190
+ ```
191
+
192
+ ---
193
+
194
+ ## ⚙️ Configuration Options
195
+
196
+ ### Available Options (`NgxLinkifyOptions`)
197
+
198
+ All options are optional and follow the [linkifyjs options](https://linkify.js.org/docs/options.html):
199
+
200
+ ```typescript
201
+ interface NgxLinkifyOptions {
202
+ /**
203
+ * Add custom attributes to links
204
+ */
205
+ attributes?: Record<string, any>;
206
+
207
+ /**
208
+ * CSS class to add to links (default: 'linkified')
209
+ */
210
+ className?: string;
211
+
212
+ /**
213
+ * Default protocol for URLs without one (default: 'http')
214
+ */
215
+ defaultProtocol?: string;
216
+
217
+ /**
218
+ * Event handlers for links
219
+ */
220
+ events?: Record<string, (e: Event) => void>;
221
+
222
+ /**
223
+ * Format the link text
224
+ */
225
+ format?: (value: string, type: string) => string;
226
+
227
+ /**
228
+ * Format the href attribute
229
+ */
230
+ formatHref?: (href: string, type: string) => string;
231
+
232
+ /**
233
+ * HTML tags to ignore when linkifying
234
+ */
235
+ ignoreTags?: string[];
236
+
237
+ /**
238
+ * Convert newlines to <br> tags
239
+ */
240
+ nl2br?: boolean;
241
+
242
+ /**
243
+ * HTML tag to use for links (default: 'a')
244
+ */
245
+ tagName?: string;
246
+
247
+ /**
248
+ * Target attribute for links
249
+ */
250
+ target?: { url: string };
251
+
252
+ /**
253
+ * Validate links before linkifying
254
+ */
255
+ validate?: boolean;
256
+ }
257
+ ```
258
+
259
+ ### Example: Custom Configuration
260
+
261
+ ```typescript
262
+ import { NgxLinkifyOptions } from '@code-name-jack/ngx-linkifyjs';
263
+
264
+ export class MyComponent {
265
+ options: NgxLinkifyOptions = {
266
+ className: 'fancy-link',
267
+ target: { url: '_blank' },
268
+ defaultProtocol: 'https',
269
+
270
+ // Customize link text
271
+ format: (value, type) => {
272
+ if (type === 'url' && value.length > 50) {
273
+ return value.slice(0, 50) + '…';
274
+ }
275
+ return value;
276
+ },
277
+
278
+ // Customize href
279
+ formatHref: (href, type) => {
280
+ if (type === 'hashtag') {
281
+ return 'https://twitter.com/hashtag/' + href.slice(1);
282
+ }
283
+ return href;
284
+ },
285
+
286
+ // Add custom attributes
287
+ attributes: {
288
+ rel: 'noopener noreferrer'
289
+ }
290
+ };
291
+ }
292
+ ```
293
+
294
+ ### Global Configuration
295
+
296
+ Configure hashtag and mention support globally:
297
+
298
+ ```typescript
299
+ // For standalone apps (in app.config.ts)
300
+ import { ApplicationConfig } from '@angular/core';
301
+ import { NgxLinkifyjsService, NgxLinkifyjsConfigToken } from '@code-name-jack/ngx-linkifyjs';
302
+
303
+ export const appConfig: ApplicationConfig = {
304
+ providers: [
305
+ NgxLinkifyjsService,
306
+ {
307
+ provide: NgxLinkifyjsConfigToken,
308
+ useValue: {
309
+ enableHash: true, // Enable #hashtag detection
310
+ enableMention: true // Enable @mention detection
311
+ }
312
+ }
313
+ ]
314
+ };
315
+
316
+ // In app.config.ts
317
+ import { provideNgxLinkifyjs } from '@code-name-jack/ngx-linkifyjs';
318
+
319
+ export const appConfig: ApplicationConfig = {
320
+ providers: [
321
+ provideNgxLinkifyjs({
322
+ enableHash: false, // Disable hashtags
323
+ enableMention: false // Disable mentions
324
+ })
325
+ ]
326
+ };
327
+ ```
328
+
329
+ ---
330
+
331
+ ## 🎨 Styling Links
332
+
333
+ Add custom CSS to style your linkified links:
334
+
335
+ ```css
336
+ /* Default linkified class */
337
+ .linkified {
338
+ color: #0066cc;
339
+ text-decoration: underline;
340
+ }
341
+
342
+ .linkified:hover {
343
+ color: #0052a3;
344
+ }
345
+
346
+ /* Custom class from options */
347
+ .custom-link {
348
+ color: #667eea;
349
+ font-weight: 600;
350
+ text-decoration: none;
351
+ border-bottom: 2px solid transparent;
352
+ transition: all 0.2s;
353
+ }
354
+
355
+ .custom-link:hover {
356
+ border-bottom-color: #667eea;
357
+ }
358
+ ```
359
+
360
+ ---
361
+
362
+ ## 🔍 Link Types
363
+
364
+ The library detects four types of links:
365
+
366
+ | Type | Example | Output |
367
+ |------|---------|--------|
368
+ | **URL** | `https://example.com` | `<a href="https://example.com">...</a>` |
369
+ | **Email** | `user@example.com` | `<a href="mailto:user@example.com">...</a>` |
370
+ | **Hashtag** | `#angular` | `<a href="#angular">#angular</a>` |
371
+ | **Mention** | `@username` | `<a href="/username">@username</a>` |
372
+
373
+ > 💡 **Note:** Hashtags and mentions are enabled by default but can be disabled in configuration.
374
+
375
+ ---
376
+
377
+ ## 📱 Real-World Examples
378
+
379
+ ### Social Media Posts
380
+
381
+ ```typescript
382
+ @Component({
383
+ template: `
384
+ <div class="post" [innerHTML]="post | linkify:socialOptions"></div>
385
+ `
386
+ })
387
+ export class PostComponent {
388
+ post = 'Check out the new @angular release! 🚀 #Angular20 https://angular.io';
389
+
390
+ socialOptions: NgxLinkifyOptions = {
391
+ target: { url: '_blank' },
392
+ formatHref: (href, type) => {
393
+ if (type === 'hashtag') {
394
+ return `https://twitter.com/hashtag/${href.slice(1)}`;
395
+ }
396
+ if (type === 'mention') {
397
+ return `https://twitter.com/${href.slice(1)}`;
398
+ }
399
+ return href;
400
+ }
401
+ };
402
+ }
403
+ ```
404
+
405
+ ### Comment Section
406
+
407
+ ```typescript
408
+ @Component({
409
+ template: `
410
+ <div class="comment"
411
+ *ngFor="let comment of comments"
412
+ [innerHTML]="comment.text | linkify:commentOptions">
413
+ </div>
414
+ `
415
+ })
416
+ export class CommentsComponent {
417
+ comments = [
418
+ { text: 'Great article! See more at example.com' },
419
+ { text: 'Contact me at john@example.com for details' }
420
+ ];
421
+
422
+ commentOptions: NgxLinkifyOptions = {
423
+ className: 'comment-link',
424
+ target: { url: '_blank' },
425
+ attributes: {
426
+ rel: 'nofollow noopener'
427
+ }
428
+ };
429
+ }
430
+ ```
431
+
432
+ ### Chat Application
433
+
434
+ ```typescript
435
+ @Component({
436
+ selector: 'chat-message',
437
+ template: `
438
+ <div class="message" [innerHTML]="message | linkify"></div>
439
+ `
440
+ })
441
+ export class ChatMessageComponent {
442
+ @Input() message!: string;
443
+ }
444
+ ```
445
+
446
+ ---
447
+
448
+ ## 🧪 Testing
449
+
450
+ When testing components that use ngx-linkifyjs:
451
+
452
+ ```typescript
453
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
454
+ import { NgxLinkifyjsPipe, NgxLinkifyjsService } from '@code-name-jack/ngx-linkifyjs';
455
+
456
+ describe('MyComponent', () => {
457
+ let component: MyComponent;
458
+ let fixture: ComponentFixture<MyComponent>;
459
+
460
+ beforeEach(async () => {
461
+ await TestBed.configureTestingModule({
462
+ imports: [MyComponent, NgxLinkifyjsPipe],
463
+ providers: [NgxLinkifyjsService]
464
+ }).compileComponents();
465
+
466
+ fixture = TestBed.createComponent(MyComponent);
467
+ component = fixture.componentInstance;
468
+ });
469
+
470
+ it('should linkify URLs', () => {
471
+ component.text = 'Visit example.com';
472
+ fixture.detectChanges();
473
+
474
+ const element = fixture.nativeElement;
475
+ expect(element.querySelector('a')).toBeTruthy();
476
+ expect(element.querySelector('a').href).toContain('example.com');
477
+ });
478
+ });
479
+ ```
480
+
481
+ ---
482
+
483
+ ## 📚 API Reference
484
+
485
+ ### Exports
486
+
487
+ ```typescript
488
+ // Provider function (for both standalone and NgModule apps)
489
+ export { provideNgxLinkifyjs }
490
+
491
+ // Standalone pipe
492
+ export { NgxLinkifyjsPipe }
493
+
494
+ // Service
495
+ export { NgxLinkifyjsService }
496
+
497
+ // Types & Interfaces
498
+ export { NgxLinkifyOptions }
499
+ export { NgxLinkifyjsConfig }
500
+ export { Link }
501
+ export { LinkType }
502
+
503
+ // Tokens
504
+ export { NgxLinkifyjsConfigToken }
505
+ export { DEFAULT_CONFIG }
506
+ ```
507
+
508
+ ### Types
509
+
510
+ ```typescript
511
+ interface Link {
512
+ type: string; // 'url' | 'email' | 'hashtag' | 'mention'
513
+ value: string; // Original text
514
+ href: string; // Generated href attribute
515
+ }
516
+
517
+ enum LinkType {
518
+ URL = 'url',
519
+ EMAIL = 'email',
520
+ HASHTAG = 'hashtag',
521
+ MENTION = 'mention'
522
+ }
523
+
524
+ interface NgxLinkifyjsConfig {
525
+ enableHash?: boolean; // Enable hashtag detection (default: true)
526
+ enableMention?: boolean; // Enable mention detection (default: true)
527
+ }
528
+ ```
529
+
530
+ ---
531
+
532
+
533
+ ## 🤝 Contributing
534
+
535
+ Contributions are welcome! Please feel free to submit a Pull Request.
536
+
537
+ For development setup and publishing instructions, see the [Developer Guide](https://github.com/code-name-jack/ngx-linkifyjs-v2/blob/master/projects/ngx-linkifyjs-v2/README.dev.md).
538
+
539
+ ---
540
+
541
+ ## 🐛 Issues & Support
542
+
543
+ - 🐛 [Report bugs](https://github.com/code-name-jack/ngx-linkifyjs-v2/issues)
544
+ - 💡 [Request features](https://github.com/code-name-jack/ngx-linkifyjs-v2/issues)
545
+ - 💬 [Ask questions](https://github.com/code-name-jack/ngx-linkifyjs-v2/discussions)
546
+
547
+ ---
548
+
549
+ ## 📄 License
550
+
551
+ Copyright (c) 2018 Anthony Nahas
552
+ Copyright (c) 2022 Ethan Gerardot
553
+ Copyright (c) 2025 Code Name Jack
554
+
555
+ Licensed under the [MIT License](LICENSE)
556
+
557
+ ---
558
+
559
+ ## 🌟 Show Your Support
560
+
561
+ If this project helped you, please consider:
562
+
563
+ - ⭐ Starring the repository
564
+ - 🐛 Reporting bugs
565
+ - 💡 Suggesting features
566
+ - 📢 Sharing with others
567
+
568
+ ---
569
+
570
+ ## 🔗 Related Projects
571
+
572
+ - [@angular-material-extensions/link-preview](https://github.com/angular-material-extensions/link-preview) - Link preview component using ngx-linkifyjs
573
+ - [linkifyjs](https://linkify.js.org/) - The underlying linkify library
574
+
575
+ ---
576
+
577
+ <p align="center">
578
+ Made with ❤️ for the Angular community
579
+ </p>
580
+
581
+ <p align="center">
582
+ <a href="https://www.jetbrains.com">
583
+ <img src="assets/jetbrains-variant-4_logos/jetbrains-variant-4.png" alt="JetBrains" height="50">
584
+ </a>
585
+ <br>
586
+ <sub>Supported by JetBrains with 1 ALL PRODUCTS PACK OS LICENSE</sub>
587
+ </p>
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Pipe, Injectable, InjectionToken, NgModule } from '@angular/core';
2
+ import { Pipe, Injectable, InjectionToken, makeEnvironmentProviders } from '@angular/core';
3
3
  import linkifyStr from 'linkify-string';
4
4
  import * as linkify from 'linkifyjs';
5
5
 
@@ -13,7 +13,10 @@ var LinkType;
13
13
 
14
14
  class NgxLinkifyjsPipe {
15
15
  transform(value, options) {
16
- return value ? linkifyStr(value, options) : value;
16
+ if (!value) {
17
+ return '';
18
+ }
19
+ return linkifyStr(value, options);
17
20
  }
18
21
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
19
22
  static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsPipe, isStandalone: true, name: "linkify" }); }
@@ -27,83 +30,119 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
27
30
  }] });
28
31
 
29
32
  class NgxLinkifyjsService {
30
- constructor() {
31
- }
32
33
  /**
33
34
  * Convert the passed text as a string to an appropriate url
34
35
  *
35
36
  * @param text - the string to convert
36
37
  * @param options - options to pass it to the linkifyjs library
38
+ * @returns HTML string with linkified URLs, emails, hashtags, and mentions
37
39
  */
38
40
  linkify(text, options) {
41
+ if (!text) {
42
+ return '';
43
+ }
39
44
  return linkifyStr(text, options);
40
45
  }
41
46
  /**
42
47
  * Find any links in a given text as a string
43
48
  *
44
49
  * @param text - the string to find some links
50
+ * @returns Array of Link objects found in the text
45
51
  */
46
52
  find(text) {
53
+ if (!text) {
54
+ return [];
55
+ }
47
56
  return linkify.find(text);
48
57
  }
49
58
  /**
50
59
  * Test if a given value is a link or an array of all links
51
60
  *
52
- * @param value - the value to test
61
+ * @param value - the value to test (string or array of strings)
62
+ * @returns true if all values are valid links, false otherwise
53
63
  */
54
64
  test(value) {
55
65
  if (typeof value === 'string') {
56
66
  return linkify.test(value);
57
67
  }
58
- return value.find(v => !linkify.test(v)) === undefined;
68
+ return value.every(v => linkify.test(v));
59
69
  }
60
70
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
61
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsService }); }
71
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsService, providedIn: 'root' }); }
62
72
  }
63
73
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsService, decorators: [{
64
- type: Injectable
65
- }], ctorParameters: () => [] });
74
+ type: Injectable,
75
+ args: [{ providedIn: 'root' }]
76
+ }] });
66
77
 
78
+ /**
79
+ * Injection token for NgxLinkifyjs configuration
80
+ */
67
81
  const NgxLinkifyjsConfigToken = new InjectionToken('NgxLinkifyjsConfig');
82
+ /**
83
+ * Default configuration for NgxLinkifyjs
84
+ */
68
85
  const DEFAULT_CONFIG = { enableHash: true, enableMention: true };
86
+
69
87
  // Conditionally import plugins based on configuration
70
88
  let pluginsLoaded = false;
71
89
  function loadPlugins(config) {
72
- if (pluginsLoaded)
90
+ if (pluginsLoaded) {
73
91
  return;
92
+ }
93
+ const pluginPromises = [];
74
94
  if (config?.enableHash) {
75
- import('linkify-plugin-hashtag').catch(err => console.error('Failed to load hashtag plugin:', err));
95
+ pluginPromises.push(import('linkify-plugin-hashtag').catch(err => {
96
+ console.error('Failed to load hashtag plugin:', err);
97
+ return null;
98
+ }));
76
99
  }
77
100
  if (config?.enableMention) {
78
- import('linkify-plugin-mention').catch(err => console.error('Failed to load mention plugin:', err));
101
+ pluginPromises.push(import('linkify-plugin-mention').catch(err => {
102
+ console.error('Failed to load mention plugin:', err);
103
+ return null;
104
+ }));
79
105
  }
80
- pluginsLoaded = true;
81
- }
82
- class NgxLinkifyjsModule {
83
- static forRoot(config = DEFAULT_CONFIG) {
84
- loadPlugins(config);
85
- return {
86
- ngModule: NgxLinkifyjsModule,
87
- providers: [
88
- NgxLinkifyjsService,
89
- {
90
- provide: NgxLinkifyjsConfigToken,
91
- useValue: config
92
- }
93
- ]
94
- };
106
+ if (pluginPromises.length > 0) {
107
+ Promise.all(pluginPromises).finally(() => {
108
+ pluginsLoaded = true;
109
+ });
110
+ }
111
+ else {
112
+ pluginsLoaded = true;
95
113
  }
96
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
97
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsModule, imports: [NgxLinkifyjsPipe], exports: [NgxLinkifyjsPipe] }); }
98
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsModule }); }
99
114
  }
100
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgxLinkifyjsModule, decorators: [{
101
- type: NgModule,
102
- args: [{
103
- imports: [NgxLinkifyjsPipe],
104
- exports: [NgxLinkifyjsPipe]
105
- }]
106
- }] });
115
+ /**
116
+ * Provides NgxLinkifyjs services and configuration.
117
+ * Works with both standalone and NgModule-based applications.
118
+ *
119
+ * @param config - Configuration options for enabling hashtag and mention plugins
120
+ * @returns EnvironmentProviders array that can be used in app.config.ts
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * import { provideNgxLinkifyjs } from 'ngx-linkifyjs';
125
+ *
126
+ * export const appConfig: ApplicationConfig = {
127
+ * providers: [
128
+ * provideNgxLinkifyjs({
129
+ * enableHash: true,
130
+ * enableMention: true
131
+ * })
132
+ * ]
133
+ * };
134
+ * ```
135
+ */
136
+ function provideNgxLinkifyjs(config = DEFAULT_CONFIG) {
137
+ loadPlugins(config);
138
+ return makeEnvironmentProviders([
139
+ NgxLinkifyjsService,
140
+ {
141
+ provide: NgxLinkifyjsConfigToken,
142
+ useValue: { ...DEFAULT_CONFIG, ...config }
143
+ }
144
+ ]);
145
+ }
107
146
 
108
147
  /*
109
148
  * Public API Surface of ngx-linkifyjs
@@ -113,5 +152,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
113
152
  * Generated bundle index. Do not edit.
114
153
  */
115
154
 
116
- export { DEFAULT_CONFIG, LinkType, NgxLinkifyjsConfigToken, NgxLinkifyjsModule, NgxLinkifyjsPipe, NgxLinkifyjsService };
155
+ export { DEFAULT_CONFIG, LinkType, NgxLinkifyjsConfigToken, NgxLinkifyjsPipe, NgxLinkifyjsService, provideNgxLinkifyjs };
117
156
  //# sourceMappingURL=code-name-jack-ngx-linkifyjs.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-name-jack-ngx-linkifyjs.mjs","sources":["../../../projects/ngx-linkifyjs-v2/src/lib/enum/linktype.enum.ts","../../../projects/ngx-linkifyjs-v2/src/lib/pipes/ngx-linkifyjs.pipe.ts","../../../projects/ngx-linkifyjs-v2/src/lib/service/ngx-linkifyjs.service.ts","../../../projects/ngx-linkifyjs-v2/src/lib/ngx-linkifyjs.module.ts","../../../projects/ngx-linkifyjs-v2/src/public-api.ts","../../../projects/ngx-linkifyjs-v2/src/code-name-jack-ngx-linkifyjs.ts"],"sourcesContent":["export enum LinkType {\n URL = 'url',\n HASHTAG = 'hashtag',\n MENTION = 'mention',\n EMAIL = 'email',\n}\n","import {Pipe, PipeTransform} from '@angular/core';\nimport {NgxLinkifyOptions} from '../interfaces/ngx-linkifyjs.interface';\nimport linkifyStr from 'linkify-string';\n\n@Pipe({\n name: 'linkify',\n standalone: true\n})\nexport class NgxLinkifyjsPipe implements PipeTransform {\n\n transform(value: string, options?: NgxLinkifyOptions): string {\n return value ? linkifyStr(value, options) : value;\n }\n\n}\n","import {Injectable} from '@angular/core';\nimport * as linkify from 'linkifyjs';\nimport linkifyStr from 'linkify-string';\nimport {Link, NgxLinkifyOptions} from '../interfaces/ngx-linkifyjs.interface';\n\n@Injectable()\nexport class NgxLinkifyjsService {\n constructor() {\n }\n\n /**\n * Convert the passed text as a string to an appropriate url\n *\n * @param text - the string to convert\n * @param options - options to pass it to the linkifyjs library\n */\n linkify(text: string, options?: NgxLinkifyOptions): string {\n return linkifyStr(text, options);\n }\n\n /**\n * Find any links in a given text as a string\n *\n * @param text - the string to find some links\n */\n find(text: string): Array<Link> {\n return linkify.find(text);\n }\n\n /**\n * Test if a given value is a link or an array of all links\n *\n * @param value - the value to test\n */\n test(value: string | string[]): boolean {\n if (typeof value === 'string') {\n return linkify.test(value);\n }\n return value.find(v => !linkify.test(v)) === undefined;\n }\n\n}\n","import {InjectionToken, ModuleWithProviders, NgModule} from '@angular/core';\n\nimport {NgxLinkifyjsService} from './service/ngx-linkifyjs.service';\nimport {NgxLinkifyjsPipe} from './pipes/ngx-linkifyjs.pipe';\n\n// Export module's public API\nexport {Link} from './interfaces/ngx-linkifyjs.interface';\nimport {NgxLinkifyjsConfig} from './interfaces/ngx-linkifyjs.interface';\n\nexport {LinkType} from './enum/linktype.enum';\nexport {NgxLinkifyOptions} from './interfaces/ngx-linkifyjs.interface';\nexport {NgxLinkifyjsPipe} from './pipes/ngx-linkifyjs.pipe';\nexport {NgxLinkifyjsService} from './service/ngx-linkifyjs.service';\n\nexport const NgxLinkifyjsConfigToken = new InjectionToken<NgxLinkifyjsConfig>('NgxLinkifyjsConfig');\nexport const DEFAULT_CONFIG: NgxLinkifyjsConfig = {enableHash: true, enableMention: true};\n\n// Conditionally import plugins based on configuration\nlet pluginsLoaded = false;\n\nfunction loadPlugins(config: NgxLinkifyjsConfig) {\n if (pluginsLoaded) return;\n \n if (config?.enableHash) {\n import('linkify-plugin-hashtag').catch(err => console.error('Failed to load hashtag plugin:', err));\n }\n\n if (config?.enableMention) {\n import('linkify-plugin-mention').catch(err => console.error('Failed to load mention plugin:', err));\n }\n \n pluginsLoaded = true;\n}\n\n@NgModule({\n imports: [NgxLinkifyjsPipe],\n exports: [NgxLinkifyjsPipe]\n})\nexport class NgxLinkifyjsModule {\n\n static forRoot(config: NgxLinkifyjsConfig = DEFAULT_CONFIG): ModuleWithProviders<NgxLinkifyjsModule> {\n loadPlugins(config);\n \n return {\n ngModule: NgxLinkifyjsModule,\n providers: [\n NgxLinkifyjsService,\n {\n provide: NgxLinkifyjsConfigToken,\n useValue: config\n }\n ]\n };\n }\n\n}\n","/*\n * Public API Surface of ngx-linkifyjs\n */\n\nexport * from './lib/enum/linktype.enum';\nexport * from './lib/interfaces/ngx-linkifyjs.interface';\nexport * from './lib/pipes/ngx-linkifyjs.pipe';\nexport * from './lib/service/ngx-linkifyjs.service';\nexport * from './lib/ngx-linkifyjs.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;IAAY;AAAZ,CAAA,UAAY,QAAQ,EAAA;AAClB,IAAA,QAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,QAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,QAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,QAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACjB,CAAC,EALW,QAAQ,KAAR,QAAQ,GAAA,EAAA,CAAA,CAAA;;MCQP,gBAAgB,CAAA;IAE3B,SAAS,CAAC,KAAa,EAAE,OAA2B,EAAA;AAClD,QAAA,OAAO,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,KAAK;IACnD;8GAJW,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA,CAAA;4GAAhB,gBAAgB,EAAA,YAAA,EAAA,IAAA,EAAA,IAAA,EAAA,SAAA,EAAA,CAAA,CAAA;;2FAAhB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAJ5B,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA;AACJ,oBAAA,IAAI,EAAE,SAAS;AACf,oBAAA,UAAU,EAAE;AACb,iBAAA;;;MCDY,mBAAmB,CAAA;AAC9B,IAAA,WAAA,GAAA;IACA;AAEA;;;;;AAKG;IACH,OAAO,CAAC,IAAY,EAAE,OAA2B,EAAA;AAC/C,QAAA,OAAO,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;IAClC;AAEA;;;;AAIG;AACH,IAAA,IAAI,CAAC,IAAY,EAAA;AACf,QA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QAEnB,OAAO;AACL,YAAA,QAAQ,EAAE,kBAAkB;AAC5B,YAAA,SAAS,EAAE;gBACT,mBAAmB;AACnB,gBAAA;AACE,oBAAA,OAAO,EAAE,uBAAuB;AAChC,oBAAA,QAAQ,EAAE;AACX;AACF;SACF;IACH;8GAfW,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;+GAAlB,kBAAkB,EAAA,OAAA,EAAA,CAHnB,gBAAgB,CAAA,EAAA,OAAA,EAAA,CAChB,gBAAgB,CAAA,EAAA,CAAA,CAAA;+GAEf,kBAAkB,EAAA,CAAA,CAAA;;2FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAJ9B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;oBACR,OAAO,EAAE,CAAC,gBAAgB,CAAC;oBAC3B,OAAO,EAAE,CAAC,gBAAgB;AAC3B,iBAAA;;;ACrCD;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"code-name-jack-ngx-linkifyjs.mjs","sources":["../../../projects/ngx-linkifyjs-v2/src/lib/enum/linktype.enum.ts","../../../projects/ngx-linkifyjs-v2/src/lib/pipes/ngx-linkifyjs.pipe.ts","../../../projects/ngx-linkifyjs-v2/src/lib/service/ngx-linkifyjs.service.ts","../../../projects/ngx-linkifyjs-v2/src/lib/constants/ngx-linkifyjs.constants.ts","../../../projects/ngx-linkifyjs-v2/src/lib/providers/ngx-linkifyjs.provider.ts","../../../projects/ngx-linkifyjs-v2/src/public-api.ts","../../../projects/ngx-linkifyjs-v2/src/code-name-jack-ngx-linkifyjs.ts"],"sourcesContent":["export enum LinkType {\n URL = 'url',\n HASHTAG = 'hashtag',\n MENTION = 'mention',\n EMAIL = 'email',\n}\n","import { Pipe, PipeTransform } from '@angular/core';\nimport { NgxLinkifyOptions } from '../interfaces/ngx-linkifyjs.interface';\nimport linkifyStr from 'linkify-string';\n\n@Pipe({\n name: 'linkify',\n standalone: true\n})\nexport class NgxLinkifyjsPipe implements PipeTransform {\n transform(value: string | null | undefined, options?: NgxLinkifyOptions): string {\n if (!value) {\n return '';\n }\n return linkifyStr(value, options);\n }\n}\n","import { Injectable } from '@angular/core';\nimport * as linkify from 'linkifyjs';\nimport linkifyStr from 'linkify-string';\nimport { Link, NgxLinkifyOptions } from '../interfaces/ngx-linkifyjs.interface';\n\n@Injectable({ providedIn: 'root' })\nexport class NgxLinkifyjsService {\n /**\n * Convert the passed text as a string to an appropriate url\n *\n * @param text - the string to convert\n * @param options - options to pass it to the linkifyjs library\n * @returns HTML string with linkified URLs, emails, hashtags, and mentions\n */\n linkify(text: string, options?: NgxLinkifyOptions): string {\n if (!text) {\n return '';\n }\n return linkifyStr(text, options);\n }\n\n /**\n * Find any links in a given text as a string\n *\n * @param text - the string to find some links\n * @returns Array of Link objects found in the text\n */\n find(text: string): Link[] {\n if (!text) {\n return [];\n }\n return linkify.find(text);\n }\n\n /**\n * Test if a given value is a link or an array of all links\n *\n * @param value - the value to test (string or array of strings)\n * @returns true if all values are valid links, false otherwise\n */\n test(value: string | readonly string[]): boolean {\n if (typeof value === 'string') {\n return linkify.test(value);\n }\n return value.every(v => linkify.test(v));\n }\n}\n","import { InjectionToken } from '@angular/core';\nimport { NgxLinkifyjsConfig } from '../interfaces/ngx-linkifyjs.interface';\n\n/**\n * Injection token for NgxLinkifyjs configuration\n */\nexport const NgxLinkifyjsConfigToken = new InjectionToken<NgxLinkifyjsConfig>('NgxLinkifyjsConfig');\n\n/**\n * Default configuration for NgxLinkifyjs\n */\nexport const DEFAULT_CONFIG: NgxLinkifyjsConfig = { enableHash: true, enableMention: true };\n\n","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\nimport { NgxLinkifyjsService } from '../service/ngx-linkifyjs.service';\nimport { NgxLinkifyjsConfig } from '../interfaces/ngx-linkifyjs.interface';\nimport { NgxLinkifyjsConfigToken, DEFAULT_CONFIG } from '../constants/ngx-linkifyjs.constants';\n\n// Conditionally import plugins based on configuration\nlet pluginsLoaded = false;\n\nfunction loadPlugins(config: NgxLinkifyjsConfig): void {\n if (pluginsLoaded) {\n return;\n }\n \n const pluginPromises: Promise<unknown>[] = [];\n\n if (config?.enableHash) {\n pluginPromises.push(\n import('linkify-plugin-hashtag').catch(err => {\n console.error('Failed to load hashtag plugin:', err);\n return null;\n })\n );\n }\n\n if (config?.enableMention) {\n pluginPromises.push(\n import('linkify-plugin-mention').catch(err => {\n console.error('Failed to load mention plugin:', err);\n return null;\n })\n );\n }\n\n if (pluginPromises.length > 0) {\n Promise.all(pluginPromises).finally(() => {\n pluginsLoaded = true;\n });\n } else {\n pluginsLoaded = true;\n }\n}\n\n/**\n * Provides NgxLinkifyjs services and configuration.\n * Works with both standalone and NgModule-based applications.\n * \n * @param config - Configuration options for enabling hashtag and mention plugins\n * @returns EnvironmentProviders array that can be used in app.config.ts\n * \n * @example\n * ```typescript\n * import { provideNgxLinkifyjs } from 'ngx-linkifyjs';\n * \n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideNgxLinkifyjs({\n * enableHash: true,\n * enableMention: true\n * })\n * ]\n * };\n * ```\n */\nexport function provideNgxLinkifyjs(\n config: NgxLinkifyjsConfig = DEFAULT_CONFIG\n): EnvironmentProviders {\n loadPlugins(config);\n \n return makeEnvironmentProviders([\n NgxLinkifyjsService,\n {\n provide: NgxLinkifyjsConfigToken,\n useValue: { ...DEFAULT_CONFIG, ...config }\n }\n ]);\n}\n\n","/*\n * Public API Surface of ngx-linkifyjs\n */\n\nexport * from './lib/enum/linktype.enum';\nexport * from './lib/interfaces/ngx-linkifyjs.interface';\nexport * from './lib/pipes/ngx-linkifyjs.pipe';\nexport * from './lib/service/ngx-linkifyjs.service';\nexport * from './lib/providers/ngx-linkifyjs.provider';\nexport * from './lib/constants/ngx-linkifyjs.constants';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;IAAY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OAAO,wBAAwB,CAAC,CAAC,KAAK,CAAC,GAAG,IAAG;AAC3C,YAAA,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,GAAG,CAAC;AACpD,YAAA,OAAO,IAAI;QACb,CAAC,CAAC,CACH;IACH;AAEA,IAAA,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;QAC7B,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,MAAK;YACvC,aAAa,GAAG,IAAI;AACtB,QAAA,CAAC,CAAC;IACJ;SAAO;QACL,aAAa,GAAG,IAAI;IACtB;AACF;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,mBAAmB,CACjC,MAAA,GAA6B,cAAc,EAAA;IAE3C,WAAW,CAAC,MAAM,CAAC;AAEnB,IAAA,OAAO,wBAAwB,CAAC;QAC9B,mBAAmB;AACnB,QAAA;AACE,YAAA,OAAO,EAAE,uBAAuB;AAChC,YAAA,QAAQ,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM;AACzC;AACF,KAAA,CAAC;AACJ;;AC3EA;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { PipeTransform, InjectionToken, ModuleWithProviders } from '@angular/core';
2
+ import { PipeTransform, EnvironmentProviders, InjectionToken } from '@angular/core';
3
3
 
4
4
  declare enum LinkType {
5
5
  URL = "url",
@@ -18,60 +18,85 @@ interface NgxLinkifyjsConfig {
18
18
  enableMention?: boolean;
19
19
  }
20
20
  interface NgxLinkifyOptions {
21
- attributes?: any;
21
+ attributes?: Record<string, string | number | boolean>;
22
22
  className?: string;
23
23
  defaultProtocol?: string;
24
- events?: any;
25
- ignoreTags?: Array<any>;
24
+ events?: Record<string, (event: Event) => void>;
25
+ ignoreTags?: string[];
26
26
  nl2br?: boolean;
27
27
  tagName?: string;
28
28
  target?: {
29
29
  url: string;
30
30
  };
31
31
  validate?: boolean;
32
- format?(value: any, type: any): any;
33
- formatHref?(href: any, type: any): any;
32
+ format?: (value: string, type: string) => string;
33
+ formatHref?: (href: string, type: string) => string;
34
34
  }
35
35
 
36
36
  declare class NgxLinkifyjsPipe implements PipeTransform {
37
- transform(value: string, options?: NgxLinkifyOptions): string;
37
+ transform(value: string | null | undefined, options?: NgxLinkifyOptions): string;
38
38
  static ɵfac: i0.ɵɵFactoryDeclaration<NgxLinkifyjsPipe, never>;
39
39
  static ɵpipe: i0.ɵɵPipeDeclaration<NgxLinkifyjsPipe, "linkify", true>;
40
40
  }
41
41
 
42
42
  declare class NgxLinkifyjsService {
43
- constructor();
44
43
  /**
45
44
  * Convert the passed text as a string to an appropriate url
46
45
  *
47
46
  * @param text - the string to convert
48
47
  * @param options - options to pass it to the linkifyjs library
48
+ * @returns HTML string with linkified URLs, emails, hashtags, and mentions
49
49
  */
50
50
  linkify(text: string, options?: NgxLinkifyOptions): string;
51
51
  /**
52
52
  * Find any links in a given text as a string
53
53
  *
54
54
  * @param text - the string to find some links
55
+ * @returns Array of Link objects found in the text
55
56
  */
56
- find(text: string): Array<Link>;
57
+ find(text: string): Link[];
57
58
  /**
58
59
  * Test if a given value is a link or an array of all links
59
60
  *
60
- * @param value - the value to test
61
+ * @param value - the value to test (string or array of strings)
62
+ * @returns true if all values are valid links, false otherwise
61
63
  */
62
- test(value: string | string[]): boolean;
64
+ test(value: string | readonly string[]): boolean;
63
65
  static ɵfac: i0.ɵɵFactoryDeclaration<NgxLinkifyjsService, never>;
64
66
  static ɵprov: i0.ɵɵInjectableDeclaration<NgxLinkifyjsService>;
65
67
  }
66
68
 
69
+ /**
70
+ * Provides NgxLinkifyjs services and configuration.
71
+ * Works with both standalone and NgModule-based applications.
72
+ *
73
+ * @param config - Configuration options for enabling hashtag and mention plugins
74
+ * @returns EnvironmentProviders array that can be used in app.config.ts
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import { provideNgxLinkifyjs } from 'ngx-linkifyjs';
79
+ *
80
+ * export const appConfig: ApplicationConfig = {
81
+ * providers: [
82
+ * provideNgxLinkifyjs({
83
+ * enableHash: true,
84
+ * enableMention: true
85
+ * })
86
+ * ]
87
+ * };
88
+ * ```
89
+ */
90
+ declare function provideNgxLinkifyjs(config?: NgxLinkifyjsConfig): EnvironmentProviders;
91
+
92
+ /**
93
+ * Injection token for NgxLinkifyjs configuration
94
+ */
67
95
  declare const NgxLinkifyjsConfigToken: InjectionToken<NgxLinkifyjsConfig>;
96
+ /**
97
+ * Default configuration for NgxLinkifyjs
98
+ */
68
99
  declare const DEFAULT_CONFIG: NgxLinkifyjsConfig;
69
- declare class NgxLinkifyjsModule {
70
- static forRoot(config?: NgxLinkifyjsConfig): ModuleWithProviders<NgxLinkifyjsModule>;
71
- static ɵfac: i0.ɵɵFactoryDeclaration<NgxLinkifyjsModule, never>;
72
- static ɵmod: i0.ɵɵNgModuleDeclaration<NgxLinkifyjsModule, never, [typeof NgxLinkifyjsPipe], [typeof NgxLinkifyjsPipe]>;
73
- static ɵinj: i0.ɵɵInjectorDeclaration<NgxLinkifyjsModule>;
74
- }
75
100
 
76
- export { DEFAULT_CONFIG, LinkType, NgxLinkifyjsConfigToken, NgxLinkifyjsModule, NgxLinkifyjsPipe, NgxLinkifyjsService };
101
+ export { DEFAULT_CONFIG, LinkType, NgxLinkifyjsConfigToken, NgxLinkifyjsPipe, NgxLinkifyjsService, provideNgxLinkifyjs };
77
102
  export type { Link, NgxLinkifyOptions, NgxLinkifyjsConfig };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@code-name-jack/ngx-linkifyjs",
3
3
  "description": "Angular wrapper for linkifyjs(v4) - library for finding links in plain text and converting them to HTML &lt;a&gt; tags via linkifyjs",
4
- "version": "20.0.1",
4
+ "version": "20.1.0",
5
5
  "homepage": "https://github.com/code-name-jack/ngx-linkifyjs-v2",
6
6
  "author": {
7
7
  "name": "Code Name Jack",