{
  "source": "path.markdown",
  "modules": [
    {
      "textRaw": "路径 (Path)",
      "name": "路径_(path)",
      "desc": "<pre><code>稳定度: 3 - 稳定</code></pre>\n<p>This module contains utilities for handling and transforming file\npaths.  Almost all these methods perform only string transformations.\nThe file system is not consulted to check whether paths are valid.\n\n</p>\n<p>本模块包含一套用于处理和转换文件路径的工具集。几乎所有的方法仅对字符串进行转换，\n文件系统是不会检查路径是否真实有效的。\n\n</p>\n<p>Use <code>require(&apos;path&apos;)</code> to use this module.  The following methods are provided:\n\n</p>\n<p>通过 <code>require(&apos;path&apos;)</code> 来加载此模块。以下是本模块所提供的方法：\n\n</p>\n",
      "methods": [
        {
          "textRaw": "path.normalize(p)",
          "type": "method",
          "name": "normalize",
          "desc": "<p>Normalize a string path, taking care of <code>&apos;..&apos;</code> and <code>&apos;.&apos;</code> parts.\n\n</p>\n<p>规范化字符串路径，注意 <code>&apos;..&apos;</code> 和 `&apos;.&apos; 部分\n\n</p>\n<p>When multiple slashes are found, they&apos;re replaced by a single one;\nwhen the path contains a trailing slash, it is preserved.\nOn Windows backslashes are used.\n\n</p>\n<p>当发现有多个连续的斜杠时，会替换成一个；\n当路径末尾包含斜杠时，会保留；\n在 Windows 系统会使用反斜杠。\n\n</p>\n<p>Example:\n\n</p>\n<p>示例：\n\n</p>\n<pre><code>path.normalize(&apos;/foo/bar//baz/asdf/quux/..&apos;)\n// returns\n&apos;/foo/bar/baz/asdf&apos;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "p"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "path.join([path1], [path2], [...])",
          "type": "method",
          "name": "join",
          "desc": "<p>Join all arguments together and normalize the resulting path.\n\n</p>\n<p>组合参数中的所有路径，返回规范化后的路径。\n\n</p>\n<p>Arguments must be strings.  In v0.8, non-string arguments were\nsilently ignored.  In v0.10 and up, an exception is thrown.\n\n</p>\n<p>参数必须是字符串。在 v0.8 版本非字符串参数会被悄悄忽略。\n在 v0.10 及以后版本将会抛出一个异常。\n\n</p>\n<p>Example:\n\n</p>\n<p>示例：\n\n</p>\n<pre><code>path.join(&apos;foo&apos;, {}, &apos;bar&apos;)\n// 抛出异常\nTypeError: Arguments to path.join must be strings</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "path1",
                  "optional": true
                },
                {
                  "name": "path2",
                  "optional": true
                },
                {
                  "name": "...",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "path.resolve([from ...], to)",
          "type": "method",
          "name": "resolve",
          "desc": "<p>Resolves <code>to</code> to an absolute path.\n\n</p>\n<p>将 <code>to</code> 参数解析为一个绝对路径。\n\n</p>\n<p>If <code>to</code> isn&apos;t already absolute <code>from</code> arguments are prepended in right to left\norder, until an absolute path is found. If after using all <code>from</code> paths still\nno absolute path is found, the current working directory is used as well. The\nresulting path is normalized, and trailing slashes are removed unless the path\ngets resolved to the root directory. Non-string arguments are ignored.\n\n</p>\n<p>如果<code>to</code>不是一个相对于<code>from</code> 参数的绝对路径，<code>to</code>会被添加到<code>from</code>的右边，直到找出一个绝对路径为止。如果使用<code>from</code>路径且仍没有找到绝对路径时，使用当时路径作为目录。返回的结果已经规范化，得到的路径会去掉结尾的斜杠，除非得到的当前路径为root目录。非字符串参数将被忽略。\n\n</p>\n<p>Another way to think of it is as a sequence of <code>cd</code> commands in a shell.\n\n</p>\n<p>另一种思考方式就是像在shell里面用一系列的‘cd’命令一样.\n\n</p>\n<pre><code>path.resolve(&apos;foo/bar&apos;, &apos;/tmp/file/&apos;, &apos;..&apos;, &apos;a/../subfile&apos;)</code></pre>\n<p>Is similar to:\n\n</p>\n<p>相当于:\n\n</p>\n<pre><code>cd foo/bar\ncd /tmp/file/\ncd ..\ncd a/../subfile\npwd</code></pre>\n<p>The difference is that the different paths don&apos;t need to exist and may also be\nfiles.\n\n</p>\n<p>不同的是，不同的路径不需要存在的，也可能是文件。\n\n</p>\n<p>Examples:\n\n</p>\n<p>示例:\n\n</p>\n<pre><code>path.resolve(&apos;wwwroot&apos;, &apos;static_files/png/&apos;, &apos;../gif/image.gif&apos;)\n// 如果当前工作目录为 /home/myself/node，它返回：\n&apos;/home/myself/node/wwwroot/static_files/gif/image.gif&apos;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "from ...",
                  "optional": true
                },
                {
                  "name": "to"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "path.isAbsolute(path)",
          "type": "method",
          "name": "isAbsolute",
          "desc": "<p>Determines whether <code>path</code> is an absolute path. An absolute path will always\nresolve to the same location, regardless of the working directory.\n\n</p>\n<p>判定<code>path</code>是否为绝对路径。一个绝对路径总是指向一个相同的位置，无论当前工作目录是在哪里。\n\n</p>\n<p>Posix examples:\n\n</p>\n<p>Posix 示例:\n\n</p>\n<pre><code>path.isAbsolute(&apos;/foo/bar&apos;) // true\npath.isAbsolute(&apos;/baz/..&apos;)  // true\npath.isAbsolute(&apos;qux/&apos;)     // false\npath.isAbsolute(&apos;.&apos;)        // false</code></pre>\n<p>Windows examples:\n\n</p>\n<p>Windows 示例:\n\n</p>\n<pre><code>path.isAbsolute(&apos;//server&apos;)  // true\npath.isAbsolute(&apos;C:/foo/..&apos;) // true\npath.isAbsolute(&apos;bar\\\\baz&apos;)   // false\npath.isAbsolute(&apos;.&apos;)         // false</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "path"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "path.relative(from, to)",
          "type": "method",
          "name": "relative",
          "desc": "<p>Solve the relative path from <code>from</code> to <code>to</code>.\n\n</p>\n<p>解决从<code>from</code>到<code>to</code>的相对路径。\n\n</p>\n<p>At times we have two absolute paths, and we need to derive the relative\npath from one to the other.  This is actually the reverse transform of\n<code>path.resolve</code>, which means we see that:\n\n</p>\n<p>有时我们有2个绝对路径, 我们需要从中找出相对目录的起源目录。这完全是<code>path.resolve</code>的相反实现,我们可以看看是什么意思:\n\n</p>\n<pre><code>path.resolve(from, path.relative(from, to)) == path.resolve(to)</code></pre>\n<p>Examples:\n\n</p>\n<p>示例:\n\n</p>\n<pre><code>path.relative(&apos;/data/orandea/test/aaa&apos;, &apos;/data/orandea/impl/bbb&apos;)\n// 返回\n&apos;../../impl/bbb&apos;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "from"
                },
                {
                  "name": "to"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "path.dirname(p)",
          "type": "method",
          "name": "dirname",
          "desc": "<p>Return the directory name of a path.  Similar to the Unix <code>dirname</code> command.\n\n</p>\n<p>返回路径中文件夹的名称.  类似于Unix的<code>dirname</code> 命令.\n\n</p>\n<p>Example:\n\n</p>\n<p>示例：\n\n</p>\n<pre><code>path.dirname(&apos;/foo/bar/baz/asdf/quux&apos;)\n// returns\n&apos;/foo/bar/baz/asdf&apos;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "p"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "path.basename(p, [ext])",
          "type": "method",
          "name": "basename",
          "desc": "<p>Return the last portion of a path.  Similar to the Unix <code>basename</code> command.\n\n</p>\n<p>返回路径中的最后哦一部分.  类似于Unix 的 <code>basename</code> 命令.\n\n</p>\n<p>Example:\n\n</p>\n<p>示例：\n\n</p>\n<pre><code>path.basename(&apos;/foo/bar/baz/asdf/quux.html&apos;, &apos;.html&apos;)\n// returns\n&apos;quux&apos;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "p"
                },
                {
                  "name": "ext",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "path.extname(p)",
          "type": "method",
          "name": "extname",
          "desc": "<p>Return the extension of the path, from the last &apos;.&apos; to end of string\nin the last portion of the path.  If there is no &apos;.&apos; in the last portion\nof the path or the first character of it is &apos;.&apos;, then it returns\nan empty string.  Examples:\n\n</p>\n<p>返回路径中文件的扩展名, 在从最后一部分中的最后一个&apos;.&apos;到字符串的末尾。\n如果在路径的最后一部分没有&apos;.&apos;，或者第一个字符是&apos;.&apos;，就返回一个\n空字符串。 例子：\n\n</p>\n<pre><code>path.extname(&apos;index&apos;)\n// returns\n&apos;&apos;</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "p"
                }
              ]
            }
          ]
        }
      ],
      "properties": [
        {
          "textRaw": "path.sep",
          "name": "sep",
          "desc": "<p>The platform-specific file separator. <code>&apos;\\\\&apos;</code> or <code>&apos;/&apos;</code>.\n\n</p>\n<p>特定平台的文件分隔工具. <code>&apos;\\\\&apos;</code> 或者 <code>&apos;/&apos;</code>.\n\n</p>\n<p>An example on *nix:\n\n</p>\n<p>*nix 上的例子:\n\n</p>\n<pre><code>&apos;foo/bar/baz&apos;.split(path.sep)\n// returns\n[&apos;foo&apos;, &apos;bar&apos;, &apos;baz&apos;]</code></pre>\n<p>An example on Windows:\n\n</p>\n<p>Windows 上的例子:\n\n</p>\n<pre><code>&apos;foo\\\\bar\\\\baz&apos;.split(path.sep)\n// returns\n[&apos;foo&apos;, &apos;bar&apos;, &apos;baz&apos;]</code></pre>\n"
        },
        {
          "textRaw": "path.delimiter",
          "name": "delimiter",
          "desc": "<p>The platform-specific path delimiter, <code>;</code> or <code>&apos;:&apos;</code>.\n\n</p>\n<p>特定平台的路径分隔符, <code>;</code> 或者 <code>&apos;:&apos;</code>.\n\n</p>\n<p>An example on *nix:\n\n</p>\n<p>*nix 上的例子:\n\n</p>\n<pre><code>process.env.PATH.split(path.delimiter)\n// returns\n[&apos;/usr/bin&apos;, &apos;/bin&apos;, &apos;/usr/sbin&apos;, &apos;/sbin&apos;, &apos;/usr/local/bin&apos;]</code></pre>\n<p>An example on Windows:\n\n</p>\n<p>Windows 上的例子:\n\n</p>\n<pre><code>console.log(process.env.PATH)\n// &apos;C:\\Windows\\system32;C:\\Windows;C:\\Program Files\\nodejs\\&apos;\n\nprocess.env.PATH.split(path.delimiter)\n// returns\n[&apos;C:\\Windows\\system32&apos;, &apos;C:\\Windows&apos;, &apos;C:\\Program Files\\nodejs\\&apos;]\n\n\nprocess.env.PATH.split(path.delimiter)\n// returns\n[&apos;C:\\Windows\\system32&apos;, &apos;C:\\Windows&apos;, &apos;C:\\Program Files\\nodejs\\&apos;]</code></pre>\n"
        }
      ],
      "type": "module",
      "displayName": "路径 (Path)"
    }
  ]
}