JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q17865F
  • License MIT

Reliably move to an unused path.

Package Exports

  • move-unused-path

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (move-unused-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

Features

  • It reliably retrieves an unused path via get-unused-path.
  • It attempts to move to it, re-trying in case of failure.

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 * as 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 ();

License

MIT © Fabio Spampinato