# base-path-converter

> Convert file paths to start with their base directory

Latest version **1.0.2** (published 2020-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install base-path-converter
pnpm add base-path-converter
yarn add base-path-converter
bun add base-path-converter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-02-28 |
| First published | 2019-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matt Ober |
| Maintainers | mattober |
| Keywords | base, directory, converter, filepath |

## Links

- npm: https://www.npmjs.com/package/base-path-converter
- Repository: https://github.com/obo20/baseDirectoryPathConverter
- Issues: https://github.com/obo20/baseDirectoryPathConverter/issues
- npm.io page: https://npm.io/package/base-path-converter

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-02-28
- 1.0.1 — 2019-06-25
- 1.0.0 — 2019-05-24

## README

# Base Directory Path Converter

This package converts file paths to starting from a desired "base" directory.

For example:

If the sourcePath is `parentDirectory/childDirectory/sourceDirectory` 

and the provided filePath is `parentDirectory/childDirectory/sourceDirectory/example/test.file`

then the returned filepath will be `sourceDirectory/example/test.file`


## Installation

```
npm install --save base-path-converter
```

## Usage

##### Params
* `sourcePath` - The path for the original "base" directory being read from
* `filePath` - A filepath that for a file that was read from that source directory

#### Response
A trimmed version of the filepath that starts from the "base" directory

##### Example Code
Here's an example of the package being utilized to prepare a form-data object to be send to an API.

In this example, we want to overwrite the filepath we're sending for each file, as we don't want the API receiving the file to care about the "base" folder's parents.

```javascript
const recursive = require('recursive-fs');
const FormData = require('form-data');
const basePathConverter = require('base-path-converter');

const src = './../builds/React-Builds/myBuild/'
recursive.readdirr(src, function (err, dirs, files) {
    const body = new FormData();
    files.forEach((file) => {
        const filepath = path.normalize(file);
        body.append(`file`, fs.createReadStream(file), {
            filepath: basePathConverter(src, file)
        })
    });
});
```

####Special Handling of `./`
If the sourcePath is passed in and begins with `./`, then the `./` will be trimmed from the beginning of it before the sourcePath is processed.

---
_Source: https://npm.io/package/base-path-converter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
