@tryghost/url-utils 5.0.0-rc.1 → 5.0.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 (88) hide show
  1. package/index.js +1 -0
  2. package/lib/UrlUtils.d.ts +3 -0
  3. package/lib/UrlUtils.js +45 -111
  4. package/lib/utils/absolute-to-relative.d.ts +13 -0
  5. package/lib/utils/absolute-to-relative.js +5 -13
  6. package/lib/utils/absolute-to-transform-ready.d.ts +4 -0
  7. package/lib/utils/absolute-to-transform-ready.js +31 -91
  8. package/lib/utils/build-early-exit-match.d.ts +14 -0
  9. package/lib/utils/build-early-exit-match.js +39 -0
  10. package/lib/utils/deduplicate-double-slashes.d.ts +1 -0
  11. package/lib/utils/deduplicate-double-slashes.js +6 -2
  12. package/lib/utils/deduplicate-subdirectory.d.ts +9 -0
  13. package/lib/utils/deduplicate-subdirectory.js +3 -7
  14. package/lib/utils/html-absolute-to-relative.d.ts +3 -0
  15. package/lib/utils/html-absolute-to-relative.js +3 -6
  16. package/lib/utils/html-absolute-to-transform-ready.d.ts +4 -0
  17. package/lib/utils/html-absolute-to-transform-ready.js +4 -31
  18. package/lib/utils/html-relative-to-absolute.d.ts +3 -0
  19. package/lib/utils/html-relative-to-absolute.js +3 -5
  20. package/lib/utils/html-relative-to-transform-ready.d.ts +3 -0
  21. package/lib/utils/html-relative-to-transform-ready.js +2 -5
  22. package/lib/utils/html-to-transform-ready.d.ts +3 -0
  23. package/lib/utils/html-to-transform-ready.js +2 -2
  24. package/lib/utils/html-transform.d.ts +4 -0
  25. package/lib/utils/html-transform.js +10 -30
  26. package/lib/utils/index.d.ts +0 -0
  27. package/lib/utils/index.js +2 -0
  28. package/lib/utils/is-ssl.d.ts +2 -0
  29. package/lib/utils/is-ssl.js +4 -4
  30. package/lib/utils/lexical-absolute-to-relative.d.ts +2 -0
  31. package/lib/utils/lexical-absolute-to-relative.js +4 -6
  32. package/lib/utils/lexical-absolute-to-transform-ready.d.ts +2 -0
  33. package/lib/utils/lexical-absolute-to-transform-ready.js +4 -6
  34. package/lib/utils/lexical-relative-to-absolute.d.ts +3 -0
  35. package/lib/utils/lexical-relative-to-absolute.js +4 -5
  36. package/lib/utils/lexical-relative-to-transform-ready.d.ts +3 -0
  37. package/lib/utils/lexical-relative-to-transform-ready.js +4 -5
  38. package/lib/utils/lexical-to-transform-ready.d.ts +3 -0
  39. package/lib/utils/lexical-to-transform-ready.js +2 -2
  40. package/lib/utils/lexical-transform.d.ts +2 -0
  41. package/lib/utils/lexical-transform.js +6 -19
  42. package/lib/utils/markdown-absolute-to-relative.d.ts +4 -0
  43. package/lib/utils/markdown-absolute-to-relative.js +3 -6
  44. package/lib/utils/markdown-absolute-to-transform-ready.d.ts +5 -0
  45. package/lib/utils/markdown-absolute-to-transform-ready.js +5 -8
  46. package/lib/utils/markdown-relative-to-absolute.d.ts +4 -0
  47. package/lib/utils/markdown-relative-to-absolute.js +3 -6
  48. package/lib/utils/markdown-relative-to-transform-ready.d.ts +4 -0
  49. package/lib/utils/markdown-relative-to-transform-ready.js +3 -6
  50. package/lib/utils/markdown-to-transform-ready.d.ts +3 -0
  51. package/lib/utils/markdown-to-transform-ready.js +2 -2
  52. package/lib/utils/markdown-transform.d.ts +5 -0
  53. package/lib/utils/markdown-transform.js +7 -25
  54. package/lib/utils/mobiledoc-absolute-to-relative.d.ts +2 -0
  55. package/lib/utils/mobiledoc-absolute-to-relative.js +4 -6
  56. package/lib/utils/mobiledoc-absolute-to-transform-ready.d.ts +2 -0
  57. package/lib/utils/mobiledoc-absolute-to-transform-ready.js +4 -6
  58. package/lib/utils/mobiledoc-relative-to-absolute.d.ts +3 -0
  59. package/lib/utils/mobiledoc-relative-to-absolute.js +4 -5
  60. package/lib/utils/mobiledoc-relative-to-transform-ready.d.ts +3 -0
  61. package/lib/utils/mobiledoc-relative-to-transform-ready.js +4 -5
  62. package/lib/utils/mobiledoc-to-transform-ready.d.ts +3 -0
  63. package/lib/utils/mobiledoc-to-transform-ready.js +2 -2
  64. package/lib/utils/mobiledoc-transform.d.ts +1 -0
  65. package/lib/utils/mobiledoc-transform.js +4 -10
  66. package/lib/utils/plaintext-absolute-to-transform-ready.d.ts +4 -0
  67. package/lib/utils/plaintext-absolute-to-transform-ready.js +18 -10
  68. package/lib/utils/plaintext-relative-to-transform-ready.d.ts +2 -0
  69. package/lib/utils/plaintext-relative-to-transform-ready.js +2 -3
  70. package/lib/utils/plaintext-to-transform-ready.d.ts +3 -0
  71. package/lib/utils/plaintext-to-transform-ready.js +2 -2
  72. package/lib/utils/relative-to-absolute.d.ts +13 -0
  73. package/lib/utils/relative-to-absolute.js +6 -18
  74. package/lib/utils/relative-to-transform-ready.d.ts +2 -0
  75. package/lib/utils/relative-to-transform-ready.js +2 -9
  76. package/lib/utils/replace-permalink.d.ts +5 -0
  77. package/lib/utils/replace-permalink.js +2 -3
  78. package/lib/utils/strip-subdirectory-from-path.d.ts +9 -0
  79. package/lib/utils/strip-subdirectory-from-path.js +5 -9
  80. package/lib/utils/to-transform-ready.d.ts +3 -0
  81. package/lib/utils/to-transform-ready.js +2 -2
  82. package/lib/utils/transform-ready-to-absolute.d.ts +1 -0
  83. package/lib/utils/transform-ready-to-absolute.js +9 -27
  84. package/lib/utils/transform-ready-to-relative.d.ts +1 -0
  85. package/lib/utils/transform-ready-to-relative.js +2 -6
  86. package/lib/utils/url-join.d.ts +9 -0
  87. package/lib/utils/url-join.js +2 -8
  88. package/package.json +16 -7
