Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/utils / src / toSecureProtocol.ts
Size: Mime:
import { isObj, isString } from 'exotic'

/**
 * @todo - wonder if this should be in view layer in  the atom?
 */
const toHTTPS = (url: string): string => {
  return url.includes('https://') === true
    ? url
    : url.replace(/http:\/\//gim, 'https://')
}

interface Image {
  src?: string
  url?: string
  value?: string
}

// const IMAGE_PROPS_LIST = ['src', 'url', 'image', 'value']
// const toFirstImagePropFound = coerceFirstPropFor(IMAGE_PROPS_LIST)
const fromUnsecureToSecureImage = (image: Image | string) => {
  if (isString(image)) {
    return toHTTPS(image)
  } else if (isObj(image)) {
    // @todo modules/compose oneOf
    // const alt = name || item.alt || props.label || ''
    if (isString(image.src) === true) {
      image.src = toHTTPS(image.src)
    } else if (isString(image.url) === true) {
      image.url = toHTTPS(image.url)
    } else if (isString(image.value) === true) {
      image.value = toHTTPS(image.value)
    }

    // @todo enable
    // const url = image.src || image.url || image.image || image.value || ''
    // const [prop, value] = toFirstImagePropFound(image)
    // image[prop] = toHTTPS(value)
    return image
  } else {
    // throw new TypeError
    return image
  }
}

export default fromUnsecureToSecureImage
export {
  fromUnsecureToSecureImage,
  fromUnsecureToSecureImage as toSecureProtocol,
  toHTTPS,
}