Skip to content

A tiny yet powerfull collection of utils for processing filenames compareable to Apaches FilenameUtils for Java

Notifications You must be signed in to change notification settings

ditschedev/filename-utils

Repository files navigation

filename-utils

A tiny module written in TypeScript to help you with your filenames. A JavaScript version of the Apache FilenameUtils class.

build npm version npm downloads dependencies License

Installation

To install the module, use your preferred package manager.

yarn add filename-utils

or use npm

npm install filename-utils

Usage

First you need to import the functions you need from filename-utils.

import { getExtension, getBaseName } from 'filename-utils';

After that you can use the functions as you'd like!.

getExtension(filename: string): string

Fetches the extension of a filename. Will return an empty string, if no filename can be resolved. Examples:

getExtension('image.png'); // returns => "png"
getExtension('image.test.jpeg'); // returns => "jpeg"
getExtension('shellscript'); // returns => ""
getExtension('.htaccess'); // returns => ""

getBaseName(filename: string): string

Strips the extension off the filename and returns the base name.

getBaseName('image.png'); // returns => "image"
getBaseName('image.test.jpeg'); // returns => "image.test"
getBaseName('file'); // returns => "file"
getBaseName('.env'); // returns => ""

About

A tiny yet powerfull collection of utils for processing filenames compareable to Apaches FilenameUtils for Java

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published