Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extract-path

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-path

Extract a valid fs path from a string

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

extract-path

NPM version Build Status coveralls-image MIT license

Extract a valid fs path from a string.

extract-path is a node library that will attempt to find a possible valid file system path for a given input, validate its existance within the file system and return the matching value upon confirmation.

Table of Contents

About

The main use case for the lib is to be able to take valid path values out of verbose outputs such as those generated by a git status command:

  • modified: src/Router.js resolves to src/Router.js
  • ?? src/utils/__tests__/file.test.js resolves to src/utils/__tests__/file.test.js

This library was primarily put together for usage in iPipeTo which allows for its users to easily extract a path out of a random input value. Some extra effort was made to ensure extract-path works well as a separated lib in the hope that it can be useful for different use cases out there. Feel free to refer to iPipeTo source code as a implementation example if ever needed.

Install

npm install extract-path

Usage

// example.js
const extractPath = require('extract-path');

extractPath('Selected file: ~/Documents/foo.js ...')
	.then(path => {
		console.log(path);
		// ~/Documents/foo.js
	});

API

The API only exposes a single function, that receives a string and returns a Promise which resolves with a single, valid string value or undefined if there was no possible match.

extractPath(str, opts)

  • str string value to be parsed in order to extract a valid fs path
  • opts [optional] object containing the following:
    • validateFileExists boolean wether the module should validate the file exists, defaults to true
    • resolveWithFallback boolean uses a fallback system that matches the entire input if a path couldn't be infered from the input, defaults to true

Credit

extract-path is heavily inspired by the work done in PathPicker parsing algorithm and regular expressions.

iPipeTo - Interactive Pipe To: The missing cli interactive workflow

Contribute

Please do! This is an open source project. If you have a bug or want to discuss something, open an issue.

License

MIT © 2018 Ruy Adorno

Keywords

FAQs

Package last updated on 23 Oct 2019

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