@bartificer/linkify 2.4.0 → 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.
Files changed (41) hide show
  1. package/README.md +135 -35
  2. package/dist/index.js +1 -1
  3. package/docs/LinkData.class.mjs.html +28 -53
  4. package/docs/LinkTemplate.class.mjs.html +29 -33
  5. package/docs/Linkifier.class.mjs.html +46 -59
  6. package/docs/PageData.class.mjs.html +54 -69
  7. package/docs/defaults.mjs.html +22 -2
  8. package/docs/docdash-overrides.css +9 -3
  9. package/docs/externals.jsdoc.html +6 -2
  10. package/docs/global.html +1276 -0
  11. package/docs/index.html +114 -45
  12. package/docs/index.js.html +7 -3
  13. package/docs/mermaid-init.js +21 -0
  14. package/docs/module-cheerio.html +6 -2
  15. package/docs/module-defaults.html +100 -5
  16. package/docs/module-link-data.LinkData.html +81 -212
  17. package/docs/module-link-data.html +8 -4
  18. package/docs/module-link-template.LinkTemplate.html +71 -96
  19. package/docs/module-link-template.html +8 -4
  20. package/docs/module-linkifier.Linkifier.html +103 -376
  21. package/docs/module-linkifier.html +6 -2
  22. package/docs/module-linkify.html +7 -3
  23. package/docs/module-mustache.html +6 -2
  24. package/docs/module-node-fetch.html +6 -2
  25. package/docs/module-page-data.PageData.html +224 -202
  26. package/docs/module-page-data.html +8 -4
  27. package/docs/module-title-case.html +6 -2
  28. package/docs/module-urijs.html +6 -2
  29. package/docs/module-url-slug.html +6 -2
  30. package/docs/module-utilities.html +74 -24
  31. package/docs/typedefs.jsdoc.html +145 -0
  32. package/docs/utilities.mjs.html +36 -23
  33. package/package.json +3 -2
  34. package/src/LinkData.class.mjs +22 -51
  35. package/src/LinkTemplate.class.mjs +23 -31
  36. package/src/Linkifier.class.mjs +40 -57
  37. package/src/PageData.class.mjs +48 -67
  38. package/src/defaults.mjs +16 -0
  39. package/src/index.js +1 -1
  40. package/src/typedefs.jsdoc +52 -0
  41. package/src/utilities.mjs +30 -21
@@ -43,7 +43,7 @@
43
43
  <input type="text" id="nav-search" placeholder="Search" />
44
44
 
45
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></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>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>
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
47
 
48
48
  </nav>
49
49
 
@@ -89,28 +89,26 @@ import Mustache from 'mustache';
89
89
  * The class providing the link rendering functionality. Instances of this class capture the settings for generating links, and, generate links using these settings.
90
90
  */
