Socket
Socket
Sign inDemoInstall

relative-import-path

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    relative-import-path

path.relative for generating short require'able paths.


Version published
Maintainers
1
Install size
10.5 kB
Created

Readme

Source


relative-import-path
Styled with prettier Build status Code Coverage NPM version Downloads

Like path.relative, but for generating short require'able paths.

  • Removes unnecessary node_modules from resolved relative paths.
  • Automatically converts windows style paths to POSIX.

Installation

npm install relative-import-path

API

/**
 * Given two absolute file paths, resolves a short require'able relative path.
 */
function resolveRelativePath(from: string, to: string): string;

Examples

import { relativeImportPath } from "relative-import-path";

relativeImportPath("/a/b", "/c/d"); // /c/d
relativeImportPath("/a/a", "/a/b"); // ./b
relativeImportPath("/a/a/a", "/a/b/a"); // ../b/a
relativeImportPath("/a/node_modules/a/a", "/a/node_modules/b/a"); // b/a
relativeImportPath("/a/node_modules/a/a", "/a/node_modules/a/b"); // ./b
relativeImportPath("/a/a", "/node_modules/b"); // b
relativeImportPath("/a/a", "/a/node_modules/b"); // b
relativeImportPath("/a/b/c", "/a/node_modules/b"); // b
relativeImportPath("/a/a", "/b/node_modules/b"); // /b/node_modules/b
relativeImportPath("/a/b/c", "/b/node_modules/b"); // /b/node_modules/b
relativeImportPath("/a/a", "/a/b/node_modules/b"); // ./b/node_modules/b
relativeImportPath("/a/node_modules/@a/a/a", "/a/node_modules/@a/b/a"); // @a/b/a
relativeImportPath("/a/node_modules/@a/a/a", "/a/node_modules/@a/a/b"); // ./b

Code of Conduct

This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.

Keywords

FAQs

Last updated on 11 Mar 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc