In any case, make sure you check the returns of split and pop.
String.prototype.split() can return an empty string if the separator is the last character of the string; or the entire string if the separator is not found.
Agreed. Using built-in methods are always better than reinventing the wheel. But, we still need to read project entry assuming it's index without knowing the extension. Is It .ts or .js?
These built-ins, helpful when knowing the full name with the extension included file.js. However, I tried to introduce a method to extract an anonymous extension.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Node.js, personally I prefer to use the built-in path methods.
path.parse
path.extname
In any case, make sure you check the returns of split and pop.
Was about to comment this, but you were faster than me. Totally agreed here :)
Thanks, David!
Agreed. Using built-in methods are always better than reinventing the wheel. But, we still need to read project entry assuming it's
index
without knowing the extension. Is It.ts
or.js
?These built-ins, helpful when knowing the full name with the extension included
file.js
. However, I tried to introduce a method to extract an anonymous extension.