91
91
  export class Linkifier {
92
+ /**
93
+ * Builds a Linkifier instance ready for use rendering links using the default configration.
94
+ * @see {@link module:defaults} for the default configuration settings.
95
+ */
92
96
  constructor(){
93
97
  /**
94
- * A mapping of domain names to data transformation functions.
98
+ * A mapping of fully qualified domain names to data transformation functions.
95
99
  *
96
100
  * @private
97
- * @type {Object.&lt;FQDN, dataTransformer>}
101
+ * @type {Object.&lt;string, dataTransformer>}
98
102
  */
99
103
  this._pageDataToLinkDataTransmformers = {
100
- '.' : function(pData){
101
- let text = pData.title;
102
- if(pData.h1s.length === 1){
103
- text = pData.mainHeading;
104
- }
105
- return new LinkData(pData.url, text);
106
- }
104
+ '.' : defaults.dataTransformer
107
105
  };
108
106
 
109
107
  /**
110
- * A mapping of domains names to default template names.
108
+ * A mapping of fully qualified domain names to default template names.
111
109
  *
112
110
  * @private
113
- * @type {Object.&lt;FQDN, templateName>}
111
+ * @type {Object.&lt;string, string>}
114
112
  */
115
113
  this._pageDataToLinkTemplateName = {
116
114
  '.' : 'html' // default to the 'html' template for all domains unless otherwise specified
@@ -120,7 +118,7 @@ export class Linkifier {
120
118
  * The registered link templates.
121
119
  *
122
120
  * @private
123
- * @type {Object.&lt;templateName, module:@bartificer/linkify.LinkTemplate>}
121
+ * @type {Object.&lt;string, module:link-template.LinkTemplate>}
124
122
  */
125
123
  this._linkTemplates = {};
126
124
 
@@ -151,30 +149,30 @@ export class Linkifier {
151
149
 
152
150
  /**
153
151
  * @type {Object.&lt;string, Function>}
152
+ * @readonly
153
+ * @see {@link module:utilities} for the utility functions available in this collection.
154
154
  */
155
155
  get utilities() {
156
156
  return this._utilities;
157
157
  }
158
158
 
159
159
  /**
160
- * @see Linfifier.utilities
160
+ * Shorthand property for `.utilities`.
161
+ * @see {@link module:linkifier.Linkifier#utilities}
161
162
  */
162
163
  get util(){
163
164
  return this._utilities;
164
165
  }
165
166
 
166
167
  /**
167
- * @returns {string[]} The current list of known words with special capitalisations.
168
+ * The list of known words with special capitalisations. The words should be capitalised in the descired manner.
169
+ * @type {string[]}
168
170
  */
169
171
  get speciallyCapitalisedWords(){
170
172
  const ans = [];
171
173
  this._speciallyCapitalisedWords.map(word => ans.push(word));
172
174
  return ans;
173
175
  }
174
-
175
- /**
176
- * @param {string[]} words - a list of words with special capitalisations
177
- */
178
176
  set speciallyCapitalisedWords(words){
179
177
  // TO DO - add validation
180
178
 
@@ -182,13 +180,11 @@ export class Linkifier {
182
180
  }
183
181
 
184
182
  /**
185
- * Register a data transformer function for a given domain.
183
+ * Register a data transformer function to a domain name.
186
184
  *
187
- * @param {domainName} domain - The domain for which this transformer should be
185
+ * @param {string} domain - The fully qualified domain for which this transformer should be
188
186
  * used.
189
187
  * @param {dataTransformer} transformerFn - The data transformer callback.
190
- * @throws {ValidationError} A validation error is thrown if either parameter
191
- * is missing or invalid.
192
188
  */
193
189
  registerTransformer(domain, transformerFn){
194
190
  // TO DO - add validation
@@ -204,16 +200,14 @@ export class Linkifier {
204
200
  * Get the data transformer function for a given domain.
205
201
  *
206
202
  * Note that domains are searched from the subdomain up. For example, if passed
207
- * the domain `www.bartificer.net` the function will first look for a
208
- * transformer for the domain `www.bartificer.net`, if there's no transformer
203
+ * the domain `www.bartificer.ie` the function will first look for a
204
+ * transformer for the domain `www.bartificer.ie`, if there's no transformer
209
205
  * registered for that domain it will look for a transformer for the domain
210
- * `bartificer.net`, if there's no transformer for that domain either it will
206
+ * `bartificer.ie`, if there's no transformer for that domain either it will
211
207
  * return the default transformer.
212
208
  *
213
- * @param {domainName} domain - The domain to get the data transformer for.
209
+ * @param {string} domain - The fully qualified domain for which to get the data transformer.
214
210
  * @returns {dataTransformer}
215
- * @throws {ValidationError} A validation error is thrown unless a valid domain
216
- * name is passed.
217
211
  */
218
212
  getTransformerForDomain(domain){
219
213
  // TO DO - add validation
@@ -239,22 +233,20 @@ export class Linkifier {
239
233
  /**
240
234
  * A list of the names of the registered link templates.
241
235
  * @type {string[]}
236
+ * @readonly
242
237
  */
243
238
  get templateNames() {
244
239
  return Object.keys(this._linkTemplates);
245
240
  }
246
241
 
247
242
  /**
248
- * @returns {string} The name of the default template.
243
+ * The name of the default template used when rendering links.
244
+ * @type {string}
245
+ * @throws {ValidationError} A validation error is thrown if the template name is missing, invalid, or doesn't correspond to a registered template.
249
246
  */
250
247
  get defaultTemplateName(){
251
248
  return this._pageDataToLinkTemplateName['.'];
252
249
  }
253
-
254
- /**
255
- * @param {string} templateName - The name of the default template to use.
256
- * @throws {ValidationError} A validation error is thrown if the template name is missing, invalid, or doesn't correspond to a registered template.
257
- */
258
250
  set defaultTemplateName(templateName){
259
251
  const tplName = String(templateName);
260
252
  if(!this._linkTemplates[tplName]){
@@ -265,7 +257,8 @@ export class Linkifier {
265
257
 
266
258
  /**
267
259
  * The default link template.
268
- * @type {module:LinkTemplate.class.LinkTemplate}
260
+ * @type {module:link-template.LinkTemplate}
261
+ * @readonly
269
262
  */
270
263
  get defaultTemplate(){
271
264
  return this._linkTemplates[this._pageDataToLinkTemplateName['.']];
@@ -275,9 +268,7 @@ export class Linkifier {
275
268
  * Register a link template.
276
269
  *
277
270
  * @param {string} name
278
- * @param {LinkTemplate} template
279
- * @throws {ValidationError} A validation error is thrown unless both a valid
280
- * name and template object are passed.
271
+ * @param {module:link-template.LinkTemplate} template
281
272
  */
282
273
  registerTemplate(name, template){
283
274
  // TO DO - add validation
@@ -290,7 +281,7 @@ export class Linkifier {
290
281
  * Get a registered link template by name.
291
282
  *
292
283
  * @param {string} templateName
293
- * @returns {LinkTemplate}
284
+ * @returns {module:link-template.LinkTemplate}
294
285
  * @throws {ValidationError} A validation error is thrown unless a valid name is passed and corresponds to a registered template.
295
286
  */
296
287
  getTemplate(templateName){
@@ -306,10 +297,8 @@ export class Linkifier {
306
297
  * Register a default template for use with a given domain. This template will
307
298
  * override the overall default for this domain and all its subdomains.
308
299
  *
309
- * @param {domainName} domain - The domain for which this template should be used by default.
310
- * @param {templateName} templateName - The name of the template to use.
311
- * @throws {ValidationError} A validation error is thrown if either parameter
312
- * is missing or invalid.
300
+ * @param {string} domain - The fully qualified domain name for which this template should be used by default.
301
+ * @param {string} templateName - The name of the template to use.
313
302
  */
314
303
  registerDefaultTemplateMapping(domain, templateName){
315
304
  // TO DO - add validation
@@ -325,16 +314,14 @@ export class Linkifier {
325
314
  * Get the data transformer function for a given domain.
326
315
  *
327
316
  * Note that domains are searched from the subdomain up. For example, if passed
328
- * the domain `www.bartificer.net` the function will first look for a
329
- * transformer for the domain `www.bartificer.net`, if there's no transformer
317
+ * the domain `www.bartificer.ie` the function will first look for a
318
+ * transformer for the domain `www.bartificer.ie`, if there's no transformer
330
319
  * registered for that domain it will look for a transformer for the domain
331
- * `bartificer.net`, if there's no transformer for that domain either it will
320
+ * `bartificer.ie`, if there's no transformer for that domain either it will
332
321
  * return the default transformer.
333
322
  *
334
- * @param {domainName} domain - The domain to get the data transformer for.
323
+ * @param {string} domain - The fully qualified domain name to get the data transformer for.
335
324
  * @returns {dataTransformer}
336
- * @throws {ValidationError} A validation error is thrown unless a valid domain
337
- * name is passed.
338
325
  */
339
326
  getTemplateNameForDomain(domain){
340
327
  // TO DO - add validation
@@ -369,10 +356,8 @@ export class Linkifier {
369
356
  * Fetch the page data for a given URL.
370
357
  *
371
358
  * @async
372
- * @param {URL} url
373
- * @returns {PageData}
374
- * @throws {ValidationError} A validation error is thrown unless a valid URL is
375
- * passed.
359
+ * @param {string} url
360
+ * @returns {module:page-data.PageData}
376
361
  */
377
362
  async fetchPageData(url){
378
363
  // TO DO - add validation
@@ -412,11 +397,9 @@ export class Linkifier {
412
397
  * default will be used (`html`).
413
398
  *
414
399
  * @async
415
- * @param {URL} url
416
- * @param {templateName} [templateName='html']
400
+ * @param {string} url
401
+ * @param {string} [templateName='html']
417
402
  * @returns {string}
418
- * @throws {ValidationError} A validation error is thrown unless a valid URL is
419
- * passed.
420
403
  */
421
404
  async generateLink(url, templateName){
422
405
  // TO DO - add validation
@@ -482,7 +465,7 @@ export class Linkifier {
482
465
  <br class="clear">
483
466
 
484
467
  <footer>
485
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Apr 13 2026 16:45:07 GMT+0100 (Irish Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
468
+ 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.
486
469
  </footer>
487
470
 
488
471
  <script>prettyPrint();</script>
@@ -495,5 +478,9 @@ export class Linkifier {
495
478
 
496
479
  <link type="text/css" rel="stylesheet" href="./docdash-overrides.css">
497
480
 
481
+ <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
482
+
483
+ <script src="./mermaid-init.js"></script>
484
+
498
485
  </body>
499
486
  </html>
@@ -43,7 +43,7 @@
43
43
  <input type="text" id="nav-search" placeholder="Search" />
44
44
 
45
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></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>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>
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
47
 
48
48
  </nav>
49
49
 
@@ -60,28 +60,27 @@
60
60
  <section>
61
61
  <article>
62
62
  <pre class="prettyprint source linenums"><code>/**
63
- * @file The definition of the class representing a web page.
63
+ * @file Data model for web page information.
64
64
  * @author Bart Busschots &lt;opensource@bartificer.ie>
65
65
  * @license MIT
66
66
  */
67
67
 
68
68
  /**
69
- * This module provides as class for representing the information extracted from web pages which can be used to generate the link data avaiable for rendering links.
69
+ * This module provides the class for representing the information that is extracted from web pages.
70
70
  * @module page-data
71
71
  * @requires module:urijs
72
72
  */
73
73
  import {default as URI} from 'urijs';
74
74
 
75
75
  /**
76
- * A class representing the data extracted from web pages that can be transformed into link data for use when rendering links.
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.
77
80
  */
78
81
  export class PageData {
79
82
  /**
80
- * This constructor throws a {@link ValidationError} unless a valid URL is passed.
81
- *
82
- * @param {URL} url - The page's full URL.
83
- * @throws {ValidationError} A validation error is thrown if an invalid URL
84
- * is passed.
83
+ * @param {string} url - The page's full URL.
85
84
  */
86
85
  constructor(url){
87
86
  // TO DO - add validation
@@ -90,7 +89,7 @@ export class PageData {
90
89
  * The page's URL as a URI object.
91
90
  *
92
91
  * @private
93
- * @type {URIObject}
92
+ * @type {module:urijs}
94
93
  */
95
94
  this._uri = URI();
96
95
 
@@ -107,74 +106,73 @@ export class PageData {
107
106
  * `h1` and `h2`.
108
107
  *
109
108
  * @private
110
- * @type {plainObject}
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).
111
112
  */
112
113
  this._headings = {
113
114
  h1: [],
114
115
  h2: []
115
116
  };
116
117
 
117
- // store the URL
118
+ // store the URL using the public setter to ensure it's stored as a URI object
118
119
  this.url = url;
119
120
  }
120
121
 
121
122
  /**
122
- * @returns {string}
123
+ * @type {string}
124
+ * @throws {TypeError} on invalid URLs.
123
125
  */
124
126
  get url(){
125
127
  return this._uri.toString();
126
128
  }
127
-
128
- /**
129
- * @param {string} url - A URL as a string.
130
- * @throws {ValidationError} A validation error is thrown if an argument
131
- * is passed that's not a valid URL string.
132
- */
133
129
  set url(url){
134
130
  this._uri = URI(url).normalize();
135
131
  }
136
132
 
137
133
  /**
138
- * @returns {Object} A URI.js object.
134
+ * @type {module:urijs}
135
+ * @readonly
139
136
  */
140
137
  get uri(){
141
138
  return this._uri.clone();
142
139
  }
143
140
 
144
141
  /**
145
- * Get the domain-part of the URL as a string.
146
- *
147
- * @returns {string} The domain-part of the URL.
142
+ * The domain-part of the URL.
143
+ * @type {string}
144
+ * @readonly
148
145
  */
149
146
  get domain(){
150
147
  return this._uri.hostname();
151
148
  }
152
149
 
153
150
  /**
154
- * @returns {string} The path-part of the URL.
151
+ * The path-part of the URL.
152
+ * @type {string}
153
+ * @readonly
155
154
  */
156
155
  get path(){
157
156
  return this._uri.path();
158
157
  }
159
158
 
160
159
  /**
161
- * @returns {string}
160
+ * The page's title. Values are coerced to strings with `String(title)`.
161
+ * @type {string}
162
162
  */
163
163
  get title(){
164
164
  return this._title;
165
165
  }
166
-
167
- /**
168
- * @param {string} title - the page's title as a string. Values passed will be coerced to strings.
169
- */
170
166
  set title(title){
171
167
  this._title = String(title);
172
168
  }
173
169
 
174
170
  /**
175
- * Get the page's section headings.
176
- *
177
- * @returns {Object} A plain object containing arrays of strings indexed by `h1` and `h2`.
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
178
176
  */
179
177
  get headings(){
180
178
  let ans = {
@@ -192,8 +190,8 @@ export class PageData {
192
190
 
193
191
  /**
194
192
  * The page's top-level headings (`h1` tags).
195
- *
196
- * @returns {string[]}
193
+ * @type {string[]}
194
+ * @readonly
197
195
  */
198
196
  get topLevelHeadings(){
199
197
  var ans = [];
@@ -205,7 +203,8 @@ export class PageData {
205
203
 
206
204
  /**
207
205
  * An alias for `.topLevelHeadings`.
208
- * @see PageData#topLevelHeadings
206
+ * @readonly
207
+ * @see {@link module:page-data.PageData#topLevelHeadings}
209
208
  */
210
209
  get h1s(){
211
210
  return this.topLevelHeadings;
@@ -213,8 +212,8 @@ export class PageData {
213
212
 
214
213
  /**
215
214
  * The page's secondary headings (`h2` tags).
216
- *
217
- * @returns {string[]}
215
+ * @type {string[]}
216
+ * @readonly
218
217
  */
219
218
  get secondaryHeadings(){
220
219
  var ans = [];
@@ -226,8 +225,9 @@ export class PageData {
226
225
 
227
226
  /**
228
227
  * An alias for `.secondaryHeadings`.
229
- * @see PageData#secondaryHeadings
230
- */
228
+ * @readonly
229
+ * @see {@link module:page-data.PageData#secondaryHeadings}
230
+ */
231
231
  get h2s(){
232
232
  return this.secondaryHeadings;
233
233
  }
@@ -237,8 +237,8 @@ export class PageData {
237
237
  * has `h1` tags, the first one will be used, if not, the first `h2` tag
238
238
  * will be used, and if there's none of those either, an empty string will
239
239
  * be returned.
240
- *
241
- * @returns {string} Heading text as a string, or an empty string.
240
+ * @type {string}
241
+ * @readonly
242
242
  */
243
243
  get mainHeading(){
244
244
  if(this._headings.h1.length > 0){
@@ -254,7 +254,7 @@ export class PageData {
254
254
  * Add a top-level heading.
255
255
  *
256
256
  * @param {string} h1Text
257
- * @returns {PageData} A reference to self to
257
+ * @returns {module:page-data.PageData} A reference to self to
258
258
  * facilitate function chaning.
259
259
  */
260
260
  addTopLevelHeading(h1Text){
@@ -267,7 +267,7 @@ export class PageData {
267
267
  * Add a seconary heading.
268
268
  *
269
269
  * @param {string} h2Text
270
- * @returns {PageData} A reference to self to
270
+ * @returns {module:page-data.PageData} A reference to self to
271
271
  * facilitate function chaning.
272
272
  */
273
273
  addSecondaryHeading(h2Text){
@@ -277,27 +277,8 @@ export class PageData {
277
277
  }
278
278
 
279
279
  /**
280
- * Get the page data as a plain object of the form:
281
- * ```
282
- * {
283
- * url: 'http://www.bartificer.net/',
284
- * title: 'the page title',
285
- * topLevelHeadings: [ 'first h1', 'second h1' ],
286
- * secondaryHeadings: [ 'first h2', 'second h2' ],
287
- * mainHeading: 'first h1',
288
- * uri: {
289
- * hostname: 'www.bartificer.net',
290
- * path: '/',
291
- * hasPath: false
292
- * }
293
- * }
294
- * ```
295
- *
296
- * Note that the `uri` could contain more fields - it's initialised with
297
- * output from the `URI.parse()` function from the `URI` module.
298
- *
299
- * @returns {Object} A plain object containing the page data.
300
- * @see {@link https://medialize.github.io/URI.js/docs.html#static-parse}
280
+ * Get the page data as a plain object.
281
+ * @returns {plainPageInformationObject}
301
282
  */
302
283
  asPlainObject(){
303
284
  let ans = {
@@ -315,18 +296,18 @@ export class PageData {
315
296
 
316
297
  /**
317
298
  * A shortcut for `.addTopLevelHeading()`.
318
- *
299
+ * @name module:page-data.PageData#h1
319
300
  * @function
320
- * @see PageData#addTopLevelHeading
301
+ * @see {@link module:page-data.PageData#addTopLevelHeading}
321
302
  *
322
303
  */
323
304
  PageData.prototype.h1 = PageData.prototype.addTopLevelHeading;
324
305
 
325
306
  /**
326
307
  * A shortcut for `.addSecondaryHeading()`.
327
- *
308
+ * @name module:page-data.PageData#h2
328
309
  * @function
329
- * @see PageData#addSecondaryHeading
310
+ * @see {@link module:page-data.PageData#addSecondaryHeading}
330
311
  *
331
312
  */
332
313
  PageData.prototype.h2 = PageData.prototype.addSecondaryHeading;</code></pre>
@@ -343,7 +324,7 @@ PageData.prototype.h2 = PageData.prototype.addSecondaryHeading;</code></pre>
343
324
  <br class="clear">
344
325
 
345
326
  <footer>
346
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Apr 13 2026 16:45:07 GMT+0100 (Irish Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
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.
347
328
  </footer>
348
329
 
349
330
  <script>prettyPrint();</script>
@@ -356,5 +337,9 @@ PageData.prototype.h2 = PageData.prototype.addSecondaryHeading;</code></pre>
356
337
 
357
338
  <link type="text/css" rel="stylesheet" href="./docdash-overrides.css">
358
339
 
340
+ <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
341
+
342
+ <script src="./mermaid-init.js"></script>
343
+
359
344
  </body>
360
345
  </html>