@@ -1,12 +1,12 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  const relativeToTransformReady = require('./relative-to-transform-ready');
2
-
3
4
  const plaintextRelativeToTransformReady = function plaintextRelativeToTransformReady(plaintext, rootUrl, itemPath, options) {
4
5
  // itemPath is optional, if it's an object may be the options param instead
5
6
  if (typeof itemPath === 'object' && !options) {
6
7
  options = itemPath;
7
8
  itemPath = null;
8
9
  }
9
-
10
10
  // plaintext links look like "Link title [url]"
11
11
  // those are all we care about so we can do a fast regex here
12
12
  return plaintext.replace(/ \[(\/.*?)\]/g, function (fullMatch, path) {
@@ -14,5 +14,4 @@ const plaintextRelativeToTransformReady = function plaintextRelativeToTransformR
14
14
  return ` [${newPath}]`;
15
15
  });
16
16
  };
17
-
18
17
  module.exports = plaintextRelativeToTransformReady;
@@ -0,0 +1,3 @@
1
+ declare const plaintextRelativeToTransformReady: any;
2
+ declare const plaintextAbsoluteToTransformReady: any;
3
+ declare function plaintextToTransformReady(plaintext: any, siteUrl: any, itemPath: any, options: any): any;
@@ -1,6 +1,7 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  const plaintextRelativeToTransformReady = require('./plaintext-relative-to-transform-ready');
2
4
  const plaintextAbsoluteToTransformReady = require('./plaintext-absolute-to-transform-ready');
