2.0.1 • Published 30 days ago

move-unused-path v2.0.1

Weekly downloads
1
License
-
Repository
github
Last release
30 days ago

Move Unused Path

Reliably move to an unused path.

It is basically a wrapper around get-unused-path which doesn't just return an unused path, but also moves to it.

Install

npm install --save move-unused-path

Usage

It accepts the same options object as get-unused-path, plus the following options:

{
  autoDispose?: boolean // Automatically dispose once the operation is completed, enabled by default
}

It also returns the same return value as get-unused-path.

import fs from 'fs';
import moveUnusedPath from 'move-unused-path';

async function example () {

  const sourceFilePath = '/x/y/z/bar.txt';

  const {folderPath, filePath, fileName} = await moveUnusedPath ( sourceFilePath, {
    folderPath: '/x/y/z',
    fileName: 'foo.txt',
    // maxTries: 1000,
    // incrementer: ( name, ext, attempt ) => attempt > 1 ? `${name}-${attempt}${ext}` : `${name}${ext}`
  });

  console.log ( folderPath ); // => '/x/y/z'
  console.log ( filePath ); // => '/x/y/z/foo (3).txt'
  console.log ( fileName ); // => 'foo (3).txt'

  console.log ( fs.existsSync ( sourceFilePath ) ); // => false
  console.log ( fs.existsSync ( filePath ) ); // => true

}

example ();

Related

License

MIT © Fabio Spampinato

2.0.1

30 days ago

2.0.0

1 year ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago