@code-name-jack/ngx-linkifyjs 17.0.0 → 17.0.1
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 +399 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,24 +1,410 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ngx-linkifyjs-v2 - Angular 17 wrapper for linkifyjs - library for finding links in plain text and converting them to HTML <a> tags via linkifyjs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/js/ngx-linkifyjs),
|
|
4
|
+
[](https://anthonynahas.github.io/ngx-linkifyjs)
|
|
5
|
+
[](https://gitter.im/angular-material-extensions/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
6
|
+
[](https://circleci.com/gh/AnthonyNahas/ngx-linkifyjs)
|
|
7
|
+
[](https://travis-ci.org/AnthonyNahas/ngx-linkifyjs)
|
|
8
|
+
[](https://coveralls.io/github/AnthonyNahas/ngx-linkifyjs?branch=master)
|
|
9
|
+
[](https://david-dm.org/anthonynahas/ngx-linkifyjs)
|
|
10
|
+
[](https://david-dm.org/anthonynahas/ngx-linkifyjs#info=devDependencies)
|
|
11
|
+
[](https://greenkeeper.io/)
|
|
12
|
+
[](https://github.com/AnthonyNahas/ngx-linkifyjs/blob/master/LICENSE)
|
|
13
|
+
[](https://github.com/gdi2290/awesome-angular)
|
|
4
14
|
|
|
5
|
-
## Code scaffolding
|
|
6
15
|
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
<p align="center">
|
|
17
|
+
<img alt="ngx-linkifyjs demo" width="320px" style="text-align: center;"
|
|
18
|
+
src="https://cdn.jsdelivr.net/gh/anthonynahas/ngx-linkifyjs@master/assets/demo.gif">
|
|
19
|
+
</p>
|
|
9
20
|
|
|
10
|
-
##
|
|
21
|
+
## Built by and for developers :heart:
|
|
22
|
+
Do you have any question or suggestion ? Please do not hesitate to contact us!
|
|
23
|
+
Alternatively, provide a PR | open an appropriate issue [here](https://github.com/anthonynahas/ngx-linkifyjs/issues)
|
|
11
24
|
|
|
12
|
-
|
|
25
|
+
If you like this project, support [ngx-linkifyjs](https://github.com/anthonynahas/ngx-linkifyjs)
|
|
26
|
+
by starring :star: and sharing it :loudspeaker:
|
|
13
27
|
|
|
14
|
-
## Publishing
|
|
15
28
|
|
|
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`.
|
|
17
29
|
|
|
18
|
-
##
|
|
30
|
+
## Table of Contents
|
|
31
|
+
- [Demo](#demo)
|
|
32
|
+
- [Features](#features)
|
|
33
|
+
- [Documentation](#documentation)
|
|
34
|
+
- [Installation](#installation)
|
|
35
|
+
- [Usage](#usage)
|
|
36
|
+
- [Config](#config)
|
|
37
|
+
- [Run Demo App Locally](#run-demo-app-locally)
|
|
38
|
+
- [Other Angular Libraries](#other-angular-libraries)
|
|
39
|
+
- [Support](#support)
|
|
40
|
+
- [License](#license)
|
|
19
41
|
|
|
20
|
-
|
|
42
|
+
<a name="demo"/>
|
|
21
43
|
|
|
22
|
-
##
|
|
44
|
+
## Demo
|
|
45
|
+
|
|
46
|
+
View all the directives in action at https://anthonynahas.github.io/ngx-linkifyjs
|
|
47
|
+
|
|
48
|
+
<a name="documentation"/>
|
|
49
|
+
|
|
50
|
+
## [Documentation](https://anthonynahas.github.io/ngx-linkifyjs/doc/index.html)
|
|
51
|
+
|
|
52
|
+
<a name="dependencies"/>
|
|
53
|
+
|
|
54
|
+
## Dependencies
|
|
55
|
+
* [Angular](https://angular.io) (*requires* Angular 2 or higher, tested with 7.x)
|
|
56
|
+
|
|
57
|
+
<a name="installation"/>
|
|
58
|
+
|
|
59
|
+
# Installation
|
|
60
|
+
|
|
61
|
+
## 1. Install via *ng add*. (Recommended)
|
|
62
|
+
|
|
63
|
+
Now add the library via the `angular schematics`
|
|
64
|
+
```shell
|
|
65
|
+
ng add ngx-linkifyjs
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 2. Install via *npm*. (Alternative)
|
|
69
|
+
|
|
70
|
+
Now install `ngx-linkifyjs` via:
|
|
71
|
+
```shell
|
|
72
|
+
npm i -s ngx-linkifyjs
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
##### SystemJS
|
|
77
|
+
>**Note**:If you are using `SystemJS`, you should adjust your configuration to point to the UMD bundle.
|
|
78
|
+
In your systemjs config file, `map` needs to tell the System loader where to look for `ngx-linkifyjs`:
|
|
79
|
+
```js
|
|
80
|
+
{
|
|
81
|
+
'ngx-linkifyjs';: 'node_modules/ngx-linkifyjs/bundles/ngx-linkifyjs.umd.js',
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
Once installed you need to import the main module:
|
|
87
|
+
```js
|
|
88
|
+
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';
|
|
89
|
+
```
|
|
90
|
+
The only remaining part is to list the imported module in your application module. The exact method will be slightly
|
|
91
|
+
different for the root (top-level) module for which you should end up with the code similar to (notice ` NgxLinkifyjsModule .forRoot()`):
|
|
92
|
+
```typescript
|
|
93
|
+
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';
|
|
94
|
+
|
|
95
|
+
@NgModule({
|
|
96
|
+
declarations: [AppComponent, ...],
|
|
97
|
+
imports: [NgxLinkifyjsModule.forRoot(), ...],
|
|
98
|
+
bootstrap: [AppComponent]
|
|
99
|
+
})
|
|
100
|
+
export class AppModule {
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Other modules in your application can simply import ` NgxLinkifyjsModule `:
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';
|
|
108
|
+
|
|
109
|
+
@NgModule({
|
|
110
|
+
declarations: [OtherComponent, ...],
|
|
111
|
+
imports: [NgxLinkifyjsModule, ...],
|
|
112
|
+
})
|
|
113
|
+
export class OtherModule {
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
<a name="usage"/>
|
|
118
|
+
|
|
119
|
+
## Usage
|
|
120
|
+
|
|
121
|
+
Once the library is imported, you can use its components, directives and pipes in your Angular application:
|
|
122
|
+
|
|
123
|
+
### Options
|
|
124
|
+
|
|
125
|
+
`ngx-linkifyjs` provides an appropriate option interface called `NgxLinkifyOptions` to access [the native options of the linkifyjs library](https://soapbox.github.io/linkifyjs/docs/options.html)
|
|
126
|
+
and all of them are optional
|
|
127
|
+
- Default values
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
|
|
131
|
+
import { NgxLinkifyOptions } from 'ngx-linkifyjs';
|
|
132
|
+
|
|
133
|
+
const options: NgxLinkifyOptions =
|
|
134
|
+
{
|
|
135
|
+
attributes: null,
|
|
136
|
+
className: 'linkified',
|
|
137
|
+
defaultProtocol: 'http',
|
|
138
|
+
events: null,
|
|
139
|
+
format: function (value, type) {
|
|
140
|
+
return value;
|
|
141
|
+
},
|
|
142
|
+
formatHref: function (href, type) {
|
|
143
|
+
return href;
|
|
144
|
+
},
|
|
145
|
+
ignoreTags: [],
|
|
146
|
+
nl2br: false,
|
|
147
|
+
tagName: 'a',
|
|
148
|
+
target: {
|
|
149
|
+
url: '_blank'
|
|
150
|
+
},
|
|
151
|
+
validate: true
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Pipe
|
|
156
|
+
|
|
157
|
+
`{{text | linkify}}`
|
|
158
|
+
|
|
159
|
+
```html
|
|
160
|
+
<span [innerHTML]="'Linkify the following URL: https://github.com/anthonynahas/ngx-linkifyjs and share it <3' | linkify"></span>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**result**: Linkify the following URL: [https://github.com/anthonynahas/ngx-linkifyjs](https://github.com/anthonynahas/ngx-linkifyjs) and share it <3
|
|
164
|
+
|
|
165
|
+
if you prefer to provide your own option to the `pipe`, you can use it like the following:
|
|
166
|
+
|
|
167
|
+
- `{{text | linkify: 'options' }}`
|
|
168
|
+
- `{{text | linkify: '{/*your options*/}' }}`
|
|
169
|
+
- `{{text | linkify: '{target {url: "_self" }}' }}`
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
### Service
|
|
173
|
+
|
|
174
|
+
Inject the `NgxLinkifyjsService` service
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import {NgxLinkifyjsService, Link, LinkType} from 'ngx-linkifyjs';
|
|
178
|
+
|
|
179
|
+
constructor(public; NgxLinkifyjsService;) {
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
<a name="linkify_method"/>
|
|
185
|
+
|
|
186
|
+
#### linkify _(text: string, options?: NgxLinkifyOptions): string_
|
|
187
|
+
|
|
188
|
+
Convert a basic text string to a valid linkified text
|
|
189
|
+
|
|
190
|
+
**Params**
|
|
191
|
+
|
|
192
|
+
* **`text`** : _`String`_ Text to linkify --> to convert with links
|
|
193
|
+
* **`options`** : _`NgxLinkifyjsService`_ options to pass it to the linkifyjs library and it's optional
|
|
194
|
+
|
|
195
|
+
**Returns** _`String`_ converted text with links
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import {NgxLinkifyjsService, Link, LinkType, NgxLinkifyOptions} from 'ngx-linkifyjs';
|
|
200
|
+
|
|
201
|
+
constructor(public; NgxLinkifyjsService;) {
|
|
202
|
+
|
|
203
|
+
const options: NgxLinkifyOptions =
|
|
204
|
+
{
|
|
205
|
+
className: 'linkifiedYES',
|
|
206
|
+
target : {
|
|
207
|
+
url : '_self'
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
this.linkifyService.linkify('For help with GitHub.com, please email support@github.com');
|
|
212
|
+
// result 1 --> see below
|
|
213
|
+
|
|
214
|
+
this.linkifyService.linkify('For help with GitHub.com, please email support@github.com', options);
|
|
215
|
+
// result 2 --> see below
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
result 1
|
|
221
|
+
```typescript
|
|
222
|
+
'For help with <a href=\"http://github.com\" class=\"linkified\" target=\"_blank\">GitHub.com</a>, please email <a href=\"mailto:support@github.com\" class=\"linkified\">support@github.com</a>'
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
result 2
|
|
226
|
+
```typescript
|
|
227
|
+
'For help with <a href=\"http://github.com\" class=\"linkifiedYES\" target=\"_self\">GitHub.com</a>, please email <a href=\"mailto:support@github.com\" class=\"linkifiedYES\">support@github.com</a>'
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### `find` method
|
|
231
|
+
|
|
232
|
+
Finds all links in the given string
|
|
233
|
+
|
|
234
|
+
**Params**
|
|
235
|
+
|
|
236
|
+
* **`text`** : _`String`_ search text string
|
|
237
|
+
|
|
238
|
+
**Returns** _`Array<Link>`_ List of links where each element is a hash with properties type, value, and href:
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
* **type** is the type of entity found. Possible values are
|
|
242
|
+
- `'url'`
|
|
243
|
+
- `'email'`
|
|
244
|
+
- `'hashtag'` (if Hashtag is enabled via config/default `true`)
|
|
245
|
+
- `'mention'` (if Mention is enabled via config/default `true`)
|
|
246
|
+
* **value** is the original entity substring.
|
|
247
|
+
* **href** should be the value of this link's `href` attribute.
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import {Component, OnInit} from '@angular/core';
|
|
251
|
+
import {NgxLinkifyjsService, Link, LinkType} from 'ngx-linkifyjs';
|
|
252
|
+
|
|
253
|
+
@Component({
|
|
254
|
+
selector: 'app-home',
|
|
255
|
+
templateUrl: './home.component.html',
|
|
256
|
+
styleUrls: ['./home.component.scss']
|
|
257
|
+
})
|
|
258
|
+
export class HomeComponent {
|
|
259
|
+
|
|
260
|
+
constructor(public linkifyService: NgxLinkifyjsService) {
|
|
261
|
+
const foundLinks: Link[] = this.linkifyService.find('Any links to github.com here? If not, contact test@example.com');
|
|
262
|
+
|
|
263
|
+
// result - output --> see below
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
// Result
|
|
271
|
+
[
|
|
272
|
+
{
|
|
273
|
+
type: LinkType.URL,
|
|
274
|
+
value: 'github.com',
|
|
275
|
+
href: 'http://github.com'
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
type: LinkType.EMAIL,
|
|
279
|
+
value: 'test@example.com',
|
|
280
|
+
href: 'mailto:test@example.com'
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### `test` method
|
|
286
|
+
|
|
287
|
+
Is the given string a link? Not to be used for strict validation - See [Caveats](caveats.html)
|
|
288
|
+
|
|
289
|
+
**Params**
|
|
290
|
+
|
|
291
|
+
* **`value`** : _`String`_ | _`Array<String>`_ Test string
|
|
292
|
+
|
|
293
|
+
**Returns** _`Boolean`_
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
import {Component, OnInit} from '@angular/core';
|
|
297
|
+
import {NgxLinkifyjsService} from 'ngx-linkifyjs';
|
|
298
|
+
|
|
299
|
+
@Component({
|
|
300
|
+
selector: 'app-home',
|
|
301
|
+
templateUrl: './home.component.html',
|
|
302
|
+
styleUrls: ['./home.component.scss']
|
|
303
|
+
})
|
|
304
|
+
export class HomeComponent {
|
|
305
|
+
|
|
306
|
+
constructor(public linkifyService: NgxLinkifyjsService) {
|
|
307
|
+
this.linkifyService.test('github.com'); // return true
|
|
308
|
+
this.linkifyService.test('dev@example.com'); // return true
|
|
309
|
+
this.linkifyService.test(['github.com', 'email']); // return false
|
|
310
|
+
this.linkifyService.test('helloWorld'); // return false
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
<a name="config"/>
|
|
316
|
+
|
|
317
|
+
#### Enable/Disable the hash and mention
|
|
318
|
+
|
|
319
|
+
The config argument is 100% optional, otherwise we will take the default values `true`
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import { NgxLinkifyjsModule } from 'ngx-linkifyjs';
|
|
323
|
+
|
|
324
|
+
@NgModule({
|
|
325
|
+
declarations: [AppComponent, ...],
|
|
326
|
+
imports: [NgxLinkifyjsModule.forRoot(
|
|
327
|
+
{
|
|
328
|
+
enableHash: false, // optional - default true
|
|
329
|
+
enableMention: false // optional - default true
|
|
330
|
+
}), ...],
|
|
331
|
+
bootstrap: [AppComponent]
|
|
332
|
+
})
|
|
333
|
+
export class AppModule {
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
take a look @ [@angular-material-extensions/link-preview](https://github.com/angular-material-extensions/link-preview) which is using `ngx-linkifyjs`
|
|
338
|
+
|
|
339
|
+
## Run Demo App Locally
|
|
340
|
+
|
|
341
|
+
- [clone this repo](https://github.com/AnthonyNahas/ngx-linkifyjs.git) by running
|
|
342
|
+
```bash
|
|
343
|
+
$ git clone https://github.com/AnthonyNahas/ngx-linkifyjs.git
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
- setup the ngx-linkifyjs package
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
$ gulp steup
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
- navigate to the demo app directory
|
|
353
|
+
```bash
|
|
354
|
+
$ cd demo
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
- install the dependencies and run the app locally
|
|
358
|
+
```bash
|
|
359
|
+
$ npm i && npm start
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
- the app is now hosted by `http://localhost:4200/`
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
<a name="other-angular-libraries"/>
|
|
368
|
+
|
|
369
|
+
## Other Angular Libraries
|
|
370
|
+
- [ngx-auth-firebaseui](https://github.com/anthonynahas/ngx-auth-firebaseui)
|
|
371
|
+
- [@firebaseui/ng-bootstrap](https://github.com/firebaseui/ng-bootstrap)
|
|
372
|
+
- [@angular-material-extensions/password-strength](https://github.com/angular-material-extensions/password-strength)
|
|
373
|
+
- [@angular-material-extensions/link-preview](https://github.com/angular-material-extensions/link-preview)
|
|
374
|
+
- [@angular-material-extensions/select-country](https://github.com/angular-material-extensions/select-country)
|
|
375
|
+
- [@angular-material-extensions/pages](https://github.com/angular-material-extensions/pages)
|
|
376
|
+
- [@angular-material-extensions/contacts](https://github.com/angular-material-extensions/contacts)
|
|
377
|
+
- [@angular-material-extensions/faq](https://github.com/angular-material-extensions/faq)
|
|
378
|
+
- [@angular-material-extensions/jumbotron](https://github.com/angular-material-extensions/jumbotron)
|
|
379
|
+
- [@angular-material-extensions/google-maps-autocomplete](https://github.com/angular-material-extensions/google-maps-autocomplete)
|
|
380
|
+
- [@angular-material-extensions/combination-generator](https://github.com/angular-material-extensions/combination-generator)
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
<a name="support"/>
|
|
385
|
+
|
|
386
|
+
## Support
|
|
387
|
+
+ Drop an email to: [Anthony Nahas](mailto:anthony.na@hotmail.de)
|
|
388
|
+
+ or open an appropriate [issue](https://github.com/anthonynahas/ngx-linkifyjs/issues)
|
|
389
|
+
+ let us chat on [Gitter](https://gitter.im/angular-material-extensions/Lobby)
|
|
390
|
+
|
|
391
|
+
Built by and for developers :heart: we will help you :punch:
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+

|
|
398
|
+
|
|
399
|
+
This project is supported by [jetbrains](https://www.jetbrains.com/) with 1 ALL PRODUCTS PACK OS LICENSE incl. [webstorm](https://www.jetbrains.com/webstorm)
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
<a name="license"/>
|
|
404
|
+
|
|
405
|
+
## License
|
|
406
|
+
|
|
407
|
+
Copyright (c) 2018 Anthony Nahas
|
|
408
|
+
Copyright (c) 2022 Ethan Gerardot
|
|
409
|
+
Licensed under the MIT License (MIT)
|
|
23
410
|
|
|
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).
|
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 <a> tags via linkifyjs",
|
|
4
|
-
"version": "17.0.
|
|
4
|
+
"version": "17.0.1",
|
|
5
5
|
"homepage": "https://github.com/code-name-jack/ngx-linkifyjs-v2",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Code Name Jack",
|
|
@@ -143,4 +143,4 @@
|
|
|
143
143
|
"dependencies": {
|
|
144
144
|
"tslib": "^2.4.1"
|
|
145
145
|
}
|
|
146
|
-
}
|
|
146
|
+
}
|