@tryghost/url-utils 5.0.0 → 5.1.0

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 (92) hide show
  1. package/lib/UrlUtils.d.ts +147 -3
  2. package/lib/UrlUtils.js +228 -112
  3. package/lib/index.d.ts +2 -0
  4. package/lib/index.js +6 -0
  5. package/lib/utils/absolute-to-relative.d.ts +9 -3
  6. package/lib/utils/absolute-to-relative.js +13 -8
  7. package/lib/utils/absolute-to-transform-ready.d.ts +13 -4
  8. package/lib/utils/absolute-to-transform-ready.js +15 -10
  9. package/lib/utils/build-early-exit-match.d.ts +11 -1
  10. package/lib/utils/build-early-exit-match.js +4 -4
  11. package/lib/utils/deduplicate-double-slashes.d.ts +2 -1
  12. package/lib/utils/deduplicate-double-slashes.js +2 -2
  13. package/lib/utils/deduplicate-subdirectory.d.ts +2 -2
  14. package/lib/utils/deduplicate-subdirectory.js +4 -4
  15. package/lib/utils/html-absolute-to-relative.d.ts +3 -3
  16. package/lib/utils/html-absolute-to-relative.js +10 -7
  17. package/lib/utils/html-absolute-to-transform-ready.d.ts +3 -4
  18. package/lib/utils/html-absolute-to-transform-ready.js +16 -9
  19. package/lib/utils/html-relative-to-absolute.d.ts +3 -3
  20. package/lib/utils/html-relative-to-absolute.js +9 -6
  21. package/lib/utils/html-relative-to-transform-ready.d.ts +3 -3
  22. package/lib/utils/html-relative-to-transform-ready.js +17 -9
  23. package/lib/utils/html-to-transform-ready.d.ts +3 -3
  24. package/lib/utils/html-to-transform-ready.js +17 -9
  25. package/lib/utils/html-transform.d.ts +3 -4
  26. package/lib/utils/html-transform.js +18 -19
  27. package/lib/utils/index.d.ts +76 -0
  28. package/lib/utils/index.js +115 -38
  29. package/lib/utils/is-ssl.d.ts +2 -2
  30. package/lib/utils/is-ssl.js +4 -4
  31. package/lib/utils/lexical-absolute-to-relative.d.ts +3 -2
  32. package/lib/utils/lexical-absolute-to-relative.js +9 -6
  33. package/lib/utils/lexical-absolute-to-transform-ready.d.ts +3 -2
  34. package/lib/utils/lexical-absolute-to-transform-ready.js +10 -7
  35. package/lib/utils/lexical-relative-to-absolute.d.ts +3 -3
  36. package/lib/utils/lexical-relative-to-absolute.js +8 -5
  37. package/lib/utils/lexical-relative-to-transform-ready.d.ts +3 -3
  38. package/lib/utils/lexical-relative-to-transform-ready.js +8 -5
  39. package/lib/utils/lexical-to-transform-ready.d.ts +3 -3
  40. package/lib/utils/lexical-to-transform-ready.js +17 -9
  41. package/lib/utils/lexical-transform.d.ts +3 -2
  42. package/lib/utils/lexical-transform.js +21 -19
  43. package/lib/utils/markdown-absolute-to-relative.d.ts +3 -4
  44. package/lib/utils/markdown-absolute-to-relative.js +11 -8
  45. package/lib/utils/markdown-absolute-to-transform-ready.d.ts +3 -5
  46. package/lib/utils/markdown-absolute-to-transform-ready.js +17 -10
  47. package/lib/utils/markdown-relative-to-absolute.d.ts +3 -4
  48. package/lib/utils/markdown-relative-to-absolute.js +11 -8
  49. package/lib/utils/markdown-relative-to-transform-ready.d.ts +3 -4
  50. package/lib/utils/markdown-relative-to-transform-ready.js +11 -8
  51. package/lib/utils/markdown-to-transform-ready.d.ts +3 -3
  52. package/lib/utils/markdown-to-transform-ready.js +17 -9
  53. package/lib/utils/markdown-transform.d.ts +3 -5
  54. package/lib/utils/markdown-transform.js +9 -6
  55. package/lib/utils/mobiledoc-absolute-to-relative.d.ts +3 -2
  56. package/lib/utils/mobiledoc-absolute-to-relative.js +9 -6
  57. package/lib/utils/mobiledoc-absolute-to-transform-ready.d.ts +3 -2
  58. package/lib/utils/mobiledoc-absolute-to-transform-ready.js +10 -7
  59. package/lib/utils/mobiledoc-relative-to-absolute.d.ts +3 -3
  60. package/lib/utils/mobiledoc-relative-to-absolute.js +8 -5
  61. package/lib/utils/mobiledoc-relative-to-transform-ready.d.ts +3 -3
  62. package/lib/utils/mobiledoc-relative-to-transform-ready.js +8 -5
  63. package/lib/utils/mobiledoc-to-transform-ready.d.ts +3 -3
  64. package/lib/utils/mobiledoc-to-transform-ready.js +17 -9
  65. package/lib/utils/mobiledoc-transform.d.ts +3 -1
  66. package/lib/utils/mobiledoc-transform.js +5 -4
  67. package/lib/utils/plaintext-absolute-to-transform-ready.d.ts +5 -4
  68. package/lib/utils/plaintext-absolute-to-transform-ready.js +16 -11
  69. package/lib/utils/plaintext-relative-to-transform-ready.d.ts +3 -2
  70. package/lib/utils/plaintext-relative-to-transform-ready.js +15 -7
  71. package/lib/utils/plaintext-to-transform-ready.d.ts +5 -3
  72. package/lib/utils/plaintext-to-transform-ready.js +17 -9
  73. package/lib/utils/relative-to-absolute.d.ts +5 -3
  74. package/lib/utils/relative-to-absolute.js +25 -18
  75. package/lib/utils/relative-to-transform-ready.d.ts +8 -2
  76. package/lib/utils/relative-to-transform-ready.js +22 -10
  77. package/lib/utils/replace-permalink.d.ts +13 -2
  78. package/lib/utils/replace-permalink.js +44 -8
  79. package/lib/utils/strip-subdirectory-from-path.d.ts +1 -1
  80. package/lib/utils/strip-subdirectory-from-path.js +4 -4
  81. package/lib/utils/to-transform-ready.d.ts +5 -3
  82. package/lib/utils/to-transform-ready.js +17 -9
  83. package/lib/utils/transform-ready-to-absolute.d.ts +9 -1
  84. package/lib/utils/transform-ready-to-absolute.js +2 -2
  85. package/lib/utils/transform-ready-to-relative.d.ts +3 -1
  86. package/lib/utils/transform-ready-to-relative.js +4 -3
  87. package/lib/utils/types.d.ts +92 -0
  88. package/lib/utils/types.js +2 -0
  89. package/lib/utils/url-join.d.ts +5 -2
  90. package/lib/utils/url-join.js +11 -5
  91. package/package.json +8 -9
  92. package/index.js +0 -2
