Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error check on invalid icon paths #2

Open
Tjark-Kuehl opened this issue Jan 30, 2022 · 0 comments
Open

Error check on invalid icon paths #2

Tjark-Kuehl opened this issue Jan 30, 2022 · 0 comments

Comments

@Tjark-Kuehl
Copy link

Tjark-Kuehl commented Jan 30, 2022

Hi,
I just ran in an issue where I couldnt figure out why the package wasnt loading my icon correctly.
After looking deeper into it I found out that I had prefixed my icons with .svg
I know that its not documented like this but I still wasted an hour or so.

Could we implement either an error check or a string replacement here?
https://github.com/danielstgt/svg-vue/blob/master/src/svg-vue.vue#L20

get() {
    const cleanPath = this.icon.replace(new RegExp('.svg$'), '');
    return cleanPath.replace(new RegExp('.'.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'), 'g'), '/') + '.svg';
}

or just throw an error

get() {
    if(this.icon.endsWith('.svg')) {
        throw new Error('invalid icon path');
    }
    return this.icon.replace(new RegExp('.'.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'), 'g'), '/') + '.svg';
}

other then that I really appreciate the package :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant