@tryghost/url-utils 5.1.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.
@@ -39,7 +39,7 @@ const absoluteToRelative = function absoluteToRelative(url, rootUrl, _options =
39
39
  return url;
40
40
  }
41
41
  }
42
- catch (e) {
42
+ catch {
43
43
  return url;
44
44
  }
45
45
  if (!parsedRoot) {
@@ -10,7 +10,7 @@ function isRelative(url) {
10
10
  try {
11
11
  parsedInput = new url_1.URL(url, 'http://relative');
12
12
  }
13
- catch (e) {
13
+ catch {
14
14
  // url was unparseable
15
15
  return false;
16
16
  }
@@ -1,15 +1,47 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const html_transform_1 = __importDefault(require("./html-transform"));
39
+ const html_transform_1 = __importStar(require("./html-transform"));
7
40
  const relative_to_absolute_1 = __importDefault(require("./relative-to-absolute"));
8
41
  function htmlRelativeToAbsolute(html = '', siteUrl, itemPath, _options = {}) {
9
42
  const defaultOptions = { assetsOnly: false, secure: false };
10
43
  const options = Object.assign({}, defaultOptions, _options || {});
11
- // exit early and avoid parsing if the content does not contain an attribute we might transform
12
- options.earlyExitMatchStr = 'href=|src=|srcset=';
44
+ options.earlyExitMatchStr = html_transform_1.earlyExitMatchStr;
13
45
  if (options.assetsOnly) {
14
46
  options.earlyExitMatchStr = options.staticImageUrlPrefix;
15
47
  }
@@ -1,9 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const html_transform_1 = __importDefault(require("./html-transform"));
39
+ const html_transform_1 = __importStar(require("./html-transform"));
7
40
  const relative_to_transform_ready_1 = __importDefault(require("./relative-to-transform-ready"));
8
41
  const htmlRelativeToTransformReady = function (html = '', root, itemPath, _options) {
9
42
  // itemPath is optional, if it's an object may be the options param instead
@@ -23,8 +56,7 @@ const htmlRelativeToTransformReady = function (html = '', root, itemPath, _optio
23
56
  secure: false
24
57
  };
25
58
  const options = Object.assign({}, defaultOptions, finalOptions, overrideOptions);
26
- // exit early and avoid parsing if the content does not contain an attribute we might transform
27
- options.earlyExitMatchStr = 'href=|src=|srcset=';
59
+ options.earlyExitMatchStr = html_transform_1.earlyExitMatchStr;
28
60
  if (options.assetsOnly) {
29
61
  options.earlyExitMatchStr = options.staticImageUrlPrefix;
30
62
  }
@@ -1,3 +1,5 @@
1
1
  import type { HtmlTransformOptionsInput, UrlTransformFunction } from './types';
2
+ export declare const transformAttributes: string[];
3
+ export declare const earlyExitMatchStr: string;
2
4
  declare function htmlTransform(html: string | undefined, siteUrl: string, transformFunction: UrlTransformFunction, itemPath: string | null, _options?: HtmlTransformOptionsInput): string;
3
5
  export default htmlTransform;
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.earlyExitMatchStr = exports.transformAttributes = void 0;
4
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
3
5
  const cheerio = require('cheerio');
6
+ exports.transformAttributes = ['href', 'src', 'srcset', 'style'];
7
+ exports.earlyExitMatchStr = exports.transformAttributes
8
+ .map(attr => `${attr}=`)
9
+ .join('|');
4
10
  function escapeRegExp(string) {
5
11
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
6
12
  }
@@ -36,8 +42,7 @@ function htmlTransform(html = '', siteUrl, transformFunction, itemPath, _options
36
42
  }
37
43
  replacements[key].push(replacement);
38
44
  }
39
- // find all of the relative url attributes that we care about
40
- ['href', 'src', 'srcset', 'style'].forEach((attributeName) => {
45
+ exports.transformAttributes.forEach((attributeName) => {
41
46
  htmlContent('[' + attributeName + ']').each((ix, el) => {
42
47
  // ignore <stream> elems and html inside of <code> elements
43
48
  const elementName = 'name' in el ? el.name : null;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
3
4
  const _ = require('lodash');
4
5
  function lexicalTransform(serializedLexical, siteUrl, transformFunction, itemPath, _options = {}) {
5
6
  const defaultOptions = { assetsOnly: false, secure: false, nodes: [], transformMap: {} };
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
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,6 +22,7 @@ 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
  }
25
28
  if (!remark) {
@@ -62,7 +62,7 @@ const relativeToAbsolute = function relativeToAbsolute(path, rootUrl, itemPath,
62
62
  return path;
63
63
  }
64
64
  }
65
- catch (e) {
65
+ catch {
66
66
  return path;
67
67
  }
68
68
  // return the path as-is if it's a pure hash param
@@ -17,7 +17,7 @@ const stripSubdirectoryFromPath = function stripSubdirectoryFromPath(path = '',
17
17
  try {
18
18
  parsedRoot = new url_1.URL(rootUrl);
19
19
  }
20
- catch (e) {
20
+ catch {
21
21
  return path;
22
22
  }
23
23
  // do nothing if rootUrl does not have a subdirectory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/url-utils",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/TryGhost/SDK.git",
@@ -26,7 +26,7 @@
26
26
  "access": "public"
27
27
  },
28
28
  "devDependencies": {
29
- "@tryghost/config-url-helpers": "^1.0.19",
29
+ "@tryghost/config-url-helpers": "^1.0.20",
30
30
  "@types/cheerio": "^0.22.31",
31
31
  "@types/lodash": "^4.14.202",
32
32
  "@types/node": "^20.0.0",
@@ -34,7 +34,7 @@
34
34
  "mocha": "11.7.5",
35
35
  "rewire": "9.0.1",
36
36
  "should": "13.2.3",
37
- "sinon": "21.0.0",
37
+ "sinon": "21.0.1",
38
38
  "typescript": "5.9.3"
39
39
  },
40
40
  "dependencies": {
@@ -46,5 +46,5 @@
46
46
  "remark-footnotes": "1.0.0",
47
47
  "unist-util-visit": "^2.0.0"
48
48
  },
49
- "gitHead": "a97d783ddb64ae80592ec03468b221a4ec37948a"
49
+ "gitHead": "a5b249c5514742350f74bcb30b332977d373598a"
50
50
  }