File Name Formatter
Description
File Name Formatter is a custom formatter util designed for formatting a given file name for easier retrieval and readability.
Integration and Usage
To use fileNameFormatter util, you need to import the formatDisplayFileName function from the fileNameFormatter file into your project
import { formatDisplayFileName } from './path/to/utils/fileNameFormatter';
and call the function with a string object and a specified format.
const displayedFileNameString = formatDisplayFileName(
fileName,
displayFormat,
displayFormatFunction //optional
);
FormatDisplayFileName Function
export function formatDisplayFileName(
name: string,
format: string,
formatter?: (name: string) => string
)
Parameters
name:string- name of the file that needs to be formatted
format:string- specifies the output style
formatter:(date: Date) => string(optional)- function that customizes the output format of a
stringobject
- function that customizes the output format of a
Returns
Returns a date string formatted according to the chosen format for displaying file names.
Formats
Displayed File Name Formats
custom- custom file name format defined by the user
pascalcapitalizesall words including the first word andremoves the spacein between them
camelcapitalizesall words except the first word andremoves the spacein between them
snake- combines words by replacing the space with an
underscore (_)
- combines words by replacing the space with an
kebab- combines words by replacing the space with a
dash (-)
- combines words by replacing the space with a
title- each word starts with an
uppercaseletter and isseparatedby spaces
- each word starts with an
upperuppercasesall charactersremoving spaces or separators
lowerlowercasesall charactersremoving spaces or separators
dot- combines words by replacing space with a
dot (.)andlowercasesall characters
- combines words by replacing space with a
sentencecapizalizesonly the first word and replaces all symbols withspace, making the name look like a regular sentence
Events
This util does not have any events.