feat(api): Expand APIs with new customizable options and enhanced functionality #6
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.
Overview
This pull request introduces several enhancements and additions to the LSFND package, focusing on enhancing APIs usage by introducing some additional options, and refining type declarations to more robust and compatible with these changes and future changes.
Notable Changes
absolute
,rootDir
, andbasename
option toLsOptions
(i.e., theoptions
parameter ofls*
functions).LsOptions
, this is publicly visible.Details
APIs Enhancements
absolute
: Determines whether to return absolute paths for all entries.basename
: Controls whether returned entries include only file and/or directory names.rootDir
: Specifies the root directory to resolve relative paths.Note
These options have priority tiers, with the highest priority being at the top of the list. For example, if both
rootDir
andabsolute
are specified,absolute
takes precedence.The
basename
option implicitly includes any directories on the returned entries. If you want to only include the filenames, then combine this option withlsTypes.LS_F
type if you are usingls
function, or use this option withlsFiles
function for better flexibility.Warning
THIS MIGHT BREAKING CHANGES!
In previous release (prior to version 0.1.0) you can literally use an explicit method that makes the returned results as absolute paths entirely. That is by utilizing the
path.resolve
function, here is an example:In the above code, the directory path is resolved to an absolute path before being passed to the
lsFiles
function. As a result, the function treats the specified directory path as a relative path and does not attempt to resolve it back to a relative path, thus returning absolute paths. This approach was considered unstable and problematic due to inconsistencies in the internal logic.Therefore, the
absolute
option was introduced as a replacement and will default returns relative paths when this option are disabled (set tofalse
or unspecified), they will relative to the path specified in therootDir
option.Added support for file URLs in the
rootDir
option. Note that only URLs with the'file:'
protocol are supported, and attempting to use other protocols will result in an error. This option uses the same logic resolution as thedirpath
parameter, which you can pass a relative path of file URL string like this:Enhanced the resolution of the
options
parameter by defining a new internal function calledresolveOptions
. This improves flexibility and reduces code duplication while ensuring type strictness.Introduced the
defaultLsOptions
constant object, containing all default options forls*
functions.Types Declaration
StringPath
representing a path from a string.LsOptionsInterface
,LsTypesValues
,ResolvedLsOptions
, andDefaultLsOptions
.Documentation
defaultLsOptions
object and theresolveOptions
internal function.Summary
These changes significantly enhance the LSFND package by introducing new API options, improving options handling and documentation, and refining type declarations. These enhancements contribute to better usability, flexibility, and correctness of the package.