@code-name-jack/ngx-linkifyjs 20.0.0 โ†’ 20.0.2

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.
Files changed (2) hide show
  1. package/README.md +577 -13
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,588 @@
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 component support
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 ngx-linkifyjs
40
+ ```
41
+
42
+ ### Option 2: Using npm
43
+
44
+ ```bash
45
+ npm install ngx-linkifyjs
46
+ ```
47
+
48
+ ---
49
+
50
+ ## ๐Ÿš€ Quick Start
51
+
52
+ ### For Standalone Components (Angular 14+)
53
+
54
+ **1. Import the pipe in your component:**
55
+
56
+ ```typescript
57
+ import { Component } from '@angular/core';
58
+ import { NgxLinkifyjsPipe } from 'ngx-linkifyjs';
59
+
60
+ @Component({
61
+ selector: 'app-example',
62
+ standalone: true,
63
+ imports: [NgxLinkifyjsPipe],
64
+ template: `
65
+ <div [innerHTML]="text | linkify"></div>
66
+ `
67
+ })
68
+ export class ExampleComponent {
69
+ text = 'Visit https://github.com or email info@example.com';
70
+ }
71
+ ```
72
+
73
+ **2. Using the service:**
74
+
75
+ ```typescript
76
+ import { Component } from '@angular/core';
77
+ import { NgxLinkifyjsService } from 'ngx-linkifyjs';
78
+
79
+ @Component({
80
+ selector: 'app-example',
81
+ standalone: true,
82
+ providers: [NgxLinkifyjsService]
83
+ })
84
+ export class ExampleComponent {
85
+ constructor(private linkifyService: NgxLinkifyjsService) {
86
+ // Find all links
87
+ const links = this.linkifyService.find('Visit github.com');
88
+ // Output: [{ type: 'url', value: 'github.com', href: 'http://github.com' }]
89
+
90
+ // Test if text contains links
91
+ const hasLinks = this.linkifyService.test('example.com'); // true
92
+
93
+ // Convert text to HTML
94
+ const html = this.linkifyService.linkify('Visit example.com');
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### For NgModule-based Applications
100
+
101
+ ```typescript
102
+ import { NgModule } from '@angular/core';
103
+ import { NgxLinkifyjsModule } from 'ngx-linkifyjs';
104
+
105
+ @NgModule({
106
+ imports: [
107
+ NgxLinkifyjsModule.forRoot({
108
+ enableHash: true, // Enable hashtag detection
109
+ enableMention: true // Enable @mention detection
110
+ })
111
+ ]
112
+ })
113
+ export class AppModule { }
114
+ ```
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 '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 '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 '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
+ // For NgModule apps
317
+ import { NgxLinkifyjsModule } from 'ngx-linkifyjs';
318
+
319
+ @NgModule({
320
+ imports: [
321
+ NgxLinkifyjsModule.forRoot({
322
+ enableHash: false, // Disable hashtags
323
+ enableMention: false // Disable mentions
324
+ })
325
+ ]
326
+ })
327
+ export class AppModule { }
328
+ ```
329
+
330
+ ---
331
+
332
+ ## ๐ŸŽจ Styling Links
333
+
334
+ Add custom CSS to style your linkified links:
335
+
336
+ ```css
337
+ /* Default linkified class */
338
+ .linkified {
339
+ color: #0066cc;
340
+ text-decoration: underline;
341
+ }
342
+
343
+ .linkified:hover {
344
+ color: #0052a3;
345
+ }
346
+
347
+ /* Custom class from options */
348
+ .custom-link {
349
+ color: #667eea;
350
+ font-weight: 600;
351
+ text-decoration: none;
352
+ border-bottom: 2px solid transparent;
353
+ transition: all 0.2s;
354
+ }
355
+
356
+ .custom-link:hover {
357
+ border-bottom-color: #667eea;
358
+ }
359
+ ```
360
+
361
+ ---
362
+
363
+ ## ๐Ÿ” Link Types
364
+
365
+ The library detects four types of links:
366
+
367
+ | Type | Example | Output |
368
+ |------|---------|--------|
369
+ | **URL** | `https://example.com` | `<a href="https://example.com">...</a>` |
370
+ | **Email** | `user@example.com` | `<a href="mailto:user@example.com">...</a>` |
371
+ | **Hashtag** | `#angular` | `<a href="#angular">#angular</a>` |
372
+ | **Mention** | `@username` | `<a href="/username">@username</a>` |
373
+
374
+ > ๐Ÿ’ก **Note:** Hashtags and mentions are enabled by default but can be disabled in configuration.
375
+
376
+ ---
377
+
378
+ ## ๐Ÿ“ฑ Real-World Examples
379
+
380
+ ### Social Media Posts
381
+
382
+ ```typescript
383
+ @Component({
384
+ template: `
385
+ <div class="post" [innerHTML]="post | linkify:socialOptions"></div>
386
+ `
387
+ })
388
+ export class PostComponent {
389
+ post = 'Check out the new @angular release! ๐Ÿš€ #Angular20 https://angular.io';
390
+
391
+ socialOptions: NgxLinkifyOptions = {
392
+ target: { url: '_blank' },
393
+ formatHref: (href, type) => {
394
+ if (type === 'hashtag') {
395
+ return `https://twitter.com/hashtag/${href.slice(1)}`;
396
+ }
397
+ if (type === 'mention') {
398
+ return `https://twitter.com/${href.slice(1)}`;
399
+ }
400
+ return href;
401
+ }
402
+ };
403
+ }
404
+ ```
405
+
406
+ ### Comment Section
407
+
408
+ ```typescript
409
+ @Component({
410
+ template: `
411
+ <div class="comment"
412
+ *ngFor="let comment of comments"
413
+ [innerHTML]="comment.text | linkify:commentOptions">
414
+ </div>
415
+ `
416
+ })
417
+ export class CommentsComponent {
418
+ comments = [
419
+ { text: 'Great article! See more at example.com' },
420
+ { text: 'Contact me at john@example.com for details' }
421
+ ];
422
+
423
+ commentOptions: NgxLinkifyOptions = {
424
+ className: 'comment-link',
425
+ target: { url: '_blank' },
426
+ attributes: {
427
+ rel: 'nofollow noopener'
428
+ }
429
+ };
430
+ }
431
+ ```
432
+
433
+ ### Chat Application
434
+
435
+ ```typescript
436
+ @Component({
437
+ selector: 'chat-message',
438
+ template: `
439
+ <div class="message" [innerHTML]="message | linkify"></div>
440
+ `
441
+ })
442
+ export class ChatMessageComponent {
443
+ @Input() message!: string;
444
+ }
445
+ ```
446
+
447
+ ---
448
+
449
+ ## ๐Ÿงช Testing
450
+
451
+ When testing components that use ngx-linkifyjs:
452
+
453
+ ```typescript
454
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
455
+ import { NgxLinkifyjsPipe, NgxLinkifyjsService } from 'ngx-linkifyjs';
456
+
457
+ describe('MyComponent', () => {
458
+ let component: MyComponent;
459
+ let fixture: ComponentFixture<MyComponent>;
460
+
461
+ beforeEach(async () => {
462
+ await TestBed.configureTestingModule({
463
+ imports: [MyComponent, NgxLinkifyjsPipe],
464
+ providers: [NgxLinkifyjsService]
465
+ }).compileComponents();
466
+
467
+ fixture = TestBed.createComponent(MyComponent);
468
+ component = fixture.componentInstance;
469
+ });
470
+
471
+ it('should linkify URLs', () => {
472
+ component.text = 'Visit example.com';
473
+ fixture.detectChanges();
474
+
475
+ const element = fixture.nativeElement;
476
+ expect(element.querySelector('a')).toBeTruthy();
477
+ expect(element.querySelector('a').href).toContain('example.com');
478
+ });
479
+ });
480
+ ```
481
+
482
+ ---
483
+
484
+ ## ๐Ÿ“š API Reference
485
+
486
+ ### Exports
487
+
488
+ ```typescript
489
+ // Module
490
+ export { NgxLinkifyjsModule }
491
+
492
+ // Standalone pipe
493
+ export { NgxLinkifyjsPipe }
494
+
495
+ // Service
496
+ export { NgxLinkifyjsService }
497
+
498
+ // Types & Interfaces
499
+ export { NgxLinkifyOptions }
500
+ export { NgxLinkifyjsConfig }
501
+ export { Link }
502
+ export { LinkType }
503
+
504
+ // Tokens
505
+ export { NgxLinkifyjsConfigToken }
506
+ export { DEFAULT_CONFIG }
507
+ ```
508
+
509
+ ### Types
510
+
511
+ ```typescript
512
+ interface Link {
513
+ type: string; // 'url' | 'email' | 'hashtag' | 'mention'
514
+ value: string; // Original text
515
+ href: string; // Generated href attribute
516
+ }
517
+
518
+ enum LinkType {
519
+ URL = 'url',
520
+ EMAIL = 'email',
521
+ HASHTAG = 'hashtag',
522
+ MENTION = 'mention'
523
+ }
524
+
525
+ interface NgxLinkifyjsConfig {
526
+ enableHash?: boolean; // Enable hashtag detection (default: true)
527
+ enableMention?: boolean; // Enable mention detection (default: true)
528
+ }
529
+ ```
530
+
531
+ ---
532
+
533
+
534
+ ## ๐Ÿค Contributing
535
+
536
+ Contributions are welcome! Please feel free to submit a Pull Request.
537
+
538
+ 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).
539
+
540
+ ---
541
+
542
+ ## ๐Ÿ› Issues & Support
543
+
544
+ - ๐Ÿ› [Report bugs](https://github.com/code-name-jack/ngx-linkifyjs-v2/issues)
545
+ - ๐Ÿ’ก [Request features](https://github.com/code-name-jack/ngx-linkifyjs-v2/issues)
546
+ - ๐Ÿ’ฌ [Ask questions](https://github.com/code-name-jack/ngx-linkifyjs-v2/discussions)
547
+
548
+ ---
549
+
550
+ ## ๐Ÿ“„ License
551
+
552
+ Copyright (c) 2018 Anthony Nahas
553
+ Copyright (c) 2022 Ethan Gerardot
554
+ Copyright (c) 2025 Code Name Jack
555
+
556
+ Licensed under the [MIT License](LICENSE)
557
+
558
+ ---
559
+
560
+ ## ๐ŸŒŸ Show Your Support
561
+
562
+ If this project helped you, please consider:
563
+
564
+ - โญ Starring the repository
565
+ - ๐Ÿ› Reporting bugs
566
+ - ๐Ÿ’ก Suggesting features
567
+ - ๐Ÿ“ข Sharing with others
568
+
569
+ ---
570
+
571
+ ## ๐Ÿ”— Related Projects
572
+
573
+ - [@angular-material-extensions/link-preview](https://github.com/angular-material-extensions/link-preview) - Link preview component using ngx-linkifyjs
574
+ - [linkifyjs](https://linkify.js.org/) - The underlying linkify library
575
+
576
+ ---
577
+
578
+ <p align="center">
579
+ Made with โค๏ธ for the Angular community
580
+ </p>
581
+
582
+ <p align="center">
583
+ <a href="https://www.jetbrains.com">
584
+ <img src="assets/jetbrains-variant-4_logos/jetbrains-variant-4.png" alt="JetBrains" height="50">
585
+ </a>
586
+ <br>
587
+ <sub>Supported by JetBrains with 1 ALL PRODUCTS PACK OS LICENSE</sub>
588
+ </p>
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.0",
4
+ "version": "20.0.2",
5
5
  "homepage": "https://github.com/code-name-jack/ngx-linkifyjs-v2",
6
6
  "author": {
7
7
  "name": "Code Name Jack",