Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
How to find the given image source (url) is in svg format?

I am getting images as URLs from my CMS provider like this

SVG image src URL:

https://example.com/svg.png

Here I am getting images in different formats like png, jpeg, jpg, SVG, etc... In this, I need to find the images only in SVG format.

I planned to create a utility function and going to pass all the image URLs to it. It will return true only if the image is in SVG format else it will return false.

Is there any way I can do this in Javascript (ReactJS)? If any source or plugin is available. Please share that.

Will this function work ?


function isSvgFormatImage(url) {
  return url.split('.').includes('svg')
}

Thanks in advance

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Yes, your function would work, one a little more efficient would be:

/**
 * @param {string} url
 */
function isSVGFormatImage(url) {
  return url.endsWith(".svg");
}

// Some test cases

console.assert(isSVGFormatImage("https://example.com/another.svg") === true);

console.assert(isSVGFormatImage("https://example.com/svg.png") === false);

console.assert(isSVGFormatImage("https://example.com/file.jpg") === false);

  • console.assert docs
about 4 years ago · Juan Pablo Isaza Report

0

If the url ends in ".svg", this function returns true

function isSvgFormat (url){
   return url.endsWith(".svg")
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!