Repository URL to install this package:
Version:
0.9.5 ▾
|
/**
* @file @todo needs update since we changed
*/
import { isString, isArray } from 'exotic'
import { VideoProps, AliasedVideoTypes, VideoTypes, SourceType, AutoPlay } from './typings'
/**
* @todo similar things with image
*/
function _toType(props: VideoTypes | SourceType) {
if (isString(props)) {
switch (true) {
case props.includes('webm'):
return 'webm'
case props.includes('ogg'):
return 'ogg'
case props.includes('mp4'):
default:
return 'mp4'
}
}
switch (true) {
case !!props.type:
return props.type
case !!props.oggSource:
return 'ogg'
case !!props.webmSource:
return 'webm'
case !!props.mp4Source:
return 'mp4'
// makes it a string then calls again to trigger the above branch
// default: return _toType(toSrc(props))
default:
return 'mp4'
}
}
const toType = (props: VideoProps) => {
const type = _toType(props)
if (type.includes('type')) {
return type
} else {
return 'type/' + type
}
}
function toSrc(props: VideoTypes | SourceType): string {
if (isArray(props.src)) {
return props.src[0]
}
return (
props.src || props.oggSource || props.webmSource || props.mp4Source || props.props || '@@404'
)
}
const alias = {
toCover(props: AliasedVideoTypes): string {
return props.thumbnailImage || props.poster || props.cover
},
toAutoPlay(props: AliasedVideoTypes): AutoPlay {
return props.autoPlay || props.autoplay
},
}
export { toType, toSrc, alias }