@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,27 +1,86 @@
|
|
|
1
|
-
<!DOCTYPE html
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>PageData.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">PageData.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 web page 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 is extracted from web pages.
|
|
70
|
+
* @module page-data
|
|
11
71
|
* @requires module:urijs
|
|
12
72
|
*/
|
|
13
73
|
import {default as URI} from 'urijs';
|
|
14
74
|
|
|
15
75
|
/**
|
|
16
|
-
*
|
|
76
|
+
* The information extracted from web pages that can be used to render a link.
|
|
77
|
+
*
|
|
78
|
+
* Instances of this class are created from the information extracted from web pages and converted to link information by data transformers before being rendered to links via templates.
|
|
79
|
+
* @see {@link dataTransformer} for details of how instances of this class are used in the link generation process.
|
|
17
80
|
*/
|
|
18
81
|
export class PageData {
|
|
19
82
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @param {URL} url - The page's full URL.
|
|
23
|
-
* @throws {ValidationError} A validation error is thrown if an invalid URL
|
|
24
|
-
* is passed.
|
|
83
|
+
* @param {string} url - The page's full URL.
|
|
25
84
|
*/
|
|
26
85
|
constructor(url){
|
|
27
86
|
// TO DO - add validation
|
|
@@ -30,7 +89,7 @@ export class PageData {
|
|
|
30
89
|
* The page's URL as a URI object.
|
|
31
90
|
*
|
|
32
91
|
* @private
|
|
33
|
-
* @type {
|
|
92
|
+
* @type {module:urijs}
|
|
34
93
|
*/
|
|
35
94
|
this._uri = URI();
|
|
36
95
|
|
|
@@ -47,74 +106,73 @@ export class PageData {
|
|
|
47
106
|
* `h1` and `h2`.
|
|
48
107
|
*
|
|
49
108
|
* @private
|
|
50
|
-
* @type {
|
|
109
|
+
* @type {Object}
|
|
110
|
+
* @property {string[]} h1 - The page's top-level headings (`h1` tags).
|
|
111
|
+
* @property {string[]} h2 - The page's secondary headings (`h2` tags).
|
|
51
112
|
*/
|
|
52
113
|
this._headings = {
|
|
53
114
|
h1: [],
|
|
54
115
|
h2: []
|
|
55
116
|
};
|
|
56
117
|
|
|
57
|
-
// store the URL
|
|
118
|
+
// store the URL using the public setter to ensure it's stored as a URI object
|
|
58
119
|
this.url = url;
|
|
59
120
|
}
|
|
60
121
|
|
|
61
122
|
/**
|
|
62
|
-
* @
|
|
123
|
+
* @type {string}
|
|
124
|
+
* @throws {TypeError} on invalid URLs.
|
|
63
125
|
*/
|
|
64
126
|
get url(){
|
|
65
127
|
return this._uri.toString();
|
|
66
128
|
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @param {string} url - A URL as a string.
|
|
70
|
-
* @throws {ValidationError} A validation error is thrown if an argument
|
|
71
|
-
* is passed that's not a valid URL string.
|
|
72
|
-
*/
|
|
73
129
|
set url(url){
|
|
74
130
|
this._uri = URI(url).normalize();
|
|
75
131
|
}
|
|
76
132
|
|
|
77
133
|
/**
|
|
78
|
-
* @
|
|
134
|
+
* @type {module:urijs}
|
|
135
|
+
* @readonly
|
|
79
136
|
*/
|
|
80
137
|
get uri(){
|
|
81
138
|
return this._uri.clone();
|
|
82
139
|
}
|
|
83
140
|
|
|
84
141
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
142
|
+
* The domain-part of the URL.
|
|
143
|
+
* @type {string}
|
|
144
|
+
* @readonly
|
|
88
145
|
*/
|
|
89
146
|
get domain(){
|
|
90
147
|
return this._uri.hostname();
|
|
91
148
|
}
|
|
92
149
|
|
|
93
150
|
/**
|
|
94
|
-
*
|
|
151
|
+
* The path-part of the URL.
|
|
152
|
+
* @type {string}
|
|
153
|
+
* @readonly
|
|
95
154
|
*/
|
|
96
155
|
get path(){
|
|
97
156
|
return this._uri.path();
|
|
98
157
|
}
|
|
99
158
|
|
|
100
159
|
/**
|
|
101
|
-
*
|
|
160
|
+
* The page's title. Values are coerced to strings with `String(title)`.
|
|
161
|
+
* @type {string}
|
|
102
162
|
*/
|
|
103
163
|
get title(){
|
|
104
164
|
return this._title;
|
|
105
165
|
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @param {string} title - the page's title as a string. Values passed will be coerced to strings.
|
|
109
|
-
*/
|
|
110
166
|
set title(title){
|
|
111
167
|
this._title = String(title);
|
|
112
168
|
}
|
|
113
169
|
|
|
114
170
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @
|
|
171
|
+
* The page's primary and secondary headings.
|
|
172
|
+
* @type {Object}
|
|
173
|
+
* @property {string[]} h1 - The page's top-level headings (`h1` tags).
|
|
174
|
+
* @property {string[]} h2 - The page's secondary headings (`h2` tags).
|
|
175
|
+
* @readonly
|
|
118
176
|
*/
|
|
119
177
|
get headings(){
|
|
120
178
|
let ans = {
|
|
@@ -132,8 +190,8 @@ export class PageData {
|
|
|
132
190
|
|
|
133
191
|
/**
|
|
134
192
|
* The page's top-level headings (`h1` tags).
|
|
135
|
-
*
|
|
136
|
-
* @
|
|
193
|
+
* @type {string[]}
|
|
194
|
+
* @readonly
|
|
137
195
|
*/
|
|
138
196
|
get topLevelHeadings(){
|
|
139
197
|
var ans = [];
|
|
@@ -145,7 +203,8 @@ export class PageData {
|
|
|
145
203
|
|
|
146
204
|
/**
|
|
147
205
|
* An alias for `.topLevelHeadings`.
|
|
148
|
-
* @
|
|
206
|
+
* @readonly
|
|
207
|
+
* @see {@link module:page-data.PageData#topLevelHeadings}
|
|
149
208
|
*/
|
|
150
209
|
get h1s(){
|
|
151
210
|
return this.topLevelHeadings;
|
|
@@ -153,8 +212,8 @@ export class PageData {
|
|
|
153
212
|
|
|
154
213
|
/**
|
|
155
214
|
* The page's secondary headings (`h2` tags).
|
|
156
|
-
*
|
|
157
|
-
* @
|
|
215
|
+
* @type {string[]}
|
|
216
|
+
* @readonly
|
|
158
217
|
*/
|
|
159
218
|
get secondaryHeadings(){
|
|
160
219
|
var ans = [];
|
|
@@ -166,8 +225,9 @@ export class PageData {
|
|
|
166
225
|
|
|
167
226
|
/**
|
|
168
227
|
* An alias for `.secondaryHeadings`.
|
|
169
|
-
* @
|
|
170
|
-
|
|
228
|
+
* @readonly
|
|
229
|
+
* @see {@link module:page-data.PageData#secondaryHeadings}
|
|
230
|
+
*/
|
|
171
231
|
get h2s(){
|
|
172
232
|
return this.secondaryHeadings;
|
|
173
233
|
}
|
|
@@ -177,8 +237,8 @@ export class PageData {
|
|
|
177
237
|
* has `h1` tags, the first one will be used, if not, the first `h2` tag
|
|
178
238
|
* will be used, and if there's none of those either, an empty string will
|
|
179
239
|
* be returned.
|
|
180
|
-
*
|
|
181
|
-
* @
|
|
240
|
+
* @type {string}
|
|
241
|
+
* @readonly
|
|
182
242
|
*/
|
|
183
243
|
get mainHeading(){
|
|
184
244
|
if(this._headings.h1.length > 0){
|
|
@@ -194,7 +254,7 @@ export class PageData {
|
|
|
194
254
|
* Add a top-level heading.
|
|
195
255
|
*
|
|
196
256
|
* @param {string} h1Text
|
|
197
|
-
* @returns {PageData} A reference to self to
|
|
257
|
+
* @returns {module:page-data.PageData} A reference to self to
|
|
198
258
|
* facilitate function chaning.
|
|
199
259
|
*/
|
|
200
260
|
addTopLevelHeading(h1Text){
|
|
@@ -207,7 +267,7 @@ export class PageData {
|
|
|
207
267
|
* Add a seconary heading.
|
|
208
268
|
*
|
|
209
269
|
* @param {string} h2Text
|
|
210
|
-
* @returns {PageData} A reference to self to
|
|
270
|
+
* @returns {module:page-data.PageData} A reference to self to
|
|
211
271
|
* facilitate function chaning.
|
|
212
272
|
*/
|
|
213
273
|
addSecondaryHeading(h2Text){
|
|
@@ -217,27 +277,8 @@ export class PageData {
|
|
|
217
277
|
}
|
|
218
278
|
|
|
219
279
|
/**
|
|
220
|
-
* Get the page data as a plain object
|
|
221
|
-
*
|
|
222
|
-
* {
|
|
223
|
-
* url: 'http://www.bartificer.net/',
|
|
224
|
-
* title: 'the page title',
|
|
225
|
-
* topLevelHeadings: [ 'first h1', 'second h1' ],
|
|
226
|
-
* secondaryHeadings: [ 'first h2', 'second h2' ],
|
|
227
|
-
* mainHeading: 'first h1',
|
|
228
|
-
* uri: {
|
|
229
|
-
* hostname: 'www.bartificer.net',
|
|
230
|
-
* path: '/',
|
|
231
|
-
* hasPath: false
|
|
232
|
-
* }
|
|
233
|
-
* }
|
|
234
|
-
* ```
|
|
235
|
-
*
|
|
236
|
-
* Note that the `uri` could contain more fields - it's initialised with
|
|
237
|
-
* output from the `URI.parse()` function from the `URI` module.
|
|
238
|
-
*
|
|
239
|
-
* @returns {Object} A plain object containing the page data.
|
|
240
|
-
* @see {@link https://medialize.github.io/URI.js/docs.html#static-parse}
|
|
280
|
+
* Get the page data as a plain object.
|
|
281
|
+
* @returns {plainPageInformationObject}
|
|
241
282
|
*/
|
|
242
283
|
asPlainObject(){
|
|
243
284
|
let ans = {
|
|
@@ -255,18 +296,50 @@ export class PageData {
|
|
|
255
296
|
|
|
256
297
|
/**
|
|
257
298
|
* A shortcut for `.addTopLevelHeading()`.
|
|
258
|
-
*
|
|
299
|
+
* @name module:page-data.PageData#h1
|
|
259
300
|
* @function
|
|
260
|
-
* @see PageData#addTopLevelHeading
|
|
301
|
+
* @see {@link module:page-data.PageData#addTopLevelHeading}
|
|
261
302
|
*
|
|
262
303
|
*/
|
|
263
304
|
PageData.prototype.h1 = PageData.prototype.addTopLevelHeading;
|
|
264
305
|
|
|
265
306
|
/**
|
|
266
307
|
* A shortcut for `.addSecondaryHeading()`.
|
|
267
|
-
*
|
|
308
|
+
* @name module:page-data.PageData#h2
|
|
268
309
|
* @function
|
|
269
|
-
* @see PageData#addSecondaryHeading
|
|
310
|
+
* @see {@link module:page-data.PageData#addSecondaryHeading}
|
|
270
311
|
*
|
|
271
312
|
*/
|
|
272
|
-
PageData.prototype.h2 = PageData.prototype.addSecondaryHeading;</code></pre
|
|
313
|
+
PageData.prototype.h2 = PageData.prototype.addSecondaryHeading;</code></pre>
|
|
314
|
+
</article>
|
|
315
|
+
</section>
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
</div>
|
|
323
|
+
|
|
324
|
+
<br class="clear">
|
|
325
|
+
|
|
326
|
+
<footer>
|
|
327
|
+
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.
|
|
328
|
+
</footer>
|
|
329
|
+
|
|
330
|
+
<script>prettyPrint();</script>
|
|
331
|
+
<script src="scripts/polyfill.js"></script>
|
|
332
|
+
<script src="scripts/linenumber.js"></script>
|
|
333
|
+
|
|
334
|
+
<script src="scripts/search.js" defer></script>
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
<link type="text/css" rel="stylesheet" href="./docdash-overrides.css">
|
|
339
|
+
|
|
340
|
+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
|
341
|
+
|
|
342
|
+
<script src="./mermaid-init.js"></script>
|
|
343
|
+
|
|
344
|
+
</body>
|
|
345
|
+
</html>
|
package/docs/defaults.mjs.html
CHANGED
|
@@ -1,22 +1,105 @@
|
|
|
1
|
-
<!DOCTYPE html
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>defaults.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">defaults.mjs</h1>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<section>
|
|
61
|
+
<article>
|
|
62
|
+
<pre class="prettyprint source linenums"><code>/**
|
|
63
|
+
* @file Central location for the default values used throughout the codebase.
|
|
5
64
|
* @author Bart Busschots <opensource@bartificer.ie>
|
|
65
|
+
* @license MIT
|
|
6
66
|
*/
|
|
7
67
|
|
|
8
68
|
/**
|
|
9
|
-
*
|
|
69
|
+
* Default values used by the various functions and classes.
|
|
70
|
+
*
|
|
71
|
+
* The defaults are collected here for clarity, helping module users both understand the defaults, and, make informed decisions about which defaults to augment or override completely.
|
|
10
72
|
* @module defaults
|
|
11
|
-
* @requires
|
|
12
|
-
* @requires
|
|
73
|
+
* @requires link-template
|
|
74
|
+
* @requires utilities
|
|
13
75
|
*/
|
|
14
76
|
import { LinkTemplate } from './LinkTemplate.class.mjs';
|
|
15
77
|
import * as utilities from "./utilities.mjs";
|
|
16
78
|
|
|
17
79
|
/**
|
|
18
|
-
* The
|
|
19
|
-
*
|
|
80
|
+
* The default link transformer. The Linkifier constructor assigns this data transformer to the root DNS name `.`, ensuring it acts as the fallback when no other domains are matched.
|
|
81
|
+
*
|
|
82
|
+
* If the page has exactly one top-level heading, this heading is used as a the link text, otherwise the page title is used.
|
|
83
|
+
*
|
|
84
|
+
* The description field is not explicitly set, so will default to the link text.
|
|
85
|
+
* @type {dataTransformer}
|
|
86
|
+
*/
|
|
87
|
+
export function dataTransformer(pData){
|
|
88
|
+
let text = pData.title;
|
|
89
|
+
if(pData.h1s.length === 1){
|
|
90
|
+
text = pData.mainHeading;
|
|
91
|
+
}
|
|
92
|
+
return new LinkData(pData.url, text);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The collection of named link templates loaded by the Linkifier constructor. All templates strip UTM parameters from the URL, and regularise white space in the text and descriptions.
|
|
97
|
+
* @type {Object.<string, module:link-template.LinkTemplate>}
|
|
98
|
+
* @property {module:link-template.LinkTemplate} html - The default HTML link template. Uses the link title as a the text and description as the hover-text.
|
|
99
|
+
* @property {module:link-template.LinkTemplate} htmlNewTab - The same as the `html` template, but with a `target="_blank"` attribute added.
|
|
100
|
+
* @property {module:link-template.LinkTemplate} markdown - The default Markdown link template. Uses the link title as the text, and ignores the description.
|
|
101
|
+
* @see {@link module:utilities.stripUTMParameters} for the function used to strip UTM parameters from the URL.
|
|
102
|
+
* @see {@link module:utilities.regulariseWhitespace} for the function used to regularise white space in the text and description.
|
|
20
103
|
*/
|
|
21
104
|
export const linkTemplates = {
|
|
22
105
|
html: new LinkTemplate(
|
|
@@ -45,8 +128,18 @@ export const linkTemplates = {
|
|
|
45
128
|
};
|
|
46
129
|
|
|
47
130
|
/**
|
|
48
|
-
*
|
|
131
|
+
* When conbverting strings to title case, some joiner words should be preserved in all lower case. The Title Case module handles most appropriately, but not all.
|
|
132
|
+
* These are the additional words that also treated as so-called *small words* by the functions in the utility module.
|
|
133
|
+
* @type {string[]}
|
|
134
|
+
* @see {@link module:utilities.toTitleCase} for the function that uses this list to treat these words as small words by default.
|
|
135
|
+
* @see {@link module:title-case} for the Title Case module who's default small word list is augmented by this list.
|
|
136
|
+
*/
|
|
137
|
+
export const smallWords = [ 'is', 'its' ];
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* When converting strings to title case, some words need to have their capitalisations corrected. These are the custom capitalisations that will be used by default.
|
|
49
141
|
* @type {string[]}
|
|
142
|
+
* @see {@link module:utilities.toTitleCase} for the function that uses this list to correct capitalisations by default.
|
|
50
143
|
*/
|
|
51
144
|
export const speciallyCapitalisedWords = [
|
|
52
145
|
// generic acronyms
|
|
@@ -102,5 +195,36 @@ export const speciallyCapitalisedWords = [
|
|
|
102
195
|
'DisplayPort',
|
|
103
196
|
'LinkedIn',
|
|
104
197
|
'ChatGPT'
|
|
105
|
-
]
|
|
106
|
-
</
|
|
198
|
+
];</code></pre>
|
|
199
|
+
</article>
|
|
200
|
+
</section>
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
<br class="clear">
|
|
210
|
+
|
|
211
|
+
<footer>
|
|
212
|
+
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.
|
|
213
|
+
</footer>
|
|
214
|
+
|
|
215
|
+
<script>prettyPrint();</script>
|
|
216
|
+
<script src="scripts/polyfill.js"></script>
|
|
217
|
+
<script src="scripts/linenumber.js"></script>
|
|
218
|
+
|
|
219
|
+
<script src="scripts/search.js" defer></script>
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
<link type="text/css" rel="stylesheet" href="./docdash-overrides.css">
|
|
224
|
+
|
|
225
|
+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
|
226
|
+
|
|
227
|
+
<script src="./mermaid-init.js"></script>
|
|
228
|
+
|
|
229
|
+
</body>
|
|
230
|
+
</html>
|