1 import startCase from 'lodash/startCase';
3 const caseString = (str: string, caseFilename: boolean = true) => {
4 // avoid startCase stripping the '/'
7 .map((item, index, arr) => {
8 if (!caseFilename && index === arr.length - 1) {
12 return startCase(item);
17 export const getTitle = (filename: string, caseFilename?: boolean) => {
18 const directoryPrefix = 'src/stories/';
19 const storySuffix = /.stories.(tsx|mdx)/;
20 const strippedFileName = filename.replace(directoryPrefix, '').replace(storySuffix, '');
22 return caseString(strippedFileName, caseFilename);