3
-
4
5
  function plaintextToTransformReady(plaintext, siteUrl, itemPath, options) {
5
6
  if (typeof itemPath === 'object' && !options) {
6
7
  options = itemPath;
@@ -9,5 +10,4 @@ function plaintextToTransformReady(plaintext, siteUrl, itemPath, options) {
9
10
  const relativeTransformed = plaintextRelativeToTransformReady(plaintext, siteUrl, itemPath, options);
10
11
  return plaintextAbsoluteToTransformReady(relativeTransformed, siteUrl, options);
11
12
  }
12
-
13
13
  module.exports = plaintextToTransformReady;
@@ -0,0 +1,13 @@
1
+ declare const URL: any;
2
+ declare const urlJoin: any;
3
+ /**
4
+ * Convert a root-relative path to an absolute URL based on the supplied root.
5
+ * Will _only_ convert root-relative urls (/some/path not some/path)
6
+ *
7
+ * @param {string} path
8
+ * @param {string} rootUrl
9
+ * @param {string} itemPath
10
+ * @param {object} options
11
+ * @returns {string} The passed in url or an absolute URL using
12
+ */
13
+ declare const relativeToAbsolute: (path: any, rootUrl: any, itemPath: any, _options: any) => any;
@@ -1,7 +1,8 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  // require the whatwg compatible URL library (same behaviour in node and browser)
2
- const {URL} = require('url');
4
+ const { URL } = require('url');
3
5
  const urlJoin = require('./url-join');
4
-
5
6
  // NOTE: Ghost's relative->absolute handling is a little strange when the rootUrl
6
7
  // includes a subdirectory. Root-relative paths such as /content/image.jpg are
7
8
  // actually treated as subdirectory-relative. This means that it's possible to
@@ -10,7 +11,6 @@ const urlJoin = require('./url-join');
10
11
  // of path styles (/content/image.png and /subdir/content/image.png). To handle
11
12
  // this when all root-relative paths are treated as subdir-relative we have to
12
13
  // rely on subdirectory deduplication.
13
-
14
14
  /**
15
15
  * Convert a root-relative path to an absolute URL based on the supplied root.
16
16
  * Will _only_ convert root-relative urls (/some/path not some/path)
@@ -27,19 +27,16 @@ const relativeToAbsolute = function relativeToAbsolute(path, rootUrl, itemPath,
27
27
  _options = itemPath;
28
28
  itemPath = null;
29
29
  }
30
-
31
30
  // itemPath could be sent as a full url in which case, extract the pathname
32
31
  if (itemPath && itemPath.match(/^http/)) {
33
32
  const itemUrl = new URL(itemPath);
34
33
  itemPath = itemUrl.pathname;
35
34
  }
36
-
37
35
  const defaultOptions = {
38
36
  assetsOnly: false,
39
37
  staticImageUrlPrefix: 'content/images'
40
38
  };
41
39
  const options = Object.assign({}, defaultOptions, _options);
42
-
43
40
  // return the path as-is if it's not an asset path and we're only modifying assets
44
41
  if (options.assetsOnly) {
45
42
  const staticImageUrlPrefixRegex = new RegExp(options.staticImageUrlPrefix);
@@ -47,48 +44,39 @@ const relativeToAbsolute = function relativeToAbsolute(path, rootUrl, itemPath,
47
44
  return path;
48
45
  }
49
46
  }
50
-
51
47
  // if URL is absolute return it as-is
52
48
  try {
53
49
  const parsed = new URL(path, 'http://relative');
54
-
55
50
  if (parsed.origin !== 'http://relative') {
56
51
  return path;
57
52
  }
58
-
59
53
  // Do not convert protocol relative URLs
60
54
  if (path.lastIndexOf('//', 0) === 0) {
61
55
  return path;
62
56
  }
63
- } catch (e) {
57
+ }
58
+ catch (e) {
64
59
  return path;
65
60
  }
66
-
67
61
  // return the path as-is if it's a pure hash param
68
62
  if (path.startsWith('#')) {
69
63
  return path;
70
64
  }
71
-
72
65
  // return the path as-is if it's not root-relative and we have no itemPath
73
66
  if (!itemPath && !path.match(/^\//)) {
74
67
  return path;
75
68
  }
76
-
77
69
  // force root to always have a trailing-slash for consistent behaviour
78
70
  if (!rootUrl.endsWith('/')) {
79
71
  rootUrl = `${rootUrl}/`;
80
72
  }
81
-
82
73
  const parsedRootUrl = new URL(rootUrl);
83
74
  const basePath = path.startsWith('/') ? '' : itemPath;
84
- const fullPath = urlJoin([parsedRootUrl.pathname, basePath, path], {rootUrl});
75
+ const fullPath = urlJoin([parsedRootUrl.pathname, basePath, path], { rootUrl });
85
76
  const absoluteUrl = new URL(fullPath, rootUrl);
86
-
87
77
  if (options.secure) {
88
78
  absoluteUrl.protocol = 'https:';
89
79
  }
90
-
91
80
  return absoluteUrl.toString();
92
81
  };
93
-
94
82
  module.exports = relativeToAbsolute;
@@ -0,0 +1,2 @@
1
+ declare const relativeToAbsolute: any;
2
+ declare const relativeToTransformReady: (url: any, root: any, itemPath: any, _options: any) => any;
@@ -1,12 +1,12 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  const relativeToAbsolute = require('./relative-to-absolute');
2
-
3
4
  const relativeToTransformReady = function (url, root, itemPath, _options) {
4
5
  // itemPath is optional, if it's an object may be the options param instead
5
6
  if (typeof itemPath === 'object' && !_options) {
6
7
  _options = itemPath;
7
8
  itemPath = null;
8
9
  }
9
-
10
10
  const defaultOptions = {
11
11
  replacementStr: '__GHOST_URL__',
12
12
  staticImageUrlPrefix: 'content/images'
@@ -15,28 +15,21 @@ const relativeToTransformReady = function (url, root, itemPath, _options) {
15
15
  secure: false
16
16
  };
17
17
  const options = Object.assign({}, defaultOptions, _options, overrideOptions);
18
-
19
18
  // convert to absolute
20
19
  const absoluteUrl = relativeToAbsolute(url, root, itemPath, options);
21
-
22
20
  if (absoluteUrl === url) {
23
21
  return url;
24
22
  }
25
-
26
23
  const rootUrl = new URL(root);
27
24
  const rootPathname = rootUrl.pathname.replace(/\/$/, '');
28
-
29
25
  // only convert to transform-ready if root url has no subdirectory or the subdirectory matches
30
26
  if (!url.match(/^\//) || rootPathname === '' || url.indexOf(rootPathname) === 0 || url.indexOf(`/${options.staticImageUrlPrefix}`) === 0) {
31
27
  // replace root with replacement string
32
28
  const transformedUrl = absoluteUrl
33
29
  .replace(root, `${options.replacementStr}/`) // always have trailing slash after magic string
34
30
  .replace(/([^:])\/\//g, '$1/');
35
-
36
31
  return transformedUrl;
37
32
  }
38
-
39
33
  return url;
40
34
  };
41
-
42
35
  module.exports = relativeToTransformReady;
@@ -0,0 +1,5 @@
1
+ declare const moment: any;
2
+ /**
3
+ * creates the url path for a post based on blog timezone and permalink pattern
4
+ */
5
+ declare function replacePermalink(permalink: any, resource: any, timezone?: string): any;
@@ -1,5 +1,6 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  const moment = require('moment-timezone');
2
-
3
4
  /**
4
5
  * creates the url path for a post based on blog timezone and permalink pattern
5
6
  */
@@ -33,7 +34,6 @@ function replacePermalink(permalink, resource, timezone = 'UTC') {
33
34
  return resource.id;
34
35
  }
35
36
  };
36
-
37
37
  // replace tags like :slug or :year with actual values
38
38
  const permalinkKeys = Object.keys(permalinkLookUp);
39
39
  return output.replace(/(:[a-z_]+)/g, function (match) {
@@ -42,5 +42,4 @@ function replacePermalink(permalink, resource, timezone = 'UTC') {
42
42
  }
43
43
  });
44
44
  }
