Socket
Socket
Sign inDemoInstall

unused-filename

Package Overview
Dependencies
2
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.0.1

51

index.d.ts

@@ -1,3 +0,1 @@

/* eslint-disable no-redeclare */
declare namespace unusedFilename {

@@ -53,3 +51,3 @@ interface Options {

*/
type Incrementer = (filename: string, extension: string) => string;
type Incrementer = (filename: string, extension: string) => [string, string];

@@ -78,17 +76,20 @@ /**

*/
/* eslint-disable @typescript-eslint/no-misused-new */
interface MaxTryError extends Error {
originalPath: string;
lastTriedPath: string;
new (originalPath: string, lastTriedPath: string): MaxTryError;
}
/* eslint-enable @typescript-eslint/no-misused-new */
}
/* eslint-disable no-redeclare */
declare const unusedFilename: {
/**
Creates an incrementer that appends a number after a separator.
Get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.
`separatorIncrementer('_')` will increment `file.txt` → `file_1.txt`.
@param filePath - The path to check for filename collision.
@returns Either the original `filename` or the `filename` appended with a number (or modified by `option.incrementer` if specified).
Not all characters can be used as separators:
- On Unix-like systems, `/` is reserved.
- On Windows, `<>:"/|?*` along with trailing periods are reserved.
If an already incremented `filePath` is passed, `unusedFilename` will simply increment and replace the already existing index:

@@ -99,7 +100,9 @@ @example

console.log(await unusedFilename('rainbow.txt', {incrementer: unusedFilename.separatorIncrementer('_')}));
//=> 'rainbow_1.txt'
(async () => {
console.log(await unusedFilename('rainbow (1).txt'));
//=> 'rainbow (2).txt'
})();
```
*/
separatorIncrementer: (separator: string) => unusedFilename.Incrementer;
(filePath: string, options?: unusedFilename.Options): Promise<string>;

@@ -112,3 +115,3 @@ MaxTryError: unusedFilename.MaxTryError;

/**
Get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.
Synchronously get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.

@@ -124,17 +127,16 @@ @param filePath - The path to check for filename collision.

(async () => {
console.log(await unusedFilename('rainbow (1).txt'));
//=> 'rainbow (2).txt'
})();
console.log(unusedFilename.sync('rainbow (1).txt'));
//=> 'rainbow (2).txt'
```
*/
(filePath: string, options?: unusedFilename.Options): Promise<string>;
sync(filePath: string, options?: unusedFilename.Options): string;
/**
Synchronously get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.
Creates an incrementer that appends a number after a separator.
@param filePath - The path to check for filename collision.
@returns Either the original `filename` or the `filename` appended with a number (or modified by `option.incrementer` if specified).
`separatorIncrementer('_')` will increment `file.txt` → `file_1.txt`.
If an already incremented `filePath` is passed, `unusedFilename` will simply increment and replace the already existing index:
Not all characters can be used as separators:
- On Unix-like systems, `/` is reserved.
- On Windows, `<>:"/|?*` along with trailing periods are reserved.

@@ -145,9 +147,10 @@ @example

console.log(unusedFilename.sync('rainbow (1).txt'));
//=> 'rainbow (2).txt'
console.log(await unusedFilename('rainbow.txt', {incrementer: unusedFilename.separatorIncrementer('_')}));
//=> 'rainbow_1.txt'
```
*/
sync(filePath: string, options?: unusedFilename.Options): string;
separatorIncrementer(separator: string): unusedFilename.Incrementer;
};
/* eslint-enable no-redeclare */
export = unusedFilename;

@@ -27,3 +27,3 @@ 'use strict';

let {filename, index} = match ? match.groups : {filename: inputFilename, index: 0};
return [`${filename}${extension}`, `${filename.trim()}_${++index}${extension}`];
return [`${filename}${extension}`, `${filename.trim()}${separator}${++index}${extension}`];
};

@@ -30,0 +30,0 @@ };

{
"name": "unused-filename",
"version": "3.0.0",
"version": "3.0.1",
"description": "Get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`",

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc