tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
79.49k stars 2.36k forks source link

[feat] `path.relative` API method #10080

Open frankolson opened 2 weeks ago

frankolson commented 2 weeks ago

Describe the problem

I'm working with a couple projects where using the Tauri API to get the relative path between two files would be useful.

Describe the solution you'd like

I would like to update the Tauri commands and JS APIs to export a relative method/function similar to the one provided by the Node.js path module:

import { relative } from '@tauri/api/path';

// POSIX
relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb') == '../../impl/bbb';

// Windows
relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb') == '..\\..\\impl\\bbb';

Alternatives considered

Create a custom Tauri command in each project.

Additional context

Originally discussed in https://github.com/tauri-apps/tauri/discussions/8270, posted by Natejoestev back on November 20, 2023

frankolson commented 2 weeks ago

I'm willing to create a PR for this work, but wanted to submit an issue first per the Pull Request Guidelines in the Tauri Contribution Guide

amrbashir commented 1 week ago

apologies for the late reply @frankolson, feel free to open a PR, thanks