UNPKG

@gravityforms/utils

Version:
27 lines (26 loc) 684 B
/** * @module isImageUrl * @description Tests if an url ends with a section that contains one of: `jpg|jpeg|png|gif|svg`. * * @since 1.0.0 * * @param {string} url The url to test. * * @return {boolean} Whether the passed string is an image url or not. * * @example * import { isImageUrl } from "@gravityforms/utils"; * * function Example() { * const url = 'https://some-url.com/hello.jpg'; * if ( isImageUrl( url ) ) { * // do something * } * } * */ export default function isImageUrl( url = '' ) { const ext = url.split( '.' ).pop(); const test = ext.toLowerCase().match( /(jpg|jpeg|png|gif|svg)/g ); return ( test && test.length > 0 ) || false; }