1.1.2 • Published 1 year ago

duplicate-filename-resolver v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

duplicate-filename-resolver

npm version NPM Downloads

This package matches a file name of type string against an Array of objects of type IFile and return a unique file name of type string.

See it in action ⚡️

Changelog

Learn about the latest improvements.

Install

npm i duplicate-filename-resolver --save

Exports

  • IFile - Represents an Object containing file name of type string and the file object of type File.
{
   name: string;
   file: File;
}
  • getUniqueFileName(allFiles: IFile[], newFileName: string) - Iterates through passed array allFiles of type IFile[] matching passed newFileName of type string. If duplicate is found, return a new unique file name. Else, returns same name.

Usage

Import the package.

import { getUniqueFileName, IFile } from "duplicate-filename-resolver";

Declare a variable allFiles of type IFile.

var allFiles: IFile[] = [{
  name: "file.txt"
}];

allFiles is a array of type IFile[].

Call method getUniqueFileName(allFiles: IFile[], newFileName: string) and pass alFiles array and a string file name.

var fileName string = getUniqueFileName(this.allFiles, "file.txt");

Output - "file (1).txt"

Examples

-

var allFiles: IFile[] = [{
  name: "file (1).txt"
}];
var fileName string = getUniqueFileName(this.allFiles, "file (1).txt");

Output - "file (2).txt"

-

var allFiles: IFile[] = [{
  name: "file (1).txt"
}];
var fileName string = getUniqueFileName(this.allFiles, "file(1).txt");

Output - "file(1).txt"

-

var allFiles: IFile[] = [{
  name: "file(1).txt"
}];
var fileName string = getUniqueFileName(this.allFiles, "file(1).txt");

Output - "file(1) (1).txt"

-

var allFiles: IFile[] = [{
  name: "file.(1).txt"
}];
var fileName string = getUniqueFileName(this.allFiles, "file.(1).txt");

Output - "file.(1) (1).txt"

-

var allFiles: IFile[] = [{
  name: "file (1)(2).txt"
}];
var fileName string = getUniqueFileName(this.allFiles, "file (1)(2).txt");

Output - "file (1)(2) (1).txt"

1.1.1

1 year ago

1.1.0

1 year ago

1.1.2

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago