@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.
@@ -24911,6 +24911,7 @@ __export(index_exports, {
24911
24911
  requiredEnvironmentString: () => requiredEnvironmentString,
24912
24912
  resizeAndChangeQuality: () => resizeAndChangeQuality4,
24913
24913
  resolveStorageReadResult: () => resolveStorageReadResult,
24914
+ sanitizeImageUrl: () => sanitizeImageUrl,
24914
24915
  setBitstringStatusListBit: () => setBitstringStatusListBit,
24915
24916
  stripSdJwtReservedClaims: () => stripSdJwtReservedClaims,
24916
24917
  synthesizeDidJwk: () => synthesizeDidJwk,
@@ -25127,11 +25128,21 @@ var generateSrcSet3 = /* @__PURE__ */ __name((url, resolutions, { fix = false }
25127
25128
 
25128
25129
  // src/images/images.helpers.ts
25129
25130
  var Providers = { filestack: filestack_helpers_exports, unsplash: unsplash_helpers_exports, discord: discord_helpers_exports };
25131
+ var isHostnameMatch = /* @__PURE__ */ __name((hostname, target) => {
25132
+ return hostname === target || hostname.endsWith(`.${target}`);
25133
+ }, "isHostnameMatch");
25130
25134
  var getProvider = /* @__PURE__ */ __name((url) => {
25131
- if (url?.includes("cdn.filestackcontent.com")) return "filestack";
25132
- if (url?.includes("images.unsplash.com")) return "unsplash";
25133
- if (url?.includes("cdn.discordapp.com")) return "discord";
25134
- return null;
25135
+ if (!url) return null;
25136
+ try {
25137
+ const normalizedUrl = url.startsWith("//") ? `https:${url}` : url;
25138
+ const { hostname } = new URL(normalizedUrl);
25139
+ if (isHostnameMatch(hostname, "cdn.filestackcontent.com")) return "filestack";
25140
+ if (isHostnameMatch(hostname, "images.unsplash.com")) return "unsplash";
25141
+ if (isHostnameMatch(hostname, "cdn.discordapp.com")) return "discord";
25142
+ return null;
25143
+ } catch {
25144
+ return null;
25145
+ }
25135
25146
  }, "getProvider");
25136
25147
  var changeQuality4 = /* @__PURE__ */ __name((url, quality) => {
25137
25148
  const provider = getProvider(url);
@@ -25162,6 +25173,30 @@ var getUrlsFromSrcSet = /* @__PURE__ */ __name((srcSet) => {
25162
25173
  }, []);
25163
25174
  }, "getUrlsFromSrcSet");
25164
25175
 
25176
+ // src/images/sanitize.helpers.ts
25177
+ var sanitizeImageUrl = /* @__PURE__ */ __name((url, options = {}) => {
25178
+ if (!url) return void 0;
25179
+ const { allowBlobUrls = false, allowDataUrls = false } = options;
25180
+ try {
25181
+ const parsed = new URL(url);
25182
+ if (parsed.protocol === "https:" || parsed.protocol === "http:") {
25183
+ return parsed.href;
25184
+ }
25185
+ if (allowBlobUrls && parsed.protocol === "blob:") {
25186
+ return parsed.href;
25187
+ }
25188
+ if (allowDataUrls && parsed.protocol === "data:") {
25189
+ if (url.startsWith("data:image/")) {
25190
+ return url;
25191
+ }
25192
+ return void 0;
25193
+ }
25194
+ return void 0;
25195
+ } catch {
25196
+ return void 0;
25197
+ }
25198
+ }, "sanitizeImageUrl");
25199
+
25165
25200
  // src/types/index.ts
25166
25201
  var isNotMaybe = /* @__PURE__ */ __name((value) => value !== void 0 && value !== null, "isNotMaybe");
25167
25202
  var filterMaybes = /* @__PURE__ */ __name((array) => array?.filter(isNotMaybe) ?? [], "filterMaybes");
@@ -25896,6 +25931,7 @@ var isAppDidWeb = /* @__PURE__ */ __name((did) => {
25896
25931
  requiredEnvironmentString,
25897
25932
  resizeAndChangeQuality,
25898
25933
  resolveStorageReadResult,
25934
+ sanitizeImageUrl,
25899
25935
  setBitstringStatusListBit,
25900
25936
  stripSdJwtReservedClaims,
25901
25937
  synthesizeDidJwk,