sdthaker / Node-TILify

"Today I Learned" tool that converts text file or a directory of text files to HTML files and beyond

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extract filename with basename() method

avelynhc opened this issue · comments

When you need to extract only the filename from the file path, you can use the basename() method. This function returns only the filename, so you don't need to use split in this case.

Instead of using split() in line 138-139 helper.js

    let inputFileArr = inputFile.split('/');
    fileName = inputFileArr[inputFileArr.length - 1].split('.')[0];

Use path.basename()

import path from "path";
fileName = path.basename(inputFile, '.txt');

This issue is now fixed: 472d27e