@learncard/helpers 1.4.0 → 1.4.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.
@@ -17915,11 +17915,21 @@ var generateSrcSet3 = /* @__PURE__ */ __name((url, resolutions, { fix = false }
17915
17915
 
17916
17916
  // src/images/images.helpers.ts
17917
17917
  var Providers = { filestack: filestack_helpers_exports, unsplash: unsplash_helpers_exports, discord: discord_helpers_exports };
17918
+ var isHostnameMatch = /* @__PURE__ */ __name((hostname, target) => {
17919
+ return hostname === target || hostname.endsWith(`.${target}`);
17920
+ }, "isHostnameMatch");
17918
17921
  var getProvider = /* @__PURE__ */ __name((url) => {
17919
- if (url?.includes("cdn.filestackcontent.com")) return "filestack";
17920
- if (url?.includes("images.unsplash.com")) return "unsplash";
17921
- if (url?.includes("cdn.discordapp.com")) return "discord";
17922
- return null;
17922
+ if (!url) return null;
17923
+ try {
17924
+ const normalizedUrl = url.startsWith("//") ? `https:${url}` : url;
17925
+ const { hostname } = new URL(normalizedUrl);
17926
+ if (isHostnameMatch(hostname, "cdn.filestackcontent.com")) return "filestack";
17927
+ if (isHostnameMatch(hostname, "images.unsplash.com")) return "unsplash";
17928
+ if (isHostnameMatch(hostname, "cdn.discordapp.com")) return "discord";
17929
+ return null;
17930
+ } catch {
17931
+ return null;
17932
+ }
17923
17933
  }, "getProvider");
17924
17934
  var changeQuality4 = /* @__PURE__ */ __name((url, quality) => {
17925
17935
  const provider = getProvider(url);
@@ -17950,6 +17960,30 @@ var getUrlsFromSrcSet = /* @__PURE__ */ __name((srcSet) => {
17950
17960
  }, []);
17951
17961
  }, "getUrlsFromSrcSet");
17952
17962
 
17963
+ // src/images/sanitize.helpers.ts
17964
+ var sanitizeImageUrl = /* @__PURE__ */ __name((url, options = {}) => {
17965
+ if (!url) return void 0;
17966
+ const { allowBlobUrls = false, allowDataUrls = false } = options;
17967
+ try {
17968
+ const parsed = new URL(url);
17969
+ if (parsed.protocol === "https:" || parsed.protocol === "http:") {
17970
+ return parsed.href;
17971
+ }
17972
+ if (allowBlobUrls && parsed.protocol === "blob:") {
17973
+ return parsed.href;
17974
+ }
17975
+ if (allowDataUrls && parsed.protocol === "data:") {
17976
+ if (url.startsWith("data:image/")) {
17977
+ return url;
17978
+ }
17979
+ return void 0;
17980
+ }
17981
+ return void 0;
17982
+ } catch {
17983
+ return void 0;
17984
+ }
17985
+ }, "sanitizeImageUrl");
17986
+
17953
17987
  // src/types/index.ts
17954
17988
  var isNotMaybe = /* @__PURE__ */ __name((value) => value !== void 0 && value !== null, "isNotMaybe");
17955
17989
  var filterMaybes = /* @__PURE__ */ __name((array) => array?.filter(isNotMaybe) ?? [], "filterMaybes");
@@ -18683,6 +18717,7 @@ export {
18683
18717
  requiredEnvironmentString,
18684
18718
  resizeAndChangeQuality4 as resizeAndChangeQuality,
18685
18719
  resolveStorageReadResult,
18720
+ sanitizeImageUrl,
18686
18721
  setBitstringStatusListBit,
18687
18722
  stripSdJwtReservedClaims,
18688
18723
  synthesizeDidJwk,