pax_global_header00006660000000000000000000000064131275303550014516gustar00rootroot0000000000000052 comment=db012b4db2c9da9f6eeb5202b4a493450482e0e4 file-uri-to-path-1.0.0/000077500000000000000000000000001312753035500146025ustar00rootroot00000000000000file-uri-to-path-1.0.0/.gitignore000066400000000000000000000000161312753035500165670ustar00rootroot00000000000000/node_modules file-uri-to-path-1.0.0/.travis.yml000066400000000000000000000007301312753035500167130ustar00rootroot00000000000000sudo: false language: node_js node_js: - "0.8" - "0.10" - "0.12" - "1" - "2" - "3" - "4" - "5" - "6" - "7" - "8" install: - PATH="`npm bin`:`npm bin -g`:$PATH" # Node 0.8 comes with a too obsolete npm - if [[ "`node --version`" =~ ^v0\.8\. ]]; then npm install -g npm@1.4.28 ; fi # Install dependencies and build - npm install script: # Output useful info for debugging - node --version - npm --version # Run tests - npm test file-uri-to-path-1.0.0/History.md000066400000000000000000000006611312753035500165700ustar00rootroot00000000000000 1.0.0 / 2017-07-06 ================== * update "mocha" to v3 * fixed unicode URI decoding (#6) * add typings for Typescript * README: use SVG Travis-CI badge * add LICENSE file (MIT) * add .travis.yml file (testing Node.js 0.8 through 8 currently) * add README.md file 0.0.2 / 2014-01-27 ================== * index: invert the path separators on Windows 0.0.1 / 2014-01-27 ================== * initial commit file-uri-to-path-1.0.0/LICENSE000066400000000000000000000020731312753035500156110ustar00rootroot00000000000000Copyright (c) 2014 Nathan Rajlich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. file-uri-to-path-1.0.0/README.md000066400000000000000000000040311312753035500160570ustar00rootroot00000000000000file-uri-to-path ================ ### Convert a `file:` URI to a file path [![Build Status](https://travis-ci.org/TooTallNate/file-uri-to-path.svg?branch=master)](https://travis-ci.org/TooTallNate/file-uri-to-path) Accepts a `file:` URI and returns a regular file path suitable for use with the `fs` module functions. Installation ------------ Install with `npm`: ``` bash $ npm install file-uri-to-path ``` Example ------- ``` js var uri2path = require('file-uri-to-path'); uri2path('file://localhost/c|/WINDOWS/clock.avi'); // "c:\\WINDOWS\\clock.avi" uri2path('file:///c|/WINDOWS/clock.avi'); // "c:\\WINDOWS\\clock.avi" uri2path('file://localhost/c:/WINDOWS/clock.avi'); // "c:\\WINDOWS\\clock.avi" uri2path('file://hostname/path/to/the%20file.txt'); // "\\\\hostname\\path\\to\\the file.txt" uri2path('file:///c:/path/to/the%20file.txt'); // "c:\\path\\to\\the file.txt" ``` API --- ### fileUriToPath(String uri) → String License ------- (The MIT License) Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. file-uri-to-path-1.0.0/index.d.ts000066400000000000000000000001151312753035500165000ustar00rootroot00000000000000declare function fileUriToPath(uri: string): string; export = fileUriToPath; file-uri-to-path-1.0.0/index.js000066400000000000000000000032731312753035500162540ustar00rootroot00000000000000 /** * Module dependencies. */ var sep = require('path').sep || '/'; /** * Module exports. */ module.exports = fileUriToPath; /** * File URI to Path function. * * @param {String} uri * @return {String} path * @api public */ function fileUriToPath (uri) { if ('string' != typeof uri || uri.length <= 7 || 'file://' != uri.substring(0, 7)) { throw new TypeError('must pass in a file:// URI to convert to a file path'); } var rest = decodeURI(uri.substring(7)); var firstSlash = rest.indexOf('/'); var host = rest.substring(0, firstSlash); var path = rest.substring(firstSlash + 1); // 2. Scheme Definition // As a special case, can be the string "localhost" or the empty // string; this is interpreted as "the machine from which the URL is // being interpreted". if ('localhost' == host) host = ''; if (host) { host = sep + sep + host; } // 3.2 Drives, drive letters, mount points, file system root // Drive letters are mapped into the top of a file URI in various ways, // depending on the implementation; some applications substitute // vertical bar ("|") for the colon after the drive letter, yielding // "file:///c|/tmp/test.txt". In some cases, the colon is left // unchanged, as in "file:///c:/tmp/test.txt". In other cases, the // colon is simply omitted, as in "file:///c/tmp/test.txt". path = path.replace(/^(.+)\|/, '$1:'); // for Windows, we need to invert the path separators from what a URI uses if (sep == '\\') { path = path.replace(/\//g, '\\'); } if (/^.+\:/.test(path)) { // has Windows drive at beginning of path } else { // unix path… path = sep + path; } return host + path; } file-uri-to-path-1.0.0/package.json000066400000000000000000000013151312753035500170700ustar00rootroot00000000000000{ "name": "file-uri-to-path", "version": "1.0.0", "description": "Convert a file: URI to a file path", "main": "index.js", "types": "index.d.ts", "directories": { "test": "test" }, "scripts": { "test": "mocha --reporter spec" }, "repository": { "type": "git", "url": "git://github.com/TooTallNate/file-uri-to-path.git" }, "keywords": [ "file", "uri", "convert", "path" ], "author": "Nathan Rajlich (http://n8.io/)", "license": "MIT", "bugs": { "url": "https://github.com/TooTallNate/file-uri-to-path/issues" }, "homepage": "https://github.com/TooTallNate/file-uri-to-path", "devDependencies": { "mocha": "3" } } file-uri-to-path-1.0.0/test/000077500000000000000000000000001312753035500155615ustar00rootroot00000000000000file-uri-to-path-1.0.0/test/test.js000066400000000000000000000012321312753035500170740ustar00rootroot00000000000000 var sep = require('path').sep || '/'; var assert = require('assert'); var uri2path = require('../'); var tests = require('./tests.json'); describe('file-uri-to-path', function () { Object.keys(tests).forEach(function (uri) { // the test cases were generated from Windows' PathCreateFromUrlA() function. // On Unix, we have to replace the path separator with the Unix one instead of // the Windows one. var expected = tests[uri].replace(/\\/g, sep); it('should convert ' + JSON.stringify(uri) + ' to ' + JSON.stringify(expected), function () { var actual = uri2path(uri); assert.equal(actual, expected); }); }); }); file-uri-to-path-1.0.0/test/tests.json000066400000000000000000000014521312753035500176200ustar00rootroot00000000000000{ "file://host/path": "\\\\host\\path", "file://localhost/etc/fstab": "\\etc\\fstab", "file:///etc/fstab": "\\etc\\fstab", "file:///c:/WINDOWS/clock.avi": "c:\\WINDOWS\\clock.avi", "file://localhost/c|/WINDOWS/clock.avi": "c:\\WINDOWS\\clock.avi", "file:///c|/WINDOWS/clock.avi": "c:\\WINDOWS\\clock.avi", "file://localhost/c:/WINDOWS/clock.avi": "c:\\WINDOWS\\clock.avi", "file://hostname/path/to/the%20file.txt": "\\\\hostname\\path\\to\\the file.txt", "file:///c:/path/to/the%20file.txt": "c:\\path\\to\\the file.txt", "file:///C:/Documents%20and%20Settings/davris/FileSchemeURIs.doc": "C:\\Documents and Settings\\davris\\FileSchemeURIs.doc", "file:///C:/caf%C3%A9/%C3%A5r/d%C3%BCnn/%E7%89%9B%E9%93%83/Ph%E1%BB%9F/%F0%9F%98%B5.exe": "C:\\café\\år\\dünn\\牛铃\\Phở\\😵.exe" }