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
string
object
- 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
pascal
capitalizes
all words including the first word andremoves the space
in between them
camel
capitalizes
all words except the first word andremoves the space
in 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
uppercase
letter and isseparated
by spaces
- each word starts with an
upper
uppercases
all charactersremoving spaces or separators
lower
lowercases
all charactersremoving spaces or separators
dot
- combines words by replacing space with a
dot (.)
andlowercases
all characters
- combines words by replacing space with a
sentence
capizalizes
only the first word and replaces all symbols withspace
, making the name look like a regular sentence
Events
This util does not have any events.