Socket
Socket
Sign inDemoInstall

discover-path

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discover-path

Check for the existence of a path in a case-sensitive manner and, if not found, suggest where it might be at


Version published
Weekly downloads
1.3K
decreased by-32.53%
Maintainers
1
Weekly downloads
 
Created
Source

discover-path

npm versionBuild Status

Check for the existence of a path in a case-sensitive manner and, if not found, suggest where it might be at.

Note that this is a slow operation (recursively listing directory contents), and should only be used in cases where that's fine (CLI tools in the case of errors, for instance).

Installing

$ npm install discover-path

Usage

import {discoverPathSync} from 'discover-path'

const expectedPath = '/Users/Rexxars/webdev/discover-Path'
const actualPath = discoverPathSync(expectedPath)

// If a "direct" match is found (1:1, or on case-changes with only one option:)
console.log(actualPath) // /Users/rexxars/webdev/discover-path
  • If a 1:1 match can be found (or, if changing the casing of paths, only one option is found), the actual, "fixed" (case-sensitive) path is returned.
  • If no direct matches was found, or its unclear which alternative to use, it will throw an error. The error object contains a list of suggestions if any can be found. This array of options can also be found on the suggestions property on the error.
import {discoverPathSync} from 'discover-path'

try {
  const expectedPath = '/Users/rexxars/webdev/Discover-Path'
  const actualPath = discoverPathSync(expectedPath)
} catch (err) {
  console.log(err.code) // 'ENOENT'
  console.log(err.path) // '/Users/rexxars/webdev/Discover-Path'
  console.log(err.suggestions)
  /*
  [
    '/Users/rexxars/webdev/discover-path',
    '/Users/rexxars/webdev/discover-Path'
  ]
  */

  console.log(err.message)
  /*
  Cannot find path '/Users/Rexxars/webdev/Discover-Path'

  Did you mean:
    - /Users/rexxars/webdev/discover-path
    - /Users/rexxars/webdev/discover-Path
  */
}

License

MIT © Espen Hovlandsdal

Keywords

FAQs

Package last updated on 01 Feb 2021

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