Skip to content

Commit b603cbf

Browse files
author
David Silva
committed
Created a function that verifies urls from the data before displaying them
1 parent bf08c6b commit b603cbf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/constants/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
export const noop = () => {};
2+
3+
export const ensureUrl = (uri) => {
4+
if (!uri || typeof uri !== 'string') return '';
5+
const url = uri.trim();
6+
if (url.startsWith === '/') return url;
7+
if (url.match(/^http(s)?:\/\//) !== null) return url;
8+
return 'http://' + url;
9+
};

0 commit comments

Comments
 (0)