import { SvgSpriteAttrs , SvgSpriteOptions } from './defs' ; export const defaultOptions = { class : 'icon' , url : '/assets/svg/sprite.svg' , } ; export const getHref = ( id , options ) => options . url === '' ? `#${ id }` : `${ options . url }#${ id }` ; export const checkClass = ( classes , options ) => { const classToAdd = options . class as string ; return classes ? classes . split ( ' ' ) . some ( className => { const [ base ] = className . split ( /(-|_)/ ) ; return ( base . indexOf ( classToAdd ) !== - 1 && base . length === classToAdd . length ) ; } ) : false ; } ; export const getAttributes = ( size ? ) => { const attrs = { height : null , width : null , viewBox : null , } ; if ( ! size ) { return attrs ; } const sizeValues = size . toString ( ) . replace ( /( |, |,)/g , ' ' ) . split ( ' ' ) ; const l = sizeValues . length ; if ( l === 3 || l > 4 ) { console . warn ( `[vue-svg-sprite] size: "${ size }" is not valid` ) ; return attrs ; } const viewBox = [ ] ; viewBox [ 0 ] = l < 4 ? 0 : sizeValues [ 0 ] ; viewBox [ 1 ] = l < 4 ? 0 : sizeValues [ 1 ] ; attrs . width = viewBox [ 2 ] = l < 4 ? sizeValues [ 0 ] : sizeValues [ 2 ] ; attrs . height = viewBox [ 3 ] = sizeValues [ l - 1 ] ; attrs . viewBox = viewBox . join ( ' ' ) ; return attrs ; } ;