45
-
46
45
  module.exports = replacePermalink;
@@ -0,0 +1,9 @@
1
+ declare const URL: any;
2
+ /**
3
+ * Removes the directory in the root url from the relative path
4
+ *
5
+ * @param {string} path Relative path (eg, '/my/subdir/my/file.png)
6
+ * @param {string} rootUrl Root URL (eg, 'https://mysite.com/my/subdir/)
7
+ * @returns {string} Path relative to the rootUrl's path
8
+ */
9
+ declare const stripSubdirectoryFromPath: (path?: string, rootUrl?: string) => string;
@@ -1,5 +1,6 @@
1
- const {URL} = require('url');
2
-
1
+ "use strict";
2
+ // @ts-nocheck
3
+ const { URL } = require('url');
3
4
  /**
4
5
  * Removes the directory in the root url from the relative path
5
6
  *
@@ -12,25 +13,20 @@ const stripSubdirectoryFromPath = function stripSubdirectoryFromPath(path = '',
12
13
  if (!rootUrl.endsWith('/')) {
13
14
  rootUrl = `${rootUrl}/`;
14
15
  }
15
-
16
16
  let parsedRoot;
17
-
18
17
  try {
19
18
  parsedRoot = new URL(rootUrl);
20
- } catch (e) {
19
+ }
20
+ catch (e) {
21
21
  return path;
22
22
  }
23
-
24
23
  // do nothing if rootUrl does not have a subdirectory
25
24
  if (parsedRoot.pathname === '/') {
26
25
  return path;
27
26
  }
28
-
29
27
  if (path.startsWith(parsedRoot.pathname)) {
30
28
  return path.replace(parsedRoot.pathname, '/');
31
29
  }
32
-
33
30
  return path;
34
31
  };
35
-
36
32
  module.exports = stripSubdirectoryFromPath;
@@ -0,0 +1,3 @@
1
+ declare const relativeToAbsolute: any;
2
+ declare const absoluteToTransformReady: any;
3
+ declare function toTransformReady(url: any, siteUrl: any, itemPath: any, options: any): any;
@@ -1,6 +1,7 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  const relativeToAbsolute = require('./relative-to-absolute');
2
4
  const absoluteToTransformReady = require('./absolute-to-transform-ready');
3
-
4
5
  function toTransformReady(url, siteUrl, itemPath, options) {
5
6
  if (typeof itemPath === 'object' && !options) {
6
7
  options = itemPath;
@@ -9,5 +10,4 @@ function toTransformReady(url, siteUrl, itemPath, options) {
9
10
  const absoluteUrl = relativeToAbsolute(url, siteUrl, itemPath, options);
10
11
  return absoluteToTransformReady(absoluteUrl, siteUrl, options);
11
12
  }
12
-
13
13
  module.exports = toTransformReady;
@@ -0,0 +1 @@
1
+ declare const transformReadyToAbsolute: (str: string | undefined, root: any, _options?: {}) => string;
@@ -1,14 +1,8 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  function escapeRegExp(string) {
2
4
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3
5
  }
4
-
5
- function trimTrailingSlash(url) {
6
- if (!url) {
7
- return url;
8
- }
9
- return url.replace(/\/+$/, '');
10
- }
11
-
12
6
  const transformReadyToAbsolute = function (str = '', root, _options = {}) {
13
7
  const defaultOptions = {
14
8
  replacementStr: '__GHOST_URL__',
@@ -20,34 +14,22 @@ const transformReadyToAbsolute = function (str = '', root, _options = {}) {
20
14
  mediaBaseUrl: null
21
15
  };
22
16
  const options = Object.assign({}, defaultOptions, _options);
23
-
24
17
  if (!str || str.indexOf(options.replacementStr) === -1) {
25
18
  return str;
26
19
  }
27
-
28
20
  const replacementRegex = new RegExp(escapeRegExp(options.replacementStr), 'g');
29
- const fallbackBase = trimTrailingSlash(options.imageBaseUrl || root);
30
- const mediaBase = trimTrailingSlash(options.mediaBaseUrl);
31
- const filesBase = trimTrailingSlash(options.filesBaseUrl);
32
- const imageBase = trimTrailingSlash(options.imageBaseUrl) || fallbackBase;
33
-
34
21
  return str.replace(replacementRegex, (match, offset) => {
35
22
  const remainder = str.slice(offset + match.length);
36
-
37
- if (options.staticMediaUrlPrefix && remainder.startsWith(`/${options.staticMediaUrlPrefix}`) && mediaBase) {
38
- return mediaBase;
23
+ if (remainder.startsWith(`/${options.staticMediaUrlPrefix}`) && options.mediaBaseUrl) {
24
+ return options.mediaBaseUrl.replace(/\/$/, '');
39
25
  }
40
-
41
- if (options.staticFilesUrlPrefix && remainder.startsWith(`/${options.staticFilesUrlPrefix}`) && filesBase) {
42
- return filesBase;
26
+ if (remainder.startsWith(`/${options.staticFilesUrlPrefix}`) && options.filesBaseUrl) {
27
+ return options.filesBaseUrl.replace(/\/$/, '');
43
28
  }
44
-
45
- if (options.staticImageUrlPrefix && remainder.startsWith(`/${options.staticImageUrlPrefix}`) && imageBase) {
46
- return imageBase;
29
+ if (remainder.startsWith(`/${options.staticImageUrlPrefix}`) && options.imageBaseUrl) {
30
+ return options.imageBaseUrl.replace(/\/$/, '');
47
31
  }
48
-
49
- return fallbackBase;
32
+ return root.replace(/\/$/, '');
50
33
  });
51
34
  };
52
-
53
35
  module.exports = transformReadyToAbsolute;
@@ -0,0 +1 @@
1
+ declare const transformReadyToRelative: (str: string | undefined, root: any, _options?: {}) => string;
@@ -1,24 +1,20 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  function escapeRegExp(string) {
2
4
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3
5
  }
4
-
5
6
  const transformReadyToRelative = function (str = '', root, _options = {}) {
6
7
  const defaultOptions = {
7
8
  replacementStr: '__GHOST_URL__'
8
9
  };
9
10
  const options = Object.assign({}, defaultOptions, _options);
10
-
11
11
  if (!str || str.indexOf(options.replacementStr) === -1) {
12
12
  return str;
13
13
  }
14
-
15
14
  const rootURL = new URL(root);
16
15
  // subdir with no trailing slash because we'll always have a trailing slash after the magic string
17
16
  const subdir = rootURL.pathname.replace(/\/$/, '');
18
-
19
17
  const replacementRegex = new RegExp(escapeRegExp(options.replacementStr), 'g');
20
-
21
18
  return str.replace(replacementRegex, subdir);
22
19
  };
23
-
24
20
  module.exports = transformReadyToRelative;
@@ -0,0 +1,9 @@
1
+ declare const deduplicateSubdirectory: any;
2
+ /** urlJoin
3
+ * Returns a URL/path for internal use in Ghost.
4
+ * @param {string[]} parts takes parts and concats those to a valid path/URL.
5
+ * @param {Object} options
6
+ * @param {string} options.rootUrl used for deduplicating any subdirectories
7
+ * @return {string} URL concatinated URL/path of arguments.
8
+ */
9
+ declare function urlJoin(parts: any, options: any): any;
@@ -1,5 +1,6 @@
1
+ "use strict";
2
+ // @ts-nocheck
1
3
  const deduplicateSubdirectory = require('./deduplicate-subdirectory');
