@bartificer/linkify 2.3.4 → 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',
@@ -24,28 +24,50 @@ linkify.registerTemplate('md-apr', new LinkTemplate(
24
24
  ));
25
25
  linkify.registerDefaultTemplateMapping('apple.com', 'md-apr');
26
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
+
27
50
  // define & register custom transformers for domains that need them
28
- linkify.registerTransformer('9to5mac.com', function(pData){
29
- return new LinkData(pData.url, pData.mainHeading);
30
- });
31
- linkify.registerTransformer('cultofmac.com', function(pData){
32
- return new LinkData(pData.url, pData.mainHeading);
33
- });
34
- linkify.registerTransformer('daringfireball.net', function(pData){
35
- return new LinkData(pData.url, pData.title.replace(/^Daring Fireball:[ ]/, ''));
36
- });
37
- linkify.registerTransformer('intego.com', function(pData){
38
- return new LinkData(pData.url, pData.title.replace(' - The Mac Security Blog', ''));
39
- });
40
- linkify.registerTransformer('krebsonsecurity.com', function(pData){
41
- return new LinkData(pData.url, pData.title.replace(' – Krebs on Security', ''));
42
- });
43
- linkify.registerTransformer('macstories.net', function(pData){
44
- return new LinkData(pData.url, pData.title.replace(' - MacStories', ''));
45
- });
46
- linkify.registerTransformer('nakedsecurity.sophos.com', function(pData){
47
- return new LinkData(pData.url, pData.title.replace(' – Naked Security', ''));
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
+ }
48
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'));
49
71
  linkify.registerTransformer('overcast.fm', function(pData){
50
72
  // strip Overcast append, split on em-dash to replace with n-dash and get podcast name
51
73
  let textParts = pData.title.replace(' — Overcast', '').split('—');
@@ -55,14 +77,14 @@ linkify.registerTransformer('overcast.fm', function(pData){
55
77
  let linkText = podcastName.trim() + ': ' + textParts.join(' – ').replace(/[ ]+/g, ' ').replace(':', '-').trim();
56
78
  return new LinkData(pData.url, linkText);
57
79
  });
58
- linkify.registerTransformer('sixcolors.com', function(pData){
59
- return new LinkData(pData.url, pData.mainHeading);
60
- });
61
- linkify.registerTransformer('theverge.com', function(pData){
62
- return new linkify.LinkData(pData.url, pData.title.replace(/[ ][-][ ]The[ ]Verge.*$/, ''));
63
- });
64
- linkify.registerTransformer('wired.com', function(pData){
65
- return new linkify.LinkData(pData.url, pData.mainHeading);
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);
66
88
  });
67
89
 
68
90
  // read the URL from the clipboard
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bartificer/linkify",
3
- "version": "2.3.4",
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',