@@ -1,13 +1,21 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const markdownRelativeToAbsolute = require('./markdown-relative-to-absolute');
4
- const markdownAbsoluteToTransformReady = require('./markdown-absolute-to-transform-ready');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const markdown_relative_to_absolute_1 = __importDefault(require("./markdown-relative-to-absolute"));
7
+ const markdown_absolute_to_transform_ready_1 = __importDefault(require("./markdown-absolute-to-transform-ready"));
5
8
  function markdownToTransformReady(markdown, siteUrl, itemPath, options) {
6
- if (typeof itemPath === 'object' && !options) {
7
- options = itemPath;
8
- itemPath = null;
9
+ let finalItemPath = null;
10
+ let finalOptions = options || {};
11
+ if (typeof itemPath === 'object' && itemPath !== null && !options) {
12
+ finalOptions = itemPath;
13
+ finalItemPath = null;
9
14
  }
10
- const absolute = markdownRelativeToAbsolute(markdown, siteUrl, itemPath, options);
11
- return markdownAbsoluteToTransformReady(absolute, siteUrl, options);
15
+ else if (typeof itemPath === 'string') {
16
+ finalItemPath = itemPath;
17
+ }
18
+ const absolute = (0, markdown_relative_to_absolute_1.default)(markdown, siteUrl, finalItemPath, finalOptions);
19
+ return (0, markdown_absolute_to_transform_ready_1.default)(absolute, siteUrl, finalOptions);
12
20
  }
13
- module.exports = markdownToTransformReady;
21
+ exports.default = markdownToTransformReady;
@@ -1,5 +1,3 @@
1
- declare let remark: any;
2
- declare const footnotes: any;
3
- declare const visit: any;
4
- declare function replaceLast(find: any, replace: any, str: any): any;
5
- declare function markdownTransform(markdown: string | undefined, siteUrl: any, transformFunctions: any, itemPath: any, _options?: {}): string;
1
+ import type { MarkdownTransformOptionsInput, MarkdownTransformFunctions } from './types';
2
+ declare function markdownTransform(markdown: string | undefined, siteUrl: string, transformFunctions: MarkdownTransformFunctions, itemPath: string | null, _options?: MarkdownTransformOptionsInput): string;
3
+ export default markdownTransform;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // @ts-nocheck
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  let remark;
4
4
  const footnotes = require('remark-footnotes');
5
5
  const visit = require('unist-util-visit');
@@ -22,14 +22,17 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
22
22
  if (!remark) {
23
23
  remark = require('remark');
24
24
  }
25
+ if (!remark) {
26
+ return markdown;
27
+ }
25
28
  const tree = remark()
26
29
  .use({ settings: { commonmark: true } })
27
30
  .use(footnotes, { inlineNotes: true })
28
31
  .parse(markdown);
29
32
  visit(tree, ['link', 'image', 'html'], (node) => {
30
- if (node.type === 'html' && node.value.match(/src|srcset|href/)) {
33
+ if (node.type === 'html' && node.value && node.value.match(/src|srcset|href/) && node.position) {
31
34
  const oldValue = node.value;
32
- const newValue = transformFunctions.html(node.value, siteUrl, itemPath, options);
35
+ const newValue = transformFunctions.html(oldValue, siteUrl, itemPath, options);
33
36
  if (newValue !== oldValue) {
34
37
  replacements.push({
35
38
  old: oldValue,
@@ -39,9 +42,9 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
39
42
  });
40
43
  }
41
44
  }
42
- if (node.type === 'link' || node.type === 'image') {
45
+ if ((node.type === 'link' || node.type === 'image') && node.url && node.position) {
43
46
  const oldValue = node.url;
44
- const newValue = transformFunctions.url(node.url, siteUrl, itemPath, options);
47
+ const newValue = transformFunctions.url(oldValue, siteUrl, itemPath, options);
45
48
  if (newValue !== oldValue) {
46
49
  replacements.push({
47
50
  old: oldValue,
@@ -77,4 +80,4 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
77
80
  });
78
81
  return result;
79
82
  }
80
- module.exports = markdownTransform;
83
+ exports.default = markdownTransform;
@@ -1,2 +1,3 @@
1
- declare const absoluteToRelative: any;
2
- declare const mobiledocTransform: any;
1
+ import type { MobiledocTransformOptionsInput } from './types';
2
+ declare function mobiledocAbsoluteToRelative(serializedMobiledoc: string, siteUrl: string, _options?: MobiledocTransformOptionsInput): string;
3
+ export default mobiledocAbsoluteToRelative;
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const absoluteToRelative = require('./absolute-to-relative');
4
- const mobiledocTransform = require('./mobiledoc-transform');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const absolute_to_relative_1 = __importDefault(require("./absolute-to-relative"));
7
+ const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
5
8
  function mobiledocAbsoluteToRelative(serializedMobiledoc, siteUrl, _options = {}) {
6
9
  const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
7
10
  const overrideOptions = { siteUrl, transformType: 'absoluteToRelative' };
8
11
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
9
12
  const transformFunction = function (_url, _siteUrl, _itemPath, __options) {
10
- return absoluteToRelative(_url, _siteUrl, __options);
13
+ return (0, absolute_to_relative_1.default)(_url, _siteUrl, __options);
11
14
  };
12
- return mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, '', options);
15
+ return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, transformFunction, '', options);
13
16
  }
14
- module.exports = mobiledocAbsoluteToRelative;
17
+ exports.default = mobiledocAbsoluteToRelative;
@@ -1,2 +1,3 @@
1
- declare const absoluteToTransformReady: any;
2
- declare const mobiledocTransform: any;
1
+ import type { MobiledocTransformOptionsInput } from './types';
2
+ declare function mobiledocAbsoluteToTransformReady(serializedMobiledoc: string, siteUrl: string, _options?: MobiledocTransformOptionsInput): string;
3
+ export default mobiledocAbsoluteToTransformReady;
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const absoluteToTransformReady = require('./absolute-to-transform-ready');
4
- const mobiledocTransform = require('./mobiledoc-transform');
5
- function mobiledocAbsoluteToRelative(serializedMobiledoc, siteUrl, _options = {}) {
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const absolute_to_transform_ready_1 = __importDefault(require("./absolute-to-transform-ready"));
7
+ const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
8
+ function mobiledocAbsoluteToTransformReady(serializedMobiledoc, siteUrl, _options = {}) {
6
9
  const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
7
10
  const overrideOptions = { siteUrl, transformType: 'toTransformReady' };
8
11
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
9
12
  const transformFunction = function (_url, _siteUrl, _itemPath, __options) {
10
- return absoluteToTransformReady(_url, _siteUrl, __options);
13
+ return (0, absolute_to_transform_ready_1.default)(_url, _siteUrl, __options);
11
14
  };
12
- return mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, '', options);
15
+ return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, transformFunction, '', options);
13
16
  }
14
- module.exports = mobiledocAbsoluteToRelative;
17
+ exports.default = mobiledocAbsoluteToTransformReady;
@@ -1,3 +1,3 @@
1
- declare const relativeToAbsolute: any;
2
- declare const mobiledocTransform: any;
3
- declare function mobiledocRelativeToAbsolute(serializedMobiledoc: any, siteUrl: any, itemPath: any, _options?: {}): any;
1
+ import type { MobiledocTransformOptionsInput } from './types';
2
+ declare function mobiledocRelativeToAbsolute(serializedMobiledoc: string, siteUrl: string, itemPath: string | null, _options?: MobiledocTransformOptionsInput): string;
3
+ export default mobiledocRelativeToAbsolute;
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const relativeToAbsolute = require('./relative-to-absolute');
4
- const mobiledocTransform = require('./mobiledoc-transform');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const relative_to_absolute_1 = __importDefault(require("./relative-to-absolute"));
7
+ const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
5
8
  function mobiledocRelativeToAbsolute(serializedMobiledoc, siteUrl, itemPath, _options = {}) {
6
9
  const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
7
10
  const overrideOptions = { siteUrl, itemPath, transformType: 'relativeToAbsolute' };
8
11
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
9
- return mobiledocTransform(serializedMobiledoc, siteUrl, relativeToAbsolute, itemPath, options);
12
+ return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, relative_to_absolute_1.default, itemPath, options);
10
13
  }
11
- module.exports = mobiledocRelativeToAbsolute;
14
+ exports.default = mobiledocRelativeToAbsolute;
@@ -1,3 +1,3 @@
1
- declare const relativeToTransformReady: any;
2
- declare const mobiledocTransform: any;
3
- declare function mobiledocRelativeToTransformReady(serializedMobiledoc: any, siteUrl: any, itemPath: any, _options?: {}): any;
1
+ import type { MobiledocTransformOptionsInput } from './types';
2
+ declare function mobiledocRelativeToTransformReady(serializedMobiledoc: string, siteUrl: string, itemPath: string | null, _options?: MobiledocTransformOptionsInput): string;
3
+ export default mobiledocRelativeToTransformReady;
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const relativeToTransformReady = require('./relative-to-transform-ready');
4
- const mobiledocTransform = require('./mobiledoc-transform');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const relative_to_transform_ready_1 = __importDefault(require("./relative-to-transform-ready"));
7
+ const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
5
8
  function mobiledocRelativeToTransformReady(serializedMobiledoc, siteUrl, itemPath, _options = {}) {
6
9
  const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
7
10
  const overrideOptions = { siteUrl, transformType: 'toTransformReady' };
8
11
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
9
- return mobiledocTransform(serializedMobiledoc, siteUrl, relativeToTransformReady, itemPath, options);
12
+ return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, relative_to_transform_ready_1.default, itemPath, options);
10
13
  }
11
- module.exports = mobiledocRelativeToTransformReady;
14
+ exports.default = mobiledocRelativeToTransformReady;
@@ -1,3 +1,3 @@
1
- declare const mobiledocRelativeToAbsolute: any;
2
- declare const mobiledocAbsoluteToTransformReady: any;
3
- declare function mobiledocToTransformReady(mobiledoc: any, siteUrl: any, itemPath: any, options: any): any;
1
+ import type { MobiledocTransformOptionsInput } from './types';
2
+ declare function mobiledocToTransformReady(mobiledoc: string, siteUrl: string, itemPath: string | null | MobiledocTransformOptionsInput, options?: MobiledocTransformOptionsInput): string;
3
+ export default mobiledocToTransformReady;
@@ -1,13 +1,21 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const mobiledocRelativeToAbsolute = require('./mobiledoc-relative-to-absolute');
4
- const mobiledocAbsoluteToTransformReady = require('./mobiledoc-absolute-to-transform-ready');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const mobiledoc_relative_to_absolute_1 = __importDefault(require("./mobiledoc-relative-to-absolute"));
7
+ const mobiledoc_absolute_to_transform_ready_1 = __importDefault(require("./mobiledoc-absolute-to-transform-ready"));
5
8
  function mobiledocToTransformReady(mobiledoc, siteUrl, itemPath, options) {
6
- if (typeof itemPath === 'object' && !options) {
7
- options = itemPath;
8
- itemPath = null;
9
+ let finalItemPath = null;
10
+ let finalOptions = options || {};
11
+ if (typeof itemPath === 'object' && itemPath !== null && !options) {
12
+ finalOptions = itemPath;
13
+ finalItemPath = null;
9
14
  }
10
- const absolute = mobiledocRelativeToAbsolute(mobiledoc, siteUrl, itemPath, options);
11
- return mobiledocAbsoluteToTransformReady(absolute, siteUrl, options);
15
+ else if (typeof itemPath === 'string') {
16
+ finalItemPath = itemPath;
17
+ }
18
+ const absolute = (0, mobiledoc_relative_to_absolute_1.default)(mobiledoc, siteUrl, finalItemPath, finalOptions);
19
+ return (0, mobiledoc_absolute_to_transform_ready_1.default)(absolute, siteUrl, finalOptions);
12
20
  }
13
- module.exports = mobiledocToTransformReady;
21
+ exports.default = mobiledocToTransformReady;
@@ -1 +1,3 @@
1
- declare function mobiledocTransform(serializedMobiledoc: any, siteUrl: any, transformFunction: any, itemPath: any, _options?: {}): string;
1
+ import type { MobiledocTransformOptionsInput, UrlTransformFunction } from './types';
2
+ declare function mobiledocTransform(serializedMobiledoc: string, siteUrl: string, transformFunction: UrlTransformFunction, itemPath: string | null, _options?: MobiledocTransformOptionsInput): string;
3
+ export default mobiledocTransform;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // @ts-nocheck
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, itemPath, _options = {}) {
4
4
  const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
5
5
  const options = Object.assign({}, defaultOptions, _options, { siteUrl, itemPath });
@@ -25,7 +25,7 @@ function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, ite
25
25
  hrefIndex = index + 1;
26
26
  }
27
27
  });