2
-
3
4
  /** urlJoin
4
5
  * Returns a URL/path for internal use in Ghost.
5
6
  * @param {string[]} parts takes parts and concats those to a valid path/URL.
@@ -9,29 +10,22 @@ const deduplicateSubdirectory = require('./deduplicate-subdirectory');
9
10
  */
10
11
  function urlJoin(parts, options) {
11
12
  let prefixDoubleSlash = false;
12
-
13
13
  // Remove empty item at the beginning
14
14
  if (parts[0] === '') {
15
15
  parts.shift();
16
16
  }
17
-
18
17
  // Handle schemeless protocols
19
18
  if (parts[0].indexOf('//') === 0) {
20
19
  prefixDoubleSlash = true;
21
20
  }
22
-
23
21
  // join the elements using a slash
24
22
  let url = parts.join('/');
25
-
26
23
  // Fix multiple slashes
27
24
  url = url.replace(/(^|[^:])\/\/+/g, '$1/');
28
-
29
25
  // Put the double slash back at the beginning if this was a schemeless protocol
30
26
  if (prefixDoubleSlash) {
31
27
  url = url.replace(/^\//, '//');
32
28
  }
33
-
34
29
  return deduplicateSubdirectory(url, options.rootUrl);
35
30
  }
36
-
37
31
  module.exports = urlJoin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/url-utils",
3
- "version": "5.0.0-rc.1",
3
+ "version": "5.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/TryGhost/SDK.git",
@@ -9,10 +9,14 @@
9
9
  "author": "Ghost Foundation",
10
10
  "license": "MIT",
11
11
  "main": "index.js",
12
+ "types": "lib/UrlUtils.d.ts",
12
13
  "scripts": {
13
14
  "dev": "echo \"Implement me!\"",
14
- "test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --reporter html mocha './test/**/*.test.js'",
15
- "lint": "eslint . --ext .js --cache",
15
+ "pretest": "yarn build",
16
+ "test": "NODE_ENV=testing c8 --src lib --all --reporter text --reporter cobertura --reporter html mocha './test/**/*.test.js'",
17
+ "build": "tsc -p tsconfig.json",
18
+ "lint": "eslint src test index.js --ext .js,.ts --cache",
19
+ "prepare": "NODE_ENV=production yarn build",
16
20
  "posttest": "yarn lint"
17
21
  },
18
22
  "files": [
@@ -23,12 +27,16 @@
23
27
  "access": "public"
24
28
  },
25
29
  "devDependencies": {
26
- "@tryghost/config-url-helpers": "^1.0.17",
30
+ "@tryghost/config-url-helpers": "^1.0.19",
31
+ "@types/cheerio": "^0.22.31",
32
+ "@types/lodash": "^4.14.202",
33
+ "@types/node": "^20.0.0",
27
34
  "c8": "10.1.3",
28
- "mocha": "11.7.4",
35
+ "mocha": "11.7.5",
29
36
  "rewire": "9.0.1",
30
37
  "should": "13.2.3",
31
- "sinon": "21.0.0"
38
+ "sinon": "21.0.0",
39
+ "typescript": "5.9.3"
32
40
  },
33
41
  "dependencies": {
34
42
  "cheerio": "^0.22.0",
@@ -38,5 +46,6 @@
38
46
  "remark": "^11.0.2",
39
47
  "remark-footnotes": "^1.0.0",
40
48
  "unist-util-visit": "^2.0.0"
41
- }
49
+ },
50
+ "gitHead": "91913b7a8e8afc3ddc411eceacb3d5b271671bd6"
42
51
  }