@rokkit/core 1.0.0-next.123 → 1.0.0-next.124

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils.js +18 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/core",
3
- "version": "1.0.0-next.123",
3
+ "version": "1.0.0-next.124",
4
4
  "description": "Contains core utility functions and classes that can be used in various components.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
package/src/utils.js CHANGED
@@ -155,31 +155,33 @@ export function hex2rgb(hex) {
155
155
  * @returns {boolean} - Returns true if the string is an image URL
156
156
  */
157
157
  function isImageUrl(str) {
158
+ // Fallback regex-based validation
159
+ const fallbackValidation = () => {
160
+ const urlRegex = /^https?:\/\/.+\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff)(\?.*)?$/i
161
+ return urlRegex.test(str)
162
+ }
163
+
158
164
  // Check if the string looks like a URL
159
165
  try {
160
- // Use browser-native URL constructor or fallback to regex
161
- const url = typeof URL !== 'undefined' ? new URL(str) : null
162
-
163
- if (url) {
166
+ // Use browser-native URL constructor if available
167
+ if (typeof URL !== 'undefined') {
168
+ const url = new URL(str)
169
+ // Only accept HTTP/HTTPS protocols
170
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
171
+ return false
172
+ }
164
173
  // Check common image extensions
165
174
  const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg', '.tiff']
166
175
  const path = url.pathname.toLowerCase()
167
-
168
- if (imageExtensions.some((ext) => path.endsWith(ext))) {
169
- return true
170
- }
171
- } else {
172
- // Fallback regex-based URL validation for image extensions
173
- const urlRegex = /^https?:\/\/.+\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff)(\?.*)?$/i
174
- return urlRegex.test(str)
176
+ return imageExtensions.some((ext) => path.endsWith(ext))
175
177
  }
176
178
 
177
- return false
179
+ // Fallback if URL constructor is not available
180
+ return fallbackValidation()
178
181
  // eslint-disable-next-line no-unused-vars
179
182
  } catch (e) {
180
- // Fallback regex-based validation
181
- const urlRegex = /^https?:\/\/.+\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff)(\?.*)?$/i
182
- return urlRegex.test(str)
183
+ // Fallback if URL constructor fails
184
+ return fallbackValidation()
183
185
  }
184
186
  }
185
187
  /**