28
- if (hrefIndex !== -1) {
28
+ if (hrefIndex !== -1 && typeof markup[1][hrefIndex] === 'string') {
29
29
  const transformedUrl = transformFunction(markup[1][hrefIndex], siteUrl, itemPath, options);
30
30
  if (transformedUrl) {
31
31
  markup[1][hrefIndex] = transformedUrl;
@@ -37,7 +37,8 @@ function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, ite
37
37
  // cards may contain so we sub out to card-specific transform functions that
38
38
  // are passed in as options from the consuming application.
39
39
  (mobiledoc.cards || []).forEach((card) => {
40
- const [name, payload] = card;
40
+ const name = card[0];
41
+ const payload = card[1];
41
42
  if (cardTransformers[name]) {
42
43
  // transformers take a payload and return a transformed payload
43
44
  const transformedPayload = cardTransformers[name](payload, options);
@@ -46,4 +47,4 @@ function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, ite
46
47
  });
47
48
  return JSON.stringify(mobiledoc);
48
49
  }
49
- module.exports = mobiledocTransform;
50
+ exports.default = mobiledocTransform;
@@ -1,4 +1,5 @@
1
- declare const absoluteToTransformReady: any;
2
- declare const escapeRegExp: any;
3
- declare function buildLinkRegex(rootUrl: any, options?: {}): RegExp | null;
4
- declare const plaintextAbsoluteToTransformReady: (plaintext: any, rootUrl: any, itemPath: any, options: any) => any;
1
+ import type { AbsoluteToTransformReadyOptionsInput, BaseUrlOptionsInput } from './types';
2
+ type PlaintextAbsoluteToTransformReadyOptions = AbsoluteToTransformReadyOptionsInput & BaseUrlOptionsInput;
3
+ type PlaintextAbsoluteToTransformReadyOptionsInput = Partial<PlaintextAbsoluteToTransformReadyOptions>;
4
+ declare const plaintextAbsoluteToTransformReady: (plaintext: string, rootUrl: string, itemPath: string | null | PlaintextAbsoluteToTransformReadyOptionsInput, options?: PlaintextAbsoluteToTransformReadyOptionsInput) => string;
5
+ export default plaintextAbsoluteToTransformReady;
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const absoluteToTransformReady = require('./absolute-to-transform-ready');
4
- const { escapeRegExp } = require('./build-early-exit-match');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const absolute_to_transform_ready_1 = __importDefault(require("./absolute-to-transform-ready"));
7
+ const build_early_exit_match_1 = __importDefault(require("./build-early-exit-match"));
8
+ const { escapeRegExp } = build_early_exit_match_1.default;
9
+ const url_1 = require("url");
5
10
  function buildLinkRegex(rootUrl, options = {}) {
6
11
  // Build a regex that matches links from ANY configured base URL (site + CDNs)
7
12
  const baseUrls = [rootUrl, options.imageBaseUrl, options.filesBaseUrl, options.mediaBaseUrl]
8
- .filter(Boolean);
13
+ .filter((value) => Boolean(value));
9
14
  const patterns = baseUrls.map((baseUrl) => {
10
- const parsed = new URL(baseUrl);
15
+ const parsed = new url_1.URL(baseUrl);
11
16
  const escapedUrl = escapeRegExp(`${parsed.hostname}${parsed.pathname.replace(/\/$/, '')}`);
12
17
  return escapedUrl;
13
18
  });
@@ -19,16 +24,16 @@ function buildLinkRegex(rootUrl, options = {}) {
19
24
  }
20
25
  const plaintextAbsoluteToTransformReady = function plaintextAbsoluteToTransformReady(plaintext, rootUrl, itemPath, options) {
21
26
  // itemPath is optional, if it's an object may be the options param instead
22
- if (typeof itemPath === 'object' && !options) {
23
- options = itemPath;
24
- itemPath = null;
27
+ let finalOptions = options || {};
28
+ if (typeof itemPath === 'object' && itemPath !== null && !options) {
29
+ finalOptions = itemPath;
25
30
  }
26
31
  // plaintext links look like "Link title [url]"
27
32
  // those links are all we care about so we can do a fast regex here
28
- const linkRegex = buildLinkRegex(rootUrl, options);
33
+ const linkRegex = buildLinkRegex(rootUrl, finalOptions);
29
34
  return plaintext.replace(linkRegex, function (fullMatch, url) {
30
- const newUrl = absoluteToTransformReady(`${url}`, rootUrl, options);
35
+ const newUrl = (0, absolute_to_transform_ready_1.default)(`${url}`, rootUrl, finalOptions);
31
36
  return ` [${newUrl}]`;
32
37
  });
33
38
  };
34
- module.exports = plaintextAbsoluteToTransformReady;
39
+ exports.default = plaintextAbsoluteToTransformReady;
@@ -1,2 +1,3 @@
1
- declare const relativeToTransformReady: any;
2
- declare const plaintextRelativeToTransformReady: (plaintext: any, rootUrl: any, itemPath: any, options: any) => any;
1
+ import type { RelativeToTransformReadyOptionsInput } from './relative-to-transform-ready';
2
+ declare const plaintextRelativeToTransformReady: (plaintext: string, rootUrl: string, itemPath: string | null | RelativeToTransformReadyOptionsInput, options?: RelativeToTransformReadyOptionsInput) => string;
3
+ export default plaintextRelativeToTransformReady;
@@ -1,17 +1,25 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const relativeToTransformReady = require('./relative-to-transform-ready');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const relative_to_transform_ready_1 = __importDefault(require("./relative-to-transform-ready"));
4
7
  const plaintextRelativeToTransformReady = function plaintextRelativeToTransformReady(plaintext, rootUrl, itemPath, options) {
5
8
  // itemPath is optional, if it's an object may be the options param instead
6
- if (typeof itemPath === 'object' && !options) {
7
- options = itemPath;
8
- itemPath = null;
9
+ let finalItemPath = null;
10
+ let finalOptions = options || {};
11
+ if (typeof itemPath === 'object' && itemPath !== null && !options) {
12
+ finalOptions = itemPath;
13
+ finalItemPath = null;
14
+ }
15
+ else if (typeof itemPath === 'string') {
16
+ finalItemPath = itemPath;
9
17
  }
10
18
  // plaintext links look like "Link title [url]"
11
19
  // those are all we care about so we can do a fast regex here
12
20
  return plaintext.replace(/ \[(\/.*?)\]/g, function (fullMatch, path) {
13
- const newPath = relativeToTransformReady(`${path}`, rootUrl, itemPath, options);
21
+ const newPath = (0, relative_to_transform_ready_1.default)(`${path}`, rootUrl, finalItemPath, finalOptions);
14
22
  return ` [${newPath}]`;
15
23
  });
16
24
  };
17
- module.exports = plaintextRelativeToTransformReady;
25
+ exports.default = plaintextRelativeToTransformReady;
@@ -1,3 +1,5 @@
1
- declare const plaintextRelativeToTransformReady: any;
2
- declare const plaintextAbsoluteToTransformReady: any;
3
- declare function plaintextToTransformReady(plaintext: any, siteUrl: any, itemPath: any, options: any): any;
1
+ import type { UnknownRecord } from './types';
2
+ type PlaintextTransformOptions = UnknownRecord;
3
+ type PlaintextTransformOptionsInput = Partial<PlaintextTransformOptions>;
4
+ declare function plaintextToTransformReady(plaintext: string, siteUrl: string, itemPath: string | null | PlaintextTransformOptionsInput, options?: PlaintextTransformOptionsInput): string;
5
+ export default plaintextToTransformReady;
@@ -1,13 +1,21 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const plaintextRelativeToTransformReady = require('./plaintext-relative-to-transform-ready');
4
- const plaintextAbsoluteToTransformReady = require('./plaintext-absolute-to-transform-ready');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const plaintext_relative_to_transform_ready_1 = __importDefault(require("./plaintext-relative-to-transform-ready"));
7
+ const plaintext_absolute_to_transform_ready_1 = __importDefault(require("./plaintext-absolute-to-transform-ready"));
5
8
  function plaintextToTransformReady(plaintext, siteUrl, itemPath, options) {
6
- if (typeof itemPath === 'object' && !options) {
7
- options = itemPath;
8
- itemPath = null;
9
+ let finalItemPath = null;
10
+ let finalOptions = options || {};
11
+ if (typeof itemPath === 'object' && itemPath !== null && !options) {
12
+ finalOptions = itemPath;
13
+ finalItemPath = null;
9
14
  }
10
- const relativeTransformed = plaintextRelativeToTransformReady(plaintext, siteUrl, itemPath, options);
11
- return plaintextAbsoluteToTransformReady(relativeTransformed, siteUrl, options);
15
+ else if (typeof itemPath === 'string') {
16
+ finalItemPath = itemPath;
17
+ }
18
+ const relativeTransformed = (0, plaintext_relative_to_transform_ready_1.default)(plaintext, siteUrl, finalItemPath, finalOptions);
19
+ return (0, plaintext_absolute_to_transform_ready_1.default)(relativeTransformed, siteUrl, finalOptions);
12
20
  }
13
- module.exports = plaintextToTransformReady;
21
+ exports.default = plaintextToTransformReady;
@@ -1,5 +1,6 @@
1
- declare const URL: any;
2
- declare const urlJoin: any;
1
+ import type { SecureOptions, SecureOptionsInput } from './types';
2
+ export type RelativeToAbsoluteOptions = SecureOptions;
3
+ export type RelativeToAbsoluteOptionsInput = SecureOptionsInput;
3
4
  /**
4
5
  * Convert a root-relative path to an absolute URL based on the supplied root.
5
6
  * Will _only_ convert root-relative urls (/some/path not some/path)
@@ -10,4 +11,5 @@ declare const urlJoin: any;
10
11
  * @param {object} options
11
12
  * @returns {string} The passed in url or an absolute URL using
12
13
  */
13
- declare const relativeToAbsolute: (path: any, rootUrl: any, itemPath: any, _options: any) => any;
14
+ declare const relativeToAbsolute: (path: string, rootUrl: string, itemPath: string | null | RelativeToAbsoluteOptionsInput, _options?: RelativeToAbsoluteOptionsInput) => string;
15
+ export default relativeToAbsolute;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- // require the whatwg compatible URL library (same behaviour in node and browser)
4
- const { URL } = require('url');
5
- const urlJoin = require('./url-join');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const url_1 = require("url");
7
+ const url_join_1 = __importDefault(require("./url-join"));
6
8
  // NOTE: Ghost's relative->absolute handling is a little strange when the rootUrl
7
9
  // includes a subdirectory. Root-relative paths such as /content/image.jpg are
8
10
  // actually treated as subdirectory-relative. This means that it's possible to
@@ -23,20 +25,25 @@ const urlJoin = require('./url-join');
23
25
  */
24
26
  const relativeToAbsolute = function relativeToAbsolute(path, rootUrl, itemPath, _options) {
25
27
  // itemPath is optional, if it's an object it may be the options param instead
26
- if (typeof itemPath === 'object' && !_options) {
27
- _options = itemPath;
28
- itemPath = null;
28
+ let finalItemPath = null;
29
+ let finalOptions = _options || {};
30
+ if (typeof itemPath === 'object' && itemPath !== null && !_options) {
31
+ finalOptions = itemPath;
32
+ finalItemPath = null;
33
+ }
34
+ else if (typeof itemPath === 'string') {
35
+ finalItemPath = itemPath;
29
36
  }
30
37
  // itemPath could be sent as a full url in which case, extract the pathname
31
- if (itemPath && itemPath.match(/^http/)) {
32
- const itemUrl = new URL(itemPath);
33
- itemPath = itemUrl.pathname;
38
+ if (finalItemPath && finalItemPath.match(/^http/)) {
39
+ const itemUrl = new url_1.URL(finalItemPath);
40
+ finalItemPath = itemUrl.pathname;
34
41
  }
35
42
  const defaultOptions = {
36
43
  assetsOnly: false,
37
44
  staticImageUrlPrefix: 'content/images'
38
45
  };
39
- const options = Object.assign({}, defaultOptions, _options);
46
+ const options = Object.assign({}, defaultOptions, finalOptions);
40
47
  // return the path as-is if it's not an asset path and we're only modifying assets
41
48
  if (options.assetsOnly) {
42
49
  const staticImageUrlPrefixRegex = new RegExp(options.staticImageUrlPrefix);
@@ -46,7 +53,7 @@ const relativeToAbsolute = function relativeToAbsolute(path, rootUrl, itemPath,
46
53
  }
47
54
  // if URL is absolute return it as-is
48
55
  try {
49
- const parsed = new URL(path, 'http://relative');
56
+ const parsed = new url_1.URL(path, 'http://relative');
50
57
  if (parsed.origin !== 'http://relative') {
51
58
  return path;
52
59
  }
@@ -63,20 +70,20 @@ const relativeToAbsolute = function relativeToAbsolute(path, rootUrl, itemPath,
63
70
  return path;
64
71
  }
65
72
  // return the path as-is if it's not root-relative and we have no itemPath
66
- if (!itemPath && !path.match(/^\//)) {
73
+ if (!finalItemPath && !path.match(/^\//)) {
67
74
  return path;
68
75
  }
69
76
  // force root to always have a trailing-slash for consistent behaviour
70
77
  if (!rootUrl.endsWith('/')) {
71
78
  rootUrl = `${rootUrl}/`;
72
79
  }
73
- const parsedRootUrl = new URL(rootUrl);
74
- const basePath = path.startsWith('/') ? '' : itemPath;
75
- const fullPath = urlJoin([parsedRootUrl.pathname, basePath, path], { rootUrl });
76
- const absoluteUrl = new URL(fullPath, rootUrl);
80
+ const parsedRootUrl = new url_1.URL(rootUrl);
81
+ const basePath = path.startsWith('/') ? '' : (finalItemPath || '');
82
+ const fullPath = (0, url_join_1.default)([parsedRootUrl.pathname, basePath, path], { rootUrl });
83
+ const absoluteUrl = new url_1.URL(fullPath, rootUrl);
77
84
  if (options.secure) {
78
85
  absoluteUrl.protocol = 'https:';
79
86
  }
80
87
  return absoluteUrl.toString();
81
88
  };
82
- module.exports = relativeToAbsolute;
89
+ exports.default = relativeToAbsolute;
@@ -1,2 +1,8 @@
1
- declare const relativeToAbsolute: any;
2
- declare const relativeToTransformReady: (url: any, root: any, itemPath: any, _options: any) => any;
1
+ import type { TransformReadyReplacementOptions } from './types';
2
+ export interface RelativeToTransformReadyOptions extends TransformReadyReplacementOptions {
3
+ staticImageUrlPrefix: string;
4
+ secure: boolean;
5
+ }
6
+ export type RelativeToTransformReadyOptionsInput = Partial<RelativeToTransformReadyOptions>;
7
+ declare const relativeToTransformReady: (url: string, root: string, itemPath: string | null | RelativeToTransformReadyOptionsInput, _options?: RelativeToTransformReadyOptionsInput) => string;
8
+ export default relativeToTransformReady;
@@ -1,11 +1,20 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const relativeToAbsolute = require('./relative-to-absolute');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const relative_to_absolute_1 = __importDefault(require("./relative-to-absolute"));
7
+ const url_1 = require("url");
4
8
  const relativeToTransformReady = function (url, root, itemPath, _options) {
5
9
  // itemPath is optional, if it's an object may be the options param instead
6
- if (typeof itemPath === 'object' && !_options) {
7
- _options = itemPath;
8
- itemPath = null;
10
+ let finalItemPath = null;
11
+ let finalOptions = _options || {};
12
+ if (typeof itemPath === 'object' && itemPath !== null && !_options) {
13
+ finalOptions = itemPath;
14
+ finalItemPath = null;
15
+ }
16
+ else if (typeof itemPath === 'string') {
17
+ finalItemPath = itemPath;
9
18
  }
10
19
  const defaultOptions = {
11
20
  replacementStr: '__GHOST_URL__',
@@ -14,22 +23,25 @@ const relativeToTransformReady = function (url, root, itemPath, _options) {
14
23
  const overrideOptions = {
15
24
  secure: false
16
25
  };
17
- const options = Object.assign({}, defaultOptions, _options, overrideOptions);
26
+ const options = Object.assign({}, defaultOptions, finalOptions, overrideOptions);
18
27
  // convert to absolute
19
- const absoluteUrl = relativeToAbsolute(url, root, itemPath, options);
28
+ const absoluteUrl = (0, relative_to_absolute_1.default)(url, root, finalItemPath, options);
20
29
  if (absoluteUrl === url) {
21
30
  return url;
22
31
  }
23
- const rootUrl = new URL(root);
32
+ const rootUrl = new url_1.URL(root);
24
33
  const rootPathname = rootUrl.pathname.replace(/\/$/, '');
25
34
  // only convert to transform-ready if root url has no subdirectory or the subdirectory matches
26
35
  if (!url.match(/^\//) || rootPathname === '' || url.indexOf(rootPathname) === 0 || url.indexOf(`/${options.staticImageUrlPrefix}`) === 0) {
36
+ // normalize root to match the protocol of absoluteUrl (in case secure option changed it)
37
+ const absoluteUrlParsed = new url_1.URL(absoluteUrl);
38
+ const normalizedRoot = `${absoluteUrlParsed.protocol}//${rootUrl.host}${rootUrl.pathname}`.replace(/\/$/, '');
27
39
  // replace root with replacement string
28
40
  const transformedUrl = absoluteUrl
29
- .replace(root, `${options.replacementStr}/`) // always have trailing slash after magic string
41
+ .replace(normalizedRoot, `${options.replacementStr}/`) // always have trailing slash after magic string
30
42
  .replace(/([^:])\/\//g, '$1/');
31
43
  return transformedUrl;
32
44
  }
33
45
  return url;
34
46
  };
35
- module.exports = relativeToTransformReady;
47
+ exports.default = relativeToTransformReady;