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