path
v1.9.1A string-based path manipulation library. All of the path operations you know and love, with solid support for Windows, POSIX (Linux and Mac OS X), and the web.
Архив пакета: https://pubdev.letsnova.ru/api/archives/path/1.9.1.tar.gz
dart pub add pathREADME
A comprehensive, cross-platform path manipulation library for Dart.
The path package provides common operations for manipulating paths: joining, splitting, normalizing, etc.
We've tried very hard to make this library do the "right" thing on whatever
platform you run it on, including in the browser. When you use the top-level
functions, it will assume the current platform's path style and work with
that. If you want to explicitly work with paths of a specific style, you can
construct a p.Context for that style.
Using
The path library was designed to be imported with a prefix, though you don't have to if you don't want to:
import 'package:path/path.dart' as p;
The most common way to use the library is through the top-level functions. These manipulate path strings based on your current working directory and the path style (POSIX, Windows, or URLs) of the host platform. For example:
p.join('directory', 'file.txt');
This calls the top-level join() function to join the "directory" and
"file.txt" using the current platform's directory separator.
If you want to work with paths for a specific platform regardless of the underlying platform that the program is running on, you can create a Context and give it an explicit [Style]:
var context = p.Context(style: Style.windows);
context.join('directory', 'file.txt');
This will join "directory" and "file.txt" using the Windows path separator, even when the program is run on a POSIX machine.
Stability
The path package is used by many Dart packages, and as such it strives for a
very high degree of stability. For the same reason, though, releasing a new
major version would probably cause a lot of versioning pain, so some flexibility
is necessary.
We try to guarantee that operations with valid inputs and correct output will
not change. Operations, where one or more inputs are invalid according to the
semantics of the corresponding platform, may produce different outputs over time.
Operations for which path produces incorrect output will also change so that
we can fix bugs.
Also, the path package's URL handling is based on the WHATWG URL spec.
This is a living standard, and some parts of it haven't yet been entirely
solidified by vendor support. The path package reserves the right to change
its URL behavior if the underlying specification changes, although if the change
is big enough to break many valid uses we may elect to treat it as a breaking
change anyway.
FAQ
Where can I use this?
The path package runs on the Dart VM and in the browser under both dart2js and
Dartium. On the browser, window.location.href is used as the current path.
Why doesn't this make paths first-class objects?
When you have path objects, then every API that takes a path has to decide if it accepts strings, path objects, or both.
-
Accepting strings is the most convenient, but then it seems weird to have these path objects that aren't actually accepted by anything that needs a path. Once you've created a path, you have to always call
.toString()on it before you can do anything useful with it. -
Requiring objects forces users to wrap path strings in these objects, which is tedious. It also means coupling that API to whatever library defines this path class. If there are multiple "path" libraries that each define their own path types, then any library that works with paths has to pick which one it uses.
-
Taking both means you can't type your API. That defeats the purpose of having a path type: why have a type if your APIs can't annotate that they expect it?
Given that, we've decided this library should simply treat paths as strings.
How cross-platform is this?
We believe this library handles most of the corner cases of Windows paths (POSIX paths are generally pretty straightforward):
-
It understands that both "/" and "\" are valid path separators, not just "\".
-
It can accurately tell if a path is absolute based on drive-letters or UNC prefix.
-
It understands that "/foo" is not an absolute path on Windows.
-
It knows that "C:\foo\one.txt" and "c:/foo\two.txt" are two files in the same directory.
What is a "path" in the browser?
If you use this package in a browser, then it considers the "platform" to be the browser itself and uses URL strings to represent "browser paths".
История изменений
1.9.1
- Require Dart 3.4
- Move to
dart-lang/coremonorepo.
1.9.0
- Allow percent-encoded colons (
%3a) in drive letters infromUri. - Fixed an issue with the
splitmethod doc comment. - Require Dart 3.0
1.8.3
- Support up to 16 arguments in join function and up to 15 arguments in absolute function.
1.8.2
- Enable the
avoid_dynamic_callslint. - Populate the pubspec
repositoryfield.
1.8.1
- Don't crash when an empty string is passed to
toUri().
1.8.0
- Stable release for null safety.
1.8.0-nullsafety.3
- Update SDK constraints to
>=2.12.0-0 <3.0.0based on beta release guidelines.
1.8.0-nullsafety.2
- Allow prerelease versions of the 2.12 sdk.
1.8.0-nullsafety.1
- Allow 2.10 stable and 2.11.0 dev SDK versions.
1.8.0-nullsafety
- Migrate to null safety.
1.7.0
- Add support for multiple extension in
context.extension().
1.6.4
-
Fixed a number of lints that affect the package health score.
-
Added an example.
1.6.3
- Don't throw a FileSystemException from
currentif the working directory has been deleted, but we have a cached one we can use.
1.6.2
- Set max SDK version to
<3.0.0, and adjust other dependencies.
1.6.1
- Drop the
retypeimplementation for compatibility with the latest SDK.
1.6.0
-
Add a
PathMapclass that uses path equality for its keys. -
Add a
PathSetclass that uses path equality for its contents.
1.5.1
- Fix a number of bugs that occurred when the current working directory was
/on Linux or Mac OS.
1.5.0
- Add a
setExtension()top-level function andContextmethod.
1.4.2
-
Treat
package:URLs as absolute. -
Normalize
c:\foo\.toc:\foo.
1.4.1
- Root-relative URLs like
/fooare now resolved relative to the drive letter forfileURLs that begin with a Windows-style drive letter. This matches the WHATWG URL specification.
- When a root-relative URLs like
/foois converted to a Windows path usingfromUrl(), it is now resolved relative to the drive letter. This matches IE's behavior.
1.4.0
-
Add
equals(),hash()andcanonicalize()top-level functions andContextmethods. These make it easier to treat paths as map keys. -
Properly compare Windows paths case-insensitively.
-
Further improve the performance of
isWithin().
1.3.9
- Further improve the performance of
isWithin()when paths contain/.sequences that aren't/../.
1.3.8
-
Improve the performance of
isWithin()when the paths don't contain asymmetrical.or..components. -
Improve the performance of
relative()whenfromisnulland the path is already relative. -
Improve the performance of
currentwhen the current directory hasn't changed.
1.3.7
- Improve the performance of
absolute()andnormalize().
1.3.6
- Ensure that
path.toUripreserves trailing slashes for relative paths.
1.3.5
- Added type annotations to top-level and static fields.
1.3.4
- Fix dev_compiler warnings.
1.3.3
- Performance improvement in
Context.relative- don't callcurrentiffromis not relative.
1.3.2
- Fix some analyzer hints.
1.3.1
- Add a number of performance improvements.
1.3.0
- Expose a top-level
contextfield that provides access to aContextobject for the current system.
1.2.3
- Don't cache path Context based on cwd, as cwd involves a system-call to compute.
1.2.2
- Remove the documentation link from the pubspec so this is linked to pub.dev by default.
1.2.1
-
Many members on
Stylethat provided access to patterns and functions used internally for parsing paths have been deprecated. -
Manually parse paths (rather than using RegExps to do so) for better performance.
1.2.0
- Added
path.prettyUri, which produces a human-readable representation of a URI.
1.1.0
path.fromUrinow accepts strings as well asUriobjects.
