#Checking if a const is defined in a certain file
37 messages · Page 1 of 1 (latest)
you could use a dynamic import to do that
await import("./file") and then check the debug object is present or not
but I don't really recommend doing that
maybe you should explain what you're trying to do a bit more, so that we can come up with a better solution
Well I guess just if input debug exists in some function or whatever you can come up with, execute it, else console.log. Just basically going to introduce a docs commands, so I can have multiple inputs
you should set an env variable
and check if it exists or not
and based on that, do whatever you wanna do
oh, but wait
don't don't need to check if the variable exists or not
you can just set it
and check it's value
like, true or false
that also works and is way easier
Currently I'm confused, so I would need to check if input is in the env variable, if so, just import the function and run it?
yes
you cfould also just import the function, just like any function
and the debug function would check if the env variable is defined or not
and if not, it just doesn't do anything and return directly
might be cleaner
i mean it could be anything other than debug
Also it would be cleaner to check if there's a function like I explained, but why don't you recommend?
So users can't escape the characters right and abuse with commands?
since you can't really access a variable that doesn't exit
so there is no way to check if it exists or not by accessing it
wut? that's totally unrelated
Then why don't you recommend? I mean it would be more cleaner and simpler, no?
no
you can't access it if it doesn't exist
and since you can't access it, you can't check to see if it's defined or not
if you need flags, use env variables
or a global config object
don't check for the existance or not of a variable
How about instead of a function, maybe introduce it in a single function and make something like a JSON
I don't see how that is related