Reputation: 1
I've a Constant like below stored in a file helper.js
export const Helper = {
a() {
return "This is just a string"
},
convertToSlug(str) {
return str
.toLowerCase()
.replace(/[^\w ]+/g, "")
.replace(/ +/g, "-")
}
}
From this i want to import only convertToSlug function in another file like below
import { convertToSlug } from "helper.js"
How to do that? I tried the same but getting error
"export 'convertToSlug' was not found in '@/utils/helper'
Upvotes: 0
Views: 279
Reputation: 161657
If you want import { convertToSlug } from "helper.js"
to work then you need to have an export named convertToSlug
. Right now you've grouped everything inside Helper
but there doesn't seem to be any reason for that. It looks like most likely you'd want
export function a() {
return "This is just a string"
}
export function convertToSlug(str) {
return str
.toLowerCase()
.replace(/[^\w ]+/g, "")
.replace(/ +/g, "-")
}
Upvotes: 1