feat: Enhance APIs with file URL path support #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request brings new features, enhance the functionality APIs, improve documentation, and ensure compatibility across different environments.
Notable Changes
url.fileURLToPath
function but with added support for relative paths. It throws anURIError
for non-file
protocols or invalid path structures. This function will be utilized inls*
functions to support file URL paths.ls*
functions. Now, these functions can accept string URL paths or URL objects with the'file:'
protocol. However, please note that only the'file:'
protocol is currently supported for directory resolution and listing.fs.readdir
adheres to the required format.node:assert
module to enhance test coverage.URL
objects with the'file:'
protocol. Also, tests have been added to verify that anURIError
is correctly thrown when unsupported protocols are used.Description
New Features
This pull request brings a new feature to all
ls*
functions, that is a support to file URL path fordirpath
parameter. It accepts both a string URL path or aURL
object by following the'file:'
protocol, utilizing an internal function calledfileUrlToPath
to convert the file URLs."Why don't use the inbuilt function provided by Node.js itself?" Well, this function might behave the same with
url.fileURLToPath
function fromnode:url
module, but this function are supports relative paths. Unlikeurl.fileURLToPath
inbuilt function that doesn't accepts a string URL with relative path, attempting to do so will causing an error.Here's some examples on how to use the new feature:
This new feature has been tested and the tests code are available in the project. If having any issues while using the feature, report to us by providing the issue details.
Test Environments
Introduced new test cases to ensure that the APIs correctly handle file URL paths and
URL
objects with the'file:'
protocol and also ensured that the APIs throws aURIError
when provided with URL paths using unsupported protocols.Documentation
Added a history section to document changes made to the APIs in each version and improved the documentation for the APIs.