Repository URL to install this package:
|
Version:
1.0.10 ▾
|
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,
}