https://github.com/marko-js/relative-import-path
Like path.relative for generating short require'able paths.
https://github.com/marko-js/relative-import-path
Last synced: about 2 months ago
JSON representation
Like path.relative for generating short require'able paths.
- Host: GitHub
- URL: https://github.com/marko-js/relative-import-path
- Owner: marko-js
- License: mit
- Created: 2022-03-11T18:13:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-11T19:36:56.000Z (over 3 years ago)
- Last Synced: 2024-10-12T21:51:48.489Z (8 months ago)
- Language: TypeScript
- Size: 141 KB
- Stars: 1
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
relative-import-path
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
```console
npm install relative-import-path
```# API
```ts
/**
* Given two absolute file paths, resolves a short require'able relative path.
*/
function resolveRelativePath(from: string, to: string): string;
```# Examples
```javascript
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](./.github/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.