|
1 | 1 | module Node.Path where
|
2 | 2 |
|
3 |
| --- | |
4 |
| --- Type for strings representing file paths. |
5 |
| --- |
| 3 | +-- | Type for strings representing file paths. |
6 | 4 | type FilePath = String
|
7 | 5 |
|
8 |
| --- | |
9 |
| --- Normalize a string path, taking care of `..` and `.`, duplicated slashes, |
10 |
| --- etc. If the path contains a trailing slash it is preserved. On Windows |
11 |
| --- backslashes are used. |
12 |
| --- |
| 6 | +-- | Normalize a string path, taking care of `..` and `.`, duplicated slashes, |
| 7 | +-- | etc. If the path contains a trailing slash it is preserved. On Windows |
| 8 | +-- | backslashes are used. |
13 | 9 | foreign import normalize
|
14 | 10 | "var normalize = require('path').normalize;" :: FilePath -> FilePath
|
15 | 11 |
|
16 |
| --- | |
17 |
| --- Joins two path segments together and normalizes the resulting path. |
18 |
| --- |
19 |
| -foreign import join |
20 |
| - "var join = function (segments) { \ |
| 12 | +-- | Concatenates multiple path segments together and normalizes the resulting path. |
| 13 | +foreign import concat |
| 14 | + "var concat = function (segments) { \ |
21 | 15 | \ return require('path').join.apply(this, segments); \
|
22 | 16 | \}" :: [FilePath] -> FilePath
|
23 | 17 |
|
24 |
| --- | |
25 |
| --- Resolves `to` to an absolute path ([from...], to). |
26 |
| --- |
| 18 | +-- | Resolves `to` to an absolute path ([from...], to). |
27 | 19 | foreign import resolve
|
28 | 20 | "var resolve = function (from) { \
|
29 | 21 | \ return function (to) { \
|
30 | 22 | \ return require('path').resolve.apply(this, from.concat([to])); \
|
31 | 23 | \ }; \
|
32 | 24 | \};" :: [FilePath] -> FilePath -> FilePath
|
33 | 25 |
|
34 |
| --- | |
35 |
| --- Solve the relative path from `from` to `to`. |
36 |
| --- |
| 26 | +-- | Solve the relative path from `from` to `to`. |
37 | 27 | foreign import relative
|
38 | 28 | "var relative = function (from) { \
|
39 | 29 | \ return function (to) { \
|
40 | 30 | \ return require('path').relative(from, to); \
|
41 | 31 | \ }; \
|
42 | 32 | \}" :: FilePath -> FilePath -> FilePath
|
43 | 33 |
|
44 |
| --- | |
45 |
| --- Return the directory name of a path. |
46 |
| --- |
| 34 | +-- | Return the directory name of a path. |
47 | 35 | foreign import dirname
|
48 | 36 | "var dirname = function (path) { \
|
49 | 37 | \ var p = require('path'); \
|
50 | 38 | \ return p.normalize(p.dirname(path)); \
|
51 | 39 | \}" :: FilePath -> FilePath
|
52 | 40 |
|
53 |
| --- | |
54 |
| --- Return the last portion of a path. |
55 |
| --- |
| 41 | +-- | Return the last portion of a path. |
56 | 42 | foreign import basename
|
57 | 43 | "var basename = require('path').basename;" :: FilePath -> FilePath
|
58 | 44 |
|
59 |
| --- | |
60 |
| --- Return the last portion of a path, also dropping a specific file extension |
61 |
| --- if it matches the end of the name. |
62 |
| --- |
| 45 | +-- | Return the last portion of a path, also dropping a specific file extension |
| 46 | +-- | if it matches the end of the name. |
63 | 47 | foreign import basenameWithoutExt
|
64 | 48 | "var basenameWithoutExt = function (path) { \
|
65 | 49 | \ return function (ext) { \
|
66 | 50 | \ return require('path').basename(path, ext); \
|
67 | 51 | \ }; \
|
68 | 52 | \}" :: FilePath -> FilePath -> FilePath
|
69 | 53 |
|
70 |
| --- | |
71 |
| --- Return the extension of the path, from the last `.` to end of string in the |
72 |
| --- last portion of the path. If there is no `.` in the last portion of the path |
73 |
| --- or the first character of it is `.`, then it returns an empty string. |
74 |
| --- |
| 54 | +-- | Return the extension of the path, from the last `.` to end of string in the |
| 55 | +-- | last portion of the path. If there is no `.` in the last portion of the |
| 56 | +-- | path or the first character of it is `.`, then it returns an empty string. |
75 | 57 | foreign import extname
|
76 | 58 | "var extname = require('path').extname;" :: FilePath -> FilePath
|
77 | 59 |
|
78 |
| --- | |
79 |
| --- The platform-specific file separator. `\\` or `/`. |
80 |
| --- |
| 60 | +-- | The platform-specific file separator. `\\` or `/`. |
81 | 61 | foreign import sep
|
82 | 62 | "var sep = require('path').sep;" :: String
|
83 | 63 |
|
84 |
| --- | |
85 |
| --- The platform-specific path delimiter, `;` or `:`. |
86 |
| --- |
| 64 | +-- | The platform-specific path delimiter, `;` or `:`. |
87 | 65 | foreign import delimiter
|
88 | 66 | "var delimiter = require('path').delimiter;" :: String
|
0 commit comments