New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

base-path-converter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-path-converter

Convert file paths to start with their base directory

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.4K
decreased by-10.12%
Maintainers
1
Weekly downloads
 
Created
Source

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.

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.

Keywords

FAQs

Package last updated on 28 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc