Generates a unique string by adding or incrementing a numeric suffix to the given name.
npm install string-incrementA simple utility class that generates unique string names by appending or incrementing a numeric suffix.
- Handles names with or without existing numeric suffixes.
- Lightweight and easy to integrate.
```
npm i string-increment
`
//Name increment
const { stringincrement } = require('string-increment');
or
import { stringincrement } from 'string-increment';
//File helper
const { filehelper } = require('string-increment');
or
import { filehelper } from 'string-increment';
`
Returns a unique string by comparing the base name against an existing list of names.
#### Params
- name - The full name of the file/string
- names - A one-dimensional array of existing filenames/strings (name only, no path).
#### Example
`
const filename = "file.pdf";
const files = ["file1.pdf", "file2.pdf", "file.pdf"];
const uniqueName = stringincrement.get(filename, files);
console.log(uniqueName); // Outputs: "file (1).pdf"
`
Splits the given filename into two parts: the name and its file extension.
#### Params
- filename - The full name of the file.
#### Example
`
const filename = "file.name.pdf";
const basenameAndExt = filehelper.splitByFileExtension(filename);
console.log(basenameAndExt); // Outputs: ["file.name", "pdf"]
`
Extracts and returns the file extension from a given filename.
#### Params
- filename - The full name of the file.
- returns - File extension and its index. If file has no extension then it will return -1 as index value.
#### Example
`
const filename = "file-hello_world.pdf";
const fileExtension = stringincrement.getFileExtension(filename);
console.log(fileExtension); // Outputs: ["pdf", 17];
``