阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js url.pathToFileURL

      Node.js url.pathToFileURL(path)

      新增于: v10.12.0

      • path < string> The path to convert to a File URL.
      • Returns: < URL> The file URL object.

      This function ensures that path is resolved absolutely, and that the URL control characters are correctly encoded when converting into a File URL.

      new URL(__filename);                // Incorrect: throws (POSIX)
      new URL(__filename);                // Incorrect: C:\... (Windows)
      pathToFileURL(__filename);          // Correct:   file:///... (POSIX)
      pathToFileURL(__filename);          // Correct:   file:///C:/... (Windows)
      
      new URL('/foo#1', 'file:');         // Incorrect: file:///foo#1
      pathToFileURL('/foo#1');            // Correct:   file:///foo%231 (POSIX)
      
      new URL('/some/path%.js', 'file:'); // Incorrect: file:///some/path%
      pathToFileURL('/some/path%.js');    // Correct:   file:///some/path%25 (POSIX)
      

      更多内容请参考:Node.js URL,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录