@tryghost/url-utils 5.0.0 → 5.1.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 (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 +14 -9
  7. package/lib/utils/absolute-to-transform-ready.d.ts +13 -4
  8. package/lib/utils/absolute-to-transform-ready.js +16 -11
  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 +43 -8
  21. package/lib/utils/html-relative-to-transform-ready.d.ts +3 -3
  22. package/lib/utils/html-relative-to-transform-ready.js +51 -11
  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 +5 -4
  26. package/lib/utils/html-transform.js +25 -21
  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 +22 -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 +12 -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 +26 -19
  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 +5 -5
  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 +10 -11
  92. package/index.js +0 -2
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const markdownTransform = require('./markdown-transform');
4
- const htmlRelativeToAbsolute = require('./html-relative-to-absolute');
5
- 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 markdown_transform_1 = __importDefault(require("./markdown-transform"));
7
+ const html_relative_to_absolute_1 = __importDefault(require("./html-relative-to-absolute"));
8
+ const relative_to_absolute_1 = __importDefault(require("./relative-to-absolute"));
6
9
  function markdownRelativeToAbsolute(markdown = '', siteUrl, itemPath, _options = {}) {
7
10
  const defaultOptions = { assetsOnly: false };
8
11
  const options = Object.assign({}, defaultOptions, _options);
@@ -11,9 +14,9 @@ function markdownRelativeToAbsolute(markdown = '', siteUrl, itemPath, _options =
11
14
  options.earlyExitMatchStr = options.staticImageUrlPrefix;
12
15
  }
13
16
  const transformFunctions = {
14
- html: htmlRelativeToAbsolute,
15
- url: relativeToAbsolute
17
+ html: html_relative_to_absolute_1.default,
18
+ url: relative_to_absolute_1.default
16
19
  };
17
- return markdownTransform(markdown, siteUrl, transformFunctions, itemPath, options);
20
+ return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, itemPath, options);
18
21
  }
19
- module.exports = markdownRelativeToAbsolute;
22
+ exports.default = markdownRelativeToAbsolute;
@@ -1,4 +1,3 @@
1
- declare const markdownTransform: any;
2
- declare const htmlRelativeToTransformReady: any;
3
- declare const relativeToTransformReady: any;
4
- declare function markdownRelativeToTransformReady(markdown: string | undefined, siteUrl: any, itemPath: any, _options?: {}): any;
1
+ import type { SecureOptionsInput } from './types';
2
+ declare function markdownRelativeToTransformReady(markdown: string | undefined, siteUrl: string, itemPath: string | null, _options?: SecureOptionsInput): string;
3
+ export default markdownRelativeToTransformReady;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- const markdownTransform = require('./markdown-transform');
4
- const htmlRelativeToTransformReady = require('./html-relative-to-transform-ready');
5
- 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 markdown_transform_1 = __importDefault(require("./markdown-transform"));
7
+ const html_relative_to_transform_ready_1 = __importDefault(require("./html-relative-to-transform-ready"));
8
+ const relative_to_transform_ready_1 = __importDefault(require("./relative-to-transform-ready"));
6
9
  function markdownRelativeToTransformReady(markdown = '', siteUrl, itemPath, _options = {}) {
7
10
  const defaultOptions = { assetsOnly: false };
8
11
  const options = Object.assign({}, defaultOptions, _options);
@@ -11,9 +14,9 @@ function markdownRelativeToTransformReady(markdown = '', siteUrl, itemPath, _opt
11
14
  options.earlyExitMatchStr = options.staticImageUrlPrefix;
12
15
  }
13
16
  const transformFunctions = {
14
- html: htmlRelativeToTransformReady,
15
- url: relativeToTransformReady
17
+ html: html_relative_to_transform_ready_1.default,
18
+ url: relative_to_transform_ready_1.default
16
19
  };
17
- return markdownTransform(markdown, siteUrl, transformFunctions, itemPath, options);
20
+ return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, itemPath, options);
18
21
  }
19
- module.exports = markdownRelativeToTransformReady;
22
+ exports.default = markdownRelativeToTransformReady;
@@ -1,3 +1,3 @@
1
- declare const markdownRelativeToAbsolute: any;
2
- declare const markdownAbsoluteToTransformReady: any;
3
- declare function markdownToTransformReady(markdown: any, siteUrl: any, itemPath: any, options: any): any;
1
+ import type { MarkdownTransformOptionsInput } from './types';
2
+ declare function markdownToTransformReady(markdown: string, siteUrl: string, itemPath: string | null | MarkdownTransformOptionsInput, options?: MarkdownTransformOptionsInput): string;
3
+ export default markdownToTransformReady;
@@ -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,8 +1,10 @@
1
1
  "use strict";
2
- // @ts-nocheck
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-require-imports */
3
4
  let remark;
4
5
  const footnotes = require('remark-footnotes');
5
6
  const visit = require('unist-util-visit');
7
+ /* eslint-enable @typescript-eslint/no-require-imports */
6
8
  function replaceLast(find, replace, str) {
7
9
  const lastIndex = str.lastIndexOf(find);
8
10
  if (lastIndex === -1) {
@@ -20,16 +22,20 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
20
22
  }
21
23
  const replacements = [];
22
24
  if (!remark) {
25
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
23
26
  remark = require('remark');
24
27
  }
28
+ if (!remark) {
29
+ return markdown;
30
+ }
25
31
  const tree = remark()
26
32
  .use({ settings: { commonmark: true } })
27
33
  .use(footnotes, { inlineNotes: true })
28
34
  .parse(markdown);
29
35
  visit(tree, ['link', 'image', 'html'], (node) => {
30
- if (node.type === 'html' && node.value.match(/src|srcset|href/)) {
36
+ if (node.type === 'html' && node.value && node.value.match(/src|srcset|href/) && node.position) {
31
37
  const oldValue = node.value;
32
- const newValue = transformFunctions.html(node.value, siteUrl, itemPath, options);
38
+ const newValue = transformFunctions.html(oldValue, siteUrl, itemPath, options);
33
39
  if (newValue !== oldValue) {
34
40
  replacements.push({
35
41
  old: oldValue,
@@ -39,9 +45,9 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
39
45
  });
40
46
  }
41
47
  }
42
- if (node.type === 'link' || node.type === 'image') {
48
+ if ((node.type === 'link' || node.type === 'image') && node.url && node.position) {
43
49
  const oldValue = node.url;
44
- const newValue = transformFunctions.url(node.url, siteUrl, itemPath, options);
50
+ const newValue = transformFunctions.url(oldValue, siteUrl, itemPath, options);
45
51
  if (newValue !== oldValue) {
46
52
  replacements.push({
47
53
  old: oldValue,
@@ -77,4 +83,4 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
77
83
  });
78
84
  return result;
79
85
  }
80
- module.exports = markdownTransform;
86
+ 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;