@bartificer/linkify 2.3.3 → 2.3.5

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.
@@ -79,15 +79,20 @@ export const speciallyCapitalisedWords = [
79
79
  'iOS',
80
80
  'macOS',
81
81
  'iPhone',
82
+ 'iPhones',
82
83
  'iPad',
84
+ 'iPads',
83
85
  'iPod',
86
+ 'iPods',
84
87
  'AirTag',
88
+ 'AirTags',
85
89
  'iPadOS',
86
90
  'watchOS',
87
91
  'tvOS',
88
92
  'CarPlay',
89
93
  'AirPods',
90
94
  'MacBook',
95
+ 'MacBooks',
91
96
  'iTunes',
92
97
  'WWDC',
93
98
  'XDR',
@@ -0,0 +1,96 @@
1
+ // import Linkify Lib
2
+ import { linkify, LinkTemplate, LinkData } from '../dist/index.js';
3
+
4
+ // import 3rd-party library for interacting with the clipboard
5
+ import clipboardy from 'clipboardy';
6
+
7
+ // register a custom Markdown link template and make it the default
8
+ linkify.registerTemplate('md-bartificer', new LinkTemplate(
9
+ '[{{{text}}} — {{{uri.hostname}}}{{#uri.hasPath}}/…{{/uri.hasPath}}]({{{url}}})',
10
+ [
11
+ ['url', linkify.util.stripUTMParameters],
12
+ ['text', linkify.util.regulariseWhitespace]
13
+ ]
14
+ ));
15
+ linkify.defaultTemplateName = 'md-bartificer';
16
+
17
+ // register a special Markdown template for Apple presss releases and make it the default for Apple's domain
18
+ linkify.registerTemplate('md-apr', new LinkTemplate(
19
+ '[{{{text}}} — 📣 Apple PR]({{{url}}})',
20
+ [
21
+ ['url', linkify.util.stripUTMParameters],
22
+ ['text', linkify.util.regulariseWhitespace]
23
+ ]
24
+ ));
25
+ linkify.registerDefaultTemplateMapping('apple.com', 'md-apr');
26
+
27
+ // register a special Markdown template for XKCD cartoons presss releases and make it the default for XKCD's domain
28
+ // TO DO — figure out the right way to add support for extra fields like the sequence number, image permalink & alt text
29
+ linkify.registerTemplate('md-xkcd', new LinkTemplate(
30
+ // the description should the the comic's sequence number, at least for now
31
+ '[XKCD {{{description}}}: {{{text}}}]({{{url}}})\n![ADD DESCRIPTION](IMAGE_PERMALINK.png "ALT TEXT")'
32
+ ));
33
+ linkify.registerDefaultTemplateMapping('xkcd.com', 'md-xkcd');
34
+
35
+ // Cache commonly needed transforer functions to reduce code repetition
36
+ const transformers = {
37
+ mainHeading: function(pData){
38
+ return new LinkData(pData.url, pData.mainHeading);
39
+ },
40
+ titleMinusPrefix: function(pData, prefix){
41
+ const regex = new RegExp(`^${linkify.util.escapeRegex(prefix)}`);
42
+ return new LinkData(pData.url, pData.title.replace(regex, '').trim());
43
+ },
44
+ titleMinusPostscript: function(pData, postscript){
45
+ const regex = new RegExp(`${linkify.util.escapeRegex(postscript)}$`);
46
+ return new LinkData(pData.url, pData.title.replace(regex, '').trim());
47
+ }
48
+ };
49
+
50
+ // define & register custom transformers for domains that need them
51
+ linkify.registerTransformer('9to5mac.com', transformers.mainHeading);
52
+ linkify.registerTransformer('apod.nasa.gov', (pData) => {
53
+ // parse the title to extract the date and picture title
54
+ let titlePartsMatch = pData.title.match(/^APOD:[ ](?<year>\d{4})[ ](?<month>[a-zA-Z]+)[ ](?<day>\d{1,2})[ ]–[ ](?<title>.+)$/);
55
+ if(titlePartsMatch && titlePartsMatch.groups){
56
+ return new LinkData(
57
+ pData.url,
58
+ `NASA Astronomy Picture of the Day for ${titlePartsMatch.groups.day} ${titlePartsMatch.groups.month} ${titlePartsMatch.groups.year}: ${titlePartsMatch.groups.title}`,
59
+ )
60
+ } else {
61
+ // fall back on just using the title
62
+ return new LinkData(pData.url, pData.title);
63
+ }
64
+ });
65
+ linkify.registerTransformer('cultofmac.com', transformers.mainHeading);
66
+ linkify.registerTransformer('daringfireball.net', (pData) => transformers.titleMinusPrefix(pData, 'Daring Fireball: '));
67
+ linkify.registerTransformer('intego.com', (pData) => transformers.titleMinusPostscript(pData, ' | Intego'));
68
+ linkify.registerTransformer('krebsonsecurity.com', (pData) => transformers.titleMinusPostscript(pData, ' – Krebs on Security'));
69
+ linkify.registerTransformer('macstories.net', (pData) => transformers.titleMinusPostscript(pData, ' - MacStories'));
70
+ linkify.registerTransformer('nakedsecurity.sophos.com', (pData) => transformers.titleMinusPostscript(pData, ' – Naked Security'));
71
+ linkify.registerTransformer('overcast.fm', function(pData){
72
+ // strip Overcast append, split on em-dash to replace with n-dash and get podcast name
73
+ let textParts = pData.title.replace(' — Overcast', '').split('—');
74
+ let podcastName = textParts.pop();
75
+
76
+ // re-assemble the text
77
+ let linkText = podcastName.trim() + ': ' + textParts.join(' – ').replace(/[ ]+/g, ' ').replace(':', '-').trim();
78
+ return new LinkData(pData.url, linkText);
79
+ });
80
+ linkify.registerTransformer('sixcolors.com', transformers.mainHeading);
81
+ linkify.registerTransformer('theverge.com', transformers.mainHeading);
82
+ linkify.registerTransformer('wired.com', transformers.mainHeading);
83
+ linkify.registerTransformer('xkcd.com', (pData) => {
84
+ // extract the sequence number from the URL and add it to the description field
85
+ const comicNumber = pData.uri.path().replaceAll('/', '');
86
+ const comicTitle = pData.title.replace(/^xkcd[:][ ]/, '');
87
+ return new LinkData(pData.url, comicTitle, comicNumber);
88
+ });
89
+
90
+ // read the URL from the clipboard
91
+ let testURL = clipboardy.readSync();
92
+
93
+ // try generate the formatted link from the URL
94
+ linkify.generateLink(testURL).then(function(d){
95
+ console.log(d);
96
+ });
@@ -0,0 +1,7 @@
1
+ import clipboardy from 'clipboardy';
2
+ import linkify from '../dist/index.js';
3
+
4
+ let testURL = clipboardy.readSync();
5
+ linkify.fetchPageData(testURL).then(function(d){
6
+ console.log(d);
7
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bartificer/linkify",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "An module for converting URLs into pretty links in any format.",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/defaults.mjs CHANGED
@@ -77,15 +77,20 @@ export const speciallyCapitalisedWords = [
77
77
  'iOS',
78
78
  'macOS',
79
79
  'iPhone',
80
+ 'iPhones',
80
81
  'iPad',
82
+ 'iPads',
81
83
  'iPod',
84
+ 'iPods',
82
85
  'AirTag',
86
+ 'AirTags',
83
87
  'iPadOS',
84
88
  'watchOS',
85
89
  'tvOS',
86
90
  'CarPlay',
87
91
  'AirPods',
88
92
  'MacBook',
93
+ 'MacBooks',
89
94
  'iTunes',
90
95
  'WWDC',
91
96
  'XDR',