How to get the image type from image url in react.js

I am trying to yup validate the image URL and want to check the image type. How can I do so?

Suppose this the image URL :”https://static.wayup.com/company_logo/95tJHraryb_20171220.png”

These are the supported format

const SUPPORTED_FORMATS = ["image/jpg", "image/jpeg", "image/png"];

This is the validation am trying to do for the image

image: Yup.mixed()
    .required("Please select Image")
    .test("fileFormat", "Unsupported Format", (value) => {
      How do i get the image type from the URL?
    }),


  [1]: https://static.wayup.com/company_logo/95tJHraryb_20171220.png

Answer

Just extract the image extension from the url. See https://stackoverflow.com/a/47767860/5771750:

const SUPPORTED_FORMATS = ["jpg", "jpeg", "png"];

image: Yup.mixed()
    .required("Please select Image")
    .test("fileFormat", "Unsupported Format", (value) => {
      return SUPPORTED_FORMATS.indexOf(get_url_extension(value)) !== -1;
    }),

function get_url_extension( url ) {
    return url.split(/[#?]/)[0].split('.').pop().trim();
}