@lwrjs/shared-utils 0.8.0-alpha.12 → 0.8.0-alpha.13

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.
@@ -24,7 +24,9 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/shared-utils/src/html-meta.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
- extractMetadataFromHtml: () => extractMetadataFromHtml
27
+ extractMetadataFromHtml: () => extractMetadataFromHtml,
28
+ isRelative: () => isRelative,
29
+ isSelfUrl: () => isSelfUrl
28
30
  });
29
31
  var import_identity = __toModule(require("./identity.cjs"));
30
32
  var import_parse5_sax_parser = __toModule(require("parse5-sax-parser"));
@@ -38,12 +40,21 @@ function parseAssetLocation(htmlSource, tagName, attrLocation) {
38
40
  return {
39
41
  url,
40
42
  tagName,
43
+ relative: isRelative(url),
41
44
  location: {
42
45
  startOffset: startOffset + keyAttr.length + 2,
43
46
  endOffset: endOffset - 1
44
47
  }
45
48
  };
46
49
  }
50
+ function isRelative(url) {
51
+ return !url?.match(isNotRelativeRegex);
52
+ }
53
+ var isNotRelativeRegex = /^(http(s)?:\/\/|\/)/i;
54
+ function isSelfUrl(url) {
55
+ return !url || !!url.match(isSelfUrlRegex);
56
+ }
57
+ var isSelfUrlRegex = /^\s*(data:|#)/i;
47
58
  async function extractMetadataFromHtml(htmlSource) {
48
59
  return new Promise((resolve, reject) => {
49
60
  const customElements = [];
@@ -1,4 +1,6 @@
1
1
  import { RenderedViewMetadata } from '@lwrjs/types';
2
+ export declare function isRelative(url: string): boolean;
3
+ export declare function isSelfUrl(url: string): boolean;
2
4
  /**
3
5
  * Pull the custom elements and img tags out of an HTML string, to use as metadata
4
6
  * @param htmlSource - An HTML string to parse
@@ -12,12 +12,23 @@ function parseAssetLocation(htmlSource, tagName, attrLocation) {
12
12
  return {
13
13
  url,
14
14
  tagName,
15
+ relative: isRelative(url),
15
16
  location: {
16
17
  startOffset: startOffset + keyAttr.length + 2 /* =" */,
17
18
  endOffset: endOffset - 1,
18
19
  },
19
20
  };
20
21
  }
22
+ // Detect if this is a relative URL
23
+ export function isRelative(url) {
24
+ return !url?.match(isNotRelativeRegex);
25
+ }
26
+ const isNotRelativeRegex = /^(http(s)?:\/\/|\/)/i;
27
+ // Detect if this is just a self referential URL
28
+ export function isSelfUrl(url) {
29
+ return !url || !!url.match(isSelfUrlRegex);
30
+ }
31
+ const isSelfUrlRegex = /^\s*(data:|#)/i;
21
32
  /**
22
33
  * Pull the custom elements and img tags out of an HTML string, to use as metadata
23
34
  * @param htmlSource - An HTML string to parse
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.12",
7
+ "version": "0.8.0-alpha.13",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -45,13 +45,13 @@
45
45
  "winston": "^3.7.2"
46
46
  },
47
47
  "devDependencies": {
48
- "@lwrjs/diagnostics": "0.8.0-alpha.12",
49
- "@lwrjs/types": "0.8.0-alpha.12",
48
+ "@lwrjs/diagnostics": "0.8.0-alpha.13",
49
+ "@lwrjs/types": "0.8.0-alpha.13",
50
50
  "@types/mime-types": "2.1.1",
51
51
  "@types/path-to-regexp": "^1.7.0"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=14.15.4 <19"
55
55
  },
56
- "gitHead": "eef0342738457f04590e760a0b501e4d78d93416"
56
+ "gitHead": "cc4bc856f34d2ec15df550503dd7463fa31b30e5"
57
57
  }