@bartificer/linkify 2.3.5 → 2.4.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 +135 -35
- package/dist/index.js +1 -1
- package/docs/LinkData.class.mjs.html +119 -56
- package/docs/LinkTemplate.class.mjs.html +120 -36
- package/docs/Linkifier.class.mjs.html +141 -66
- package/docs/PageData.class.mjs.html +145 -72
- package/docs/defaults.mjs.html +136 -12
- package/docs/docdash-overrides.css +11 -0
- package/docs/externals.jsdoc.html +95 -4
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/global.html +1276 -0
- package/docs/index.html +1018 -26
- package/docs/index.js.html +143 -17
- package/docs/mermaid-init.js +21 -0
- package/docs/module-cheerio.html +193 -3
- package/docs/module-defaults.html +680 -3
- package/docs/module-link-data.LinkData.html +813 -0
- package/docs/module-link-data.html +226 -0
- package/docs/module-link-template.LinkTemplate.html +792 -0
- package/docs/module-link-template.html +226 -0
- package/docs/module-linkifier.Linkifier.html +2050 -0
- package/docs/module-linkifier.html +236 -0
- package/docs/module-linkify.html +810 -3
- package/docs/module-mustache.html +193 -3
- package/docs/module-node-fetch.html +193 -3
- package/docs/module-page-data.PageData.html +1810 -0
- package/docs/module-page-data.html +226 -0
- package/docs/module-title-case.html +193 -3
- package/docs/module-urijs.html +193 -3
- package/docs/module-url-slug.html +193 -3
- package/docs/module-utilities.html +1518 -3
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/{third-party → prettify}/Apache-License-2.0.txt +202 -202
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -265
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/docs/typedefs.jsdoc.html +145 -0
- package/docs/utilities.mjs.html +154 -22
- package/examples/clipboardURLToMarkdown.mjs +80 -1
- package/package.json +5 -3
- package/src/LinkData.class.mjs +24 -52
- package/src/LinkTemplate.class.mjs +25 -32
- package/src/Linkifier.class.mjs +46 -62
- package/src/PageData.class.mjs +50 -68
- package/src/defaults.mjs +42 -8
- package/src/index.js +48 -13
- package/src/typedefs.jsdoc +52 -0
- package/src/utilities.mjs +59 -18
- package/docs/data/search.json +0 -1
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/module-LinkData.LinkData.html +0 -13
- package/docs/module-LinkData.html +0 -3
- package/docs/module-LinkTemplate.LinkTemplate.html +0 -3
- package/docs/module-LinkTemplate.html +0 -3
- package/docs/module-Linkifier.Linkifier.html +0 -3
- package/docs/module-Linkifier.html +0 -3
- package/docs/module-PageData.PageData.html +0 -15
- package/docs/module-PageData.html +0 -3
- package/docs/scripts/core.js +0 -726
- package/docs/scripts/core.min.js +0 -23
- package/docs/scripts/resize.js +0 -90
- package/docs/scripts/search.min.js +0 -6
- package/docs/scripts/third-party/fuse.js +0 -9
- package/docs/scripts/third-party/hljs-line-num-original.js +0 -369
- package/docs/scripts/third-party/hljs-line-num.js +0 -1
- package/docs/scripts/third-party/hljs-original.js +0 -5171
- package/docs/scripts/third-party/hljs.js +0 -1
- package/docs/scripts/third-party/popper.js +0 -5
- package/docs/scripts/third-party/tippy.js +0 -1
- package/docs/scripts/third-party/tocbot.js +0 -672
- package/docs/scripts/third-party/tocbot.min.js +0 -1
- package/docs/styles/clean-jsdoc-theme-base.css +0 -1159
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -412
- package/docs/styles/clean-jsdoc-theme-light.css +0 -482
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -30
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
- package/docs/styles/clean-jsdoc-theme.min.css +0 -1
|
@@ -1,30 +1,89 @@
|
|
|
1
|
-
<!DOCTYPE html
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>LinkData.class.mjs - @bartificer/linkify Documentation</title>
|
|
7
|
+
|
|
8
|
+
<meta name="description" content="Documentation for the @bartificer/linkify package" />
|
|
9
|
+
|
|
10
|
+
<meta name="keywords" content="documentation, linkify, link, template, javascript, generator, npm, module, package" />
|
|
11
|
+
<meta name="keyword" content="documentation, linkify, link, template, javascript, generator, npm, module, package" />
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<meta property="og:title" content="@bartificer/linkify"/>
|
|
16
|
+
<meta property="og:type" content="website"/>
|
|
17
|
+
<meta property="og:image" content=""/>
|
|
18
|
+
<meta property="og:site_name" content="@bartificer/linkify Documentation"/>
|
|
19
|
+
<meta property="og:url" content="https://bartificer.github.io/linkify/"/>
|
|
20
|
+
|
|
21
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
22
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
23
|
+
<!--[if lt IE 9]>
|
|
24
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
25
|
+
<![endif]-->
|
|
26
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
27
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
28
|
+
<script src="scripts/nav.js" defer></script>
|
|
29
|
+
|
|
30
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
|
|
34
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
35
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
36
|
+
<div class="navicon"></div>
|
|
37
|
+
</label>
|
|
38
|
+
|
|
39
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
40
|
+
|
|
41
|
+
<nav class="wrap">
|
|
42
|
+
|
|
43
|
+
<input type="text" id="nav-search" placeholder="Search" />
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/bartificer/linkify" target="_blank" >On GitHub</a></h2><h2><a href="https://bartificer.net/" target="_blank" >Bartificer Creations</a></h2><h3>Modules</h3><ul><li><a href="module-defaults.html">defaults</a><ul class='members'><li data-type='member'><a href="module-defaults.html#.linkTemplates">linkTemplates</a></li><li data-type='member'><a href="module-defaults.html#.smallWords">smallWords</a></li><li data-type='member'><a href="module-defaults.html#.speciallyCapitalisedWords">speciallyCapitalisedWords</a></li></ul><ul class='methods'><li data-type='method'><a href="module-defaults.html#.dataTransformer">dataTransformer</a></li></ul></li><li><a href="module-link-data.html">link-data</a></li><li><a href="module-link-template.html">link-template</a></li><li><a href="module-linkifier.html">linkifier</a></li><li><a href="module-linkify.html">linkify</a><ul class='members'><li data-type='member'><a href="module-linkify.html#.LinkData">LinkData</a></li><li data-type='member'><a href="module-linkify.html#.LinkTemplate">LinkTemplate</a></li><li data-type='member'><a href="module-linkify.html#.Linkifier">Linkifier</a></li><li data-type='member'><a href="module-linkify.html#.PageData">PageData</a></li><li data-type='member'><a href="module-linkify.html#.VERSION">VERSION</a></li><li data-type='member'><a href="module-linkify.html#.default">default</a></li><li data-type='member'><a href="module-linkify.html#.linkify">linkify</a></li></ul></li><li><a href="module-page-data.html">page-data</a></li><li><a href="module-utilities.html">utilities</a><ul class='methods'><li data-type='method'><a href="module-utilities.html#.batchFixCustomWordCases">batchFixCustomWordCases</a></li><li data-type='method'><a href="module-utilities.html#.escapeRegex">escapeRegex</a></li><li data-type='method'><a href="module-utilities.html#.extractSlug">extractSlug</a></li><li data-type='method'><a href="module-utilities.html#.regulariseWhitespace">regulariseWhitespace</a></li><li data-type='method'><a href="module-utilities.html#.stripQueryString">stripQueryString</a></li><li data-type='method'><a href="module-utilities.html#.stripUTMParameters">stripUTMParameters</a></li><li data-type='method'><a href="module-utilities.html#.toTitleCase">toTitleCase</a></li></ul></li></ul><h3>Classes</h3><ul><li><a href="module-link-data.LinkData.html">LinkData</a><ul class='methods'><li data-type='method'><a href="module-link-data.LinkData.html#asPlainObject">asPlainObject</a></li></ul></li><li><a href="module-link-template.LinkTemplate.html">LinkTemplate</a><ul class='methods'><li data-type='method'><a href="module-link-template.LinkTemplate.html#addFilter">addFilter</a></li><li data-type='method'><a href="module-link-template.LinkTemplate.html#filtersFor">filtersFor</a></li></ul></li><li><a href="module-linkifier.Linkifier.html">Linkifier</a><ul class='methods'><li data-type='method'><a href="module-linkifier.Linkifier.html#fetchPageData">fetchPageData</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#generateLink">generateLink</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#getTemplate">getTemplate</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#getTemplateNameForDomain">getTemplateNameForDomain</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#getTransformerForDomain">getTransformerForDomain</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#registerDefaultTemplateMapping">registerDefaultTemplateMapping</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#registerTemplate">registerTemplate</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#registerTransformer">registerTransformer</a></li></ul></li><li><a href="module-page-data.PageData.html">PageData</a><ul class='methods'><li data-type='method'><a href="module-page-data.PageData.html#addSecondaryHeading">addSecondaryHeading</a></li><li data-type='method'><a href="module-page-data.PageData.html#addTopLevelHeading">addTopLevelHeading</a></li><li data-type='method'><a href="module-page-data.PageData.html#asPlainObject">asPlainObject</a></li><li data-type='method'><a href="module-page-data.PageData.html#h1">h1</a></li><li data-type='method'><a href="module-page-data.PageData.html#h2">h2</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#dataTransformer">dataTransformer</a></li><li><a href="global.html#plainLinkInformationObject">plainLinkInformationObject</a></li><li><a href="global.html#plainPageInformationObject">plainPageInformationObject</a></li><li><a href="global.html#templateFieldFilterFunction">templateFieldFilterFunction</a></li><li><a href="global.html#templateFieldFilterTuple">templateFieldFilterTuple</a></li></ul><h3>Externals</h3><ul><li><a href="module-cheerio.html">cheerio</a></li><li><a href="module-mustache.html">mustache</a></li><li><a href="module-node-fetch.html">node-fetch</a></li><li><a href="module-title-case.html">title-case</a></li><li><a href="module-urijs.html">urijs</a></li><li><a href="module-url-slug.html">url-slug</a></li></ul>
|
|
47
|
+
|
|
48
|
+
</nav>
|
|
49
|
+
|
|
50
|
+
<div id="main">
|
|
51
|
+
|
|
52
|
+
<h1 class="page-title">LinkData.class.mjs</h1>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<section>
|
|
61
|
+
<article>
|
|
62
|
+
<pre class="prettyprint source linenums"><code>/**
|
|
63
|
+
* @file Data model for link information.
|
|
5
64
|
* @author Bart Busschots <opensource@bartificer.ie>
|
|
65
|
+
* @license MIT
|
|
6
66
|
*/
|
|
7
67
|
|
|
8
68
|
/**
|
|
9
|
-
* This module provides
|
|
10
|
-
* @module
|
|
69
|
+
* This module provides the class for representing the information that can be used to render a link.
|
|
70
|
+
* @module link-data
|
|
11
71
|
* @requires module:urijs
|
|
12
72
|
*/
|
|
13
73
|
import {default as URI} from 'urijs';
|
|
14
74
|
|
|
15
75
|
/**
|
|
16
|
-
*
|
|
76
|
+
* The information that can be used to render a link.
|
|
77
|
+
*
|
|
78
|
+
* Instances of this class are created from the information extracted from web pages by data transformers.
|
|
79
|
+
* @see {@link dataTransformer} for details of how instances of this class are created.
|
|
17
80
|
*/
|
|
18
81
|
export class LinkData {
|
|
19
82
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @param {URL} url - The link's URL.
|
|
83
|
+
* @param {string} url - The link's URL.
|
|
23
84
|
* @param {string} [text] - The link's text, defaults to the URL.
|
|
24
|
-
* @param {string} [description] - A description for the link, defaults to
|
|
25
|
-
*
|
|
26
|
-
* @throws {ValidationError} A validation error is thrown if an invalid URL
|
|
27
|
-
* is passed.
|
|
85
|
+
* @param {string} [description] - A description for the link, defaults to the link text.
|
|
86
|
+
* @throws {TypeError} A TypeError is thrown if an invalid URL is passed.
|
|
28
87
|
*/
|
|
29
88
|
constructor(url, text, description){
|
|
30
89
|
// TO DO - add validation
|
|
@@ -33,9 +92,9 @@ export class LinkData {
|
|
|
33
92
|
* The link's URL as a URI.js object.
|
|
34
93
|
*
|
|
35
94
|
* @private
|
|
36
|
-
* @type {
|
|
95
|
+
* @type {module:urijs}
|
|
37
96
|
*/
|
|
38
|
-
this._uri = URI();
|
|
97
|
+
this._uri = URI(); // throws a TypeError if the URL is invalid
|
|
39
98
|
|
|
40
99
|
/**
|
|
41
100
|
* The link text.
|
|
@@ -64,78 +123,50 @@ export class LinkData {
|
|
|
64
123
|
}
|
|
65
124
|
|
|
66
125
|
/**
|
|
67
|
-
*
|
|
126
|
+
* The URL the link points to as a string.
|
|
127
|
+
* @type {string}
|
|
68
128
|
*/
|
|
69
129
|
get url(){
|
|
70
130
|
return this._uri.toString();
|
|
71
131
|
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get or set the URL.
|
|
75
|
-
*
|
|
76
|
-
* @param {string} url - A new URL as a string.
|
|
77
|
-
*/
|
|
78
132
|
set url(url){
|
|
79
133
|
this._uri = URI(String(url)).normalize();
|
|
80
134
|
}
|
|
81
135
|
|
|
82
136
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @
|
|
137
|
+
* The URL the link points to as a URI.js object representing the URL.
|
|
138
|
+
* @type {module:urijs}
|
|
139
|
+
* @readonly
|
|
86
140
|
*/
|
|
87
141
|
get uri(){
|
|
88
142
|
return this._uri.clone();
|
|
89
143
|
}
|
|
90
144
|
|
|
91
145
|
/**
|
|
92
|
-
*
|
|
146
|
+
* The link text.
|
|
147
|
+
* @type {string}
|
|
93
148
|
*/
|
|
94
149
|
get text(){
|
|
95
150
|
return this._text;
|
|
96
151
|
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @param {string} [text] - New link text. The value will be coerced to a string and trimmed.
|
|
100
|
-
*/
|
|
101
152
|
set text(text){
|
|
102
153
|
this._text = String(text).trim();
|
|
103
154
|
}
|
|
104
155
|
|
|
105
156
|
/**
|
|
106
|
-
*
|
|
157
|
+
* The link description.
|
|
158
|
+
* @type {string}
|
|
107
159
|
*/
|
|
108
160
|
get description(){
|
|
109
161
|
return this._description;
|
|
110
162
|
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @param {string} description
|
|
114
|
-
*/
|
|
115
163
|
set description(description){
|
|
116
164
|
this._description = String(description);
|
|
117
165
|
}
|
|
118
166
|
|
|
119
167
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* {
|
|
123
|
-
* url: 'http://www.bartificer.net/',
|
|
124
|
-
* text: 'the link text',
|
|
125
|
-
* description: 'the link description',
|
|
126
|
-
* uri: {
|
|
127
|
-
* hostname: 'www.bartificer.net',
|
|
128
|
-
* path: '/',
|
|
129
|
-
* hasPath: false
|
|
130
|
-
* }
|
|
131
|
-
* }
|
|
132
|
-
* ```
|
|
133
|
-
*
|
|
134
|
-
* Note that the `uri` could contain more fields - it's initialised with
|
|
135
|
-
* output from the `URI.parse()` function from the `URI` module.
|
|
136
|
-
*
|
|
137
|
-
* @returns {plainObject}
|
|
138
|
-
* @see {@link https://medialize.github.io/URI.js/docs.html#static-parse}
|
|
168
|
+
* The link data as a plain object for use in Mustache templates and the like.
|
|
169
|
+
* @returns {plainLinkInformationObject} A plain object containing the link data.
|
|
139
170
|
*/
|
|
140
171
|
asPlainObject(){
|
|
141
172
|
let ans = {
|
|
@@ -147,4 +178,36 @@ export class LinkData {
|
|
|
147
178
|
ans.uri.hasPath = ans.uri.path !== '/';
|
|
148
179
|
return ans;
|
|
149
180
|
}
|
|
150
|
-
};</code></pre
|
|
181
|
+
};</code></pre>
|
|
182
|
+
</article>
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<br class="clear">
|
|
193
|
+
|
|
194
|
+
<footer>
|
|
195
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Apr 15 2026 17:49:51 GMT+0100 (Irish Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
196
|
+
</footer>
|
|
197
|
+
|
|
198
|
+
<script>prettyPrint();</script>
|
|
199
|
+
<script src="scripts/polyfill.js"></script>
|
|
200
|
+
<script src="scripts/linenumber.js"></script>
|
|
201
|
+
|
|
202
|
+
<script src="scripts/search.js" defer></script>
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
<link type="text/css" rel="stylesheet" href="./docdash-overrides.css">
|
|
207
|
+
|
|
208
|
+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
|
209
|
+
|
|
210
|
+
<script src="./mermaid-init.js"></script>
|
|
211
|
+
|
|
212
|
+
</body>
|
|
213
|
+
</html>
|
|
@@ -1,29 +1,92 @@
|
|
|
1
|
-
<!DOCTYPE html
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>LinkTemplate.class.mjs - @bartificer/linkify Documentation</title>
|
|
7
|
+
|
|
8
|
+
<meta name="description" content="Documentation for the @bartificer/linkify package" />
|
|
9
|
+
|
|
10
|
+
<meta name="keywords" content="documentation, linkify, link, template, javascript, generator, npm, module, package" />
|
|
11
|
+
<meta name="keyword" content="documentation, linkify, link, template, javascript, generator, npm, module, package" />
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<meta property="og:title" content="@bartificer/linkify"/>
|
|
16
|
+
<meta property="og:type" content="website"/>
|
|
17
|
+
<meta property="og:image" content=""/>
|
|
18
|
+
<meta property="og:site_name" content="@bartificer/linkify Documentation"/>
|
|
19
|
+
<meta property="og:url" content="https://bartificer.github.io/linkify/"/>
|
|
20
|
+
|
|
21
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
22
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
23
|
+
<!--[if lt IE 9]>
|
|
24
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
25
|
+
<![endif]-->
|
|
26
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
27
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
28
|
+
<script src="scripts/nav.js" defer></script>
|
|
29
|
+
|
|
30
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
|
|
34
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
35
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
36
|
+
<div class="navicon"></div>
|
|
37
|
+
</label>
|
|
38
|
+
|
|
39
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
40
|
+
|
|
41
|
+
<nav class="wrap">
|
|
42
|
+
|
|
43
|
+
<input type="text" id="nav-search" placeholder="Search" />
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/bartificer/linkify" target="_blank" >On GitHub</a></h2><h2><a href="https://bartificer.net/" target="_blank" >Bartificer Creations</a></h2><h3>Modules</h3><ul><li><a href="module-defaults.html">defaults</a><ul class='members'><li data-type='member'><a href="module-defaults.html#.linkTemplates">linkTemplates</a></li><li data-type='member'><a href="module-defaults.html#.smallWords">smallWords</a></li><li data-type='member'><a href="module-defaults.html#.speciallyCapitalisedWords">speciallyCapitalisedWords</a></li></ul><ul class='methods'><li data-type='method'><a href="module-defaults.html#.dataTransformer">dataTransformer</a></li></ul></li><li><a href="module-link-data.html">link-data</a></li><li><a href="module-link-template.html">link-template</a></li><li><a href="module-linkifier.html">linkifier</a></li><li><a href="module-linkify.html">linkify</a><ul class='members'><li data-type='member'><a href="module-linkify.html#.LinkData">LinkData</a></li><li data-type='member'><a href="module-linkify.html#.LinkTemplate">LinkTemplate</a></li><li data-type='member'><a href="module-linkify.html#.Linkifier">Linkifier</a></li><li data-type='member'><a href="module-linkify.html#.PageData">PageData</a></li><li data-type='member'><a href="module-linkify.html#.VERSION">VERSION</a></li><li data-type='member'><a href="module-linkify.html#.default">default</a></li><li data-type='member'><a href="module-linkify.html#.linkify">linkify</a></li></ul></li><li><a href="module-page-data.html">page-data</a></li><li><a href="module-utilities.html">utilities</a><ul class='methods'><li data-type='method'><a href="module-utilities.html#.batchFixCustomWordCases">batchFixCustomWordCases</a></li><li data-type='method'><a href="module-utilities.html#.escapeRegex">escapeRegex</a></li><li data-type='method'><a href="module-utilities.html#.extractSlug">extractSlug</a></li><li data-type='method'><a href="module-utilities.html#.regulariseWhitespace">regulariseWhitespace</a></li><li data-type='method'><a href="module-utilities.html#.stripQueryString">stripQueryString</a></li><li data-type='method'><a href="module-utilities.html#.stripUTMParameters">stripUTMParameters</a></li><li data-type='method'><a href="module-utilities.html#.toTitleCase">toTitleCase</a></li></ul></li></ul><h3>Classes</h3><ul><li><a href="module-link-data.LinkData.html">LinkData</a><ul class='methods'><li data-type='method'><a href="module-link-data.LinkData.html#asPlainObject">asPlainObject</a></li></ul></li><li><a href="module-link-template.LinkTemplate.html">LinkTemplate</a><ul class='methods'><li data-type='method'><a href="module-link-template.LinkTemplate.html#addFilter">addFilter</a></li><li data-type='method'><a href="module-link-template.LinkTemplate.html#filtersFor">filtersFor</a></li></ul></li><li><a href="module-linkifier.Linkifier.html">Linkifier</a><ul class='methods'><li data-type='method'><a href="module-linkifier.Linkifier.html#fetchPageData">fetchPageData</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#generateLink">generateLink</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#getTemplate">getTemplate</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#getTemplateNameForDomain">getTemplateNameForDomain</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#getTransformerForDomain">getTransformerForDomain</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#registerDefaultTemplateMapping">registerDefaultTemplateMapping</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#registerTemplate">registerTemplate</a></li><li data-type='method'><a href="module-linkifier.Linkifier.html#registerTransformer">registerTransformer</a></li></ul></li><li><a href="module-page-data.PageData.html">PageData</a><ul class='methods'><li data-type='method'><a href="module-page-data.PageData.html#addSecondaryHeading">addSecondaryHeading</a></li><li data-type='method'><a href="module-page-data.PageData.html#addTopLevelHeading">addTopLevelHeading</a></li><li data-type='method'><a href="module-page-data.PageData.html#asPlainObject">asPlainObject</a></li><li data-type='method'><a href="module-page-data.PageData.html#h1">h1</a></li><li data-type='method'><a href="module-page-data.PageData.html#h2">h2</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#dataTransformer">dataTransformer</a></li><li><a href="global.html#plainLinkInformationObject">plainLinkInformationObject</a></li><li><a href="global.html#plainPageInformationObject">plainPageInformationObject</a></li><li><a href="global.html#templateFieldFilterFunction">templateFieldFilterFunction</a></li><li><a href="global.html#templateFieldFilterTuple">templateFieldFilterTuple</a></li></ul><h3>Externals</h3><ul><li><a href="module-cheerio.html">cheerio</a></li><li><a href="module-mustache.html">mustache</a></li><li><a href="module-node-fetch.html">node-fetch</a></li><li><a href="module-title-case.html">title-case</a></li><li><a href="module-urijs.html">urijs</a></li><li><a href="module-url-slug.html">url-slug</a></li></ul>
|
|
47
|
+
|
|
48
|
+
</nav>
|
|
49
|
+
|
|
50
|
+
<div id="main">
|
|
51
|
+
|
|
52
|
+
<h1 class="page-title">LinkTemplate.class.mjs</h1>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<section>
|
|
61
|
+
<article>
|
|
62
|
+
<pre class="prettyprint source linenums"><code>/**
|
|
63
|
+
* @file Link generation templates.
|
|
5
64
|
* @author Bart Busschots <opensource@bartificer.ie>
|
|
65
|
+
* @license MIT
|
|
6
66
|
*/
|
|
7
67
|
|
|
8
68
|
/**
|
|
9
|
-
* This module provides as class for representing
|
|
10
|
-
* @module
|
|
69
|
+
* This module provides as class for representing the templates used to generate links from link data objects.
|
|
70
|
+
* @module link-template
|
|
11
71
|
* @requires module:urijs
|
|
12
72
|
*/
|
|
13
73
|
|
|
14
74
|
/**
|
|
15
|
-
* A class representing the
|
|
75
|
+
* A class representing the templates used to render link data objects as actual links.
|
|
76
|
+
* @see {@link module:link-data.LinkData} for the data objects that are rendered with these templates.
|
|
16
77
|
*/
|
|
17
78
|
export class LinkTemplate{
|
|
18
79
|
/**
|
|
19
80
|
* @param {string} templateString - A Moustache template string.
|
|
20
|
-
* @param {
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
81
|
+
* @param {templateFieldFilterTuple[]} [filters=[]] - an optional set of filter functions to apply to some or all template fields.
|
|
82
|
+
* @example <caption>Example of defining a template with filters</caption>
|
|
83
|
+
* let template = new LinkTemplate(
|
|
84
|
+
* '<a href="{{{url}}}">{{{text}}}</a>',
|
|
85
|
+
* [
|
|
86
|
+
* ['url', linkify.util.stripUTMParameters],
|
|
87
|
+
* ['text', linkify.util.regulariseWhitespace]
|
|
88
|
+
* ]
|
|
89
|
+
* );
|
|
27
90
|
*/
|
|
28
91
|
constructor(templateString, filters){
|
|
29
92
|
// TO DO - add validation
|
|
@@ -46,7 +109,7 @@ export class LinkTemplate{
|
|
|
46
109
|
* * `description` - filters to be applied just the link description.
|
|
47
110
|
*
|
|
48
111
|
* @private
|
|
49
|
-
* @type {Object.<
|
|
112
|
+
* @type {Object.<"all"|"url"|"text"|"description", templateFieldFilterFunction>}
|
|
50
113
|
*/
|
|
51
114
|
this._filters = {
|
|
52
115
|
all: [],
|
|
@@ -64,20 +127,12 @@ export class LinkTemplate{
|
|
|
64
127
|
}
|
|
65
128
|
|
|
66
129
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @returns {string}
|
|
130
|
+
* The Mustache template string. Will be coerced to a string with `String(templateString)`.
|
|
131
|
+
* @type {string}
|
|
70
132
|
*/
|
|
71
133
|
get templateString(){
|
|
72
134
|
return this._templateString;
|
|
73
135
|
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Set the template string. Should be in Mustache format. All values passed
|
|
77
|
-
* will be coerced to strings.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} templateString
|
|
80
|
-
*/
|
|
81
136
|
set templateString(templateString){
|
|
82
137
|
this._templateString = String(templateString);
|
|
83
138
|
}
|
|
@@ -88,10 +143,9 @@ export class LinkTemplate{
|
|
|
88
143
|
* If an invalid args are passed, the function does not save the filter or
|
|
89
144
|
* throw an error, but it does log a warning.
|
|
90
145
|
*
|
|
91
|
-
* @param {
|
|
92
|
-
*
|
|
93
|
-
* @
|
|
94
|
-
* @returns {LinkTemplate} Returns a reference to self to facilitate function chaining.
|
|
146
|
+
* @param {"all"|"url"|"text"|"description"} fieldName
|
|
147
|
+
* @param {templateFieldFilterFunction} filterFn - the filter function.
|
|
148
|
+
* @returns {module:link-template.LinkTemplate} Returns a reference to self to facilitate function chaining.
|
|
95
149
|
*/
|
|
96
150
|
addFilter(fieldName, filterFn){
|
|
97
151
|
// make sure that args are at least plausibly valid
|
|
@@ -114,13 +168,11 @@ export class LinkTemplate{
|
|
|
114
168
|
}
|
|
115
169
|
|
|
116
170
|
/**
|
|
117
|
-
*
|
|
118
|
-
* field.
|
|
171
|
+
* Get the filter functions that should be applied to any given field.
|
|
119
172
|
*
|
|
120
|
-
* @param {
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* empty. An empty array is returned if an invalid field name is passed.
|
|
173
|
+
* @param {"all"|"url"|"text"|"description"} fieldName
|
|
174
|
+
* @returns {templateFieldFilterFunction[]} returns an array of callbacks, which may be
|
|
175
|
+
* empty. An empty array is also returned if an invalid field name is passed.
|
|
124
176
|
*/
|
|
125
177
|
filtersFor(fieldName){
|
|
126
178
|
fieldName = String(fieldName);
|
|
@@ -138,4 +190,36 @@ export class LinkTemplate{
|
|
|
138
190
|
}
|
|
139
191
|
return ans;
|
|
140
192
|
}
|
|
141
|
-
};</code></pre
|
|
193
|
+
};</code></pre>
|
|
194
|
+
</article>
|
|
195
|
+
</section>
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
<br class="clear">
|
|
205
|
+
|
|
206
|
+
<footer>
|
|
207
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Apr 15 2026 17:49:51 GMT+0100 (Irish Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
208
|
+
</footer>
|
|
209
|
+
|
|
210
|
+
<script>prettyPrint();</script>
|
|
211
|
+
<script src="scripts/polyfill.js"></script>
|
|
212
|
+
<script src="scripts/linenumber.js"></script>
|
|
213
|
+
|
|
214
|
+
<script src="scripts/search.js" defer></script>
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
<link type="text/css" rel="stylesheet" href="./docdash-overrides.css">
|
|
219
|
+
|
|
220
|
+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
|
221
|
+
|
|
222
|
+
<script src="./mermaid-init.js"></script>
|
|
223
|
+
|
|
224
|
+
</body>
|
|
225
|
+
</html>
|