Change the File Extension in Typescript – Using Path

Posted by in Software, Tutorial

Following from my previous post, I’ve updated the function to use only the path module. Now, the code looks like:

I’ve updated the workflow presented previously to:

  1. isolate the dir, ext and root components of the path
  2. replace the ext with the new extension
  3. return the normalized version of the composed path

Now, our function accepts complete paths, not only filenames.

Note: The path.normalize() function does NOT calculate the absolute path. It only changes the path separators.


A little experiment: If you find this post and ad below useful, please check the ad out :-)