OLD | NEW |
1 A comprehensive, cross-platform path manipulation library for Dart. | 1 A comprehensive, cross-platform path manipulation library for Dart. |
2 | 2 |
3 The path package provides common operations for manipulating paths: | 3 The path package provides common operations for manipulating paths: |
4 joining, splitting, normalizing, etc. | 4 joining, splitting, normalizing, etc. |
5 | 5 |
6 We've tried very hard to make this library do the "right" thing on whatever | 6 We've tried very hard to make this library do the "right" thing on whatever |
7 platform you run it on, including in the browser. When you use the top-level | 7 platform you run it on, including in the browser. When you use the top-level |
8 functions, it will assume the current platform's path style and work with | 8 functions, it will assume the current platform's path style and work with |
9 that. If you want to explicitly work with paths of a specific style, you can | 9 that. If you want to explicitly work with paths of a specific style, you can |
10 construct a `path.Builder` for that style. | 10 construct a `path.Context` for that style. |
11 | 11 |
12 ## Using | 12 ## Using |
13 | 13 |
14 The path library was designed to be imported with a prefix, though you don't | 14 The path library was designed to be imported with a prefix, though you don't |
15 have to if you don't want to: | 15 have to if you don't want to: |
16 | 16 |
17 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
18 | 18 |
19 The most common way to use the library is through the top-level functions. | 19 The most common way to use the library is through the top-level functions. |
20 These manipulate path strings based on your current working directory and | 20 These manipulate path strings based on your current working directory and |
21 the path style (POSIX, Windows, or URLs) of the host platform. For example: | 21 the path style (POSIX, Windows, or URLs) of the host platform. For example: |
22 | 22 |
23 path.join("directory", "file.txt"); | 23 path.join("directory", "file.txt"); |
24 | 24 |
25 This calls the top-level [join] function to join "directory" and | 25 This calls the top-level [join] function to join "directory" and |
26 "file.txt" using the current platform's directory separator. | 26 "file.txt" using the current platform's directory separator. |
27 | 27 |
28 If you want to work with paths for a specific platform regardless of the | 28 If you want to work with paths for a specific platform regardless of the |
29 underlying platform that the program is running on, you can create a | 29 underlying platform that the program is running on, you can create a |
30 [Builder] and give it an explicit [Style]: | 30 [Context] and give it an explicit [Style]: |
31 | 31 |
32 var builder = new path.Builder(style: Style.windows); | 32 var context = new path.Context(style: Style.windows); |
33 builder.join("directory", "file.txt"); | 33 context.join("directory", "file.txt"); |
34 | 34 |
35 This will join "directory" and "file.txt" using the Windows path separator, | 35 This will join "directory" and "file.txt" using the Windows path separator, |
36 even when the program is run on a POSIX machine. | 36 even when the program is run on a POSIX machine. |
37 | 37 |
38 ## FAQ | 38 ## FAQ |
39 | 39 |
40 ### Where can I use this? | 40 ### Where can I use this? |
41 | 41 |
42 Pathos runs on the Dart VM and in the browser under both dart2js and Dartium. | 42 Pathos runs on the Dart VM and in the browser under both dart2js and Dartium. |
43 Under dart2js, it currently returns "." as the current working directory, while | 43 Under dart2js, it currently returns "." as the current working directory, while |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 * It understands that "/foo" is not an absolute path on Windows. | 79 * It understands that "/foo" is not an absolute path on Windows. |
80 | 80 |
81 * It knows that "C:\foo\one.txt" and "c:/foo\two.txt" are two files in the | 81 * It knows that "C:\foo\one.txt" and "c:/foo\two.txt" are two files in the |
82 same directory. | 82 same directory. |
83 | 83 |
84 ### What is a "path" in the browser? | 84 ### What is a "path" in the browser? |
85 | 85 |
86 If you use this package in a browser, then it considers the "platform" to be | 86 If you use this package in a browser, then it considers the "platform" to be |
87 the browser itself and uses URL strings to represent "browser paths". | 87 the browser itself and uses URL strings to represent "browser paths". |
OLD | NEW |