pax_global_header00006660000000000000000000000064135501620760014517gustar00rootroot0000000000000052 comment=701a2d8e6927a74b40f605e7f6071ec57cd978f0 file-uri-to-path-2.0.0/000077500000000000000000000000001355016207600146045ustar00rootroot00000000000000file-uri-to-path-2.0.0/.editorconfig000066400000000000000000000013131355016207600172570ustar00rootroot00000000000000root = true [*] indent_style = tab indent_size = 4 tab_width = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{*.json,*.json.example,*.gyp,*.yml,*.yaml,*.workflow}] indent_style = space indent_size = 2 [{*.py,*.asm}] indent_style = space [*.py] indent_size = 4 [*.asm] indent_size = 8 [*.md] trim_trailing_whitespace = false # Ideal settings - some plugins might support these. [*.js] quote_type = single [{*.c,*.cc,*.h,*.hh,*.cpp,*.hpp,*.m,*.mm,*.mpp,*.js,*.java,*.go,*.rs,*.php,*.ng,*.jsx,*.ts,*.d,*.cs,*.swift}] curly_bracket_next_line = false spaces_around_operators = true spaces_around_brackets = outside # close enough to 1TB indent_brace_style = K&R file-uri-to-path-2.0.0/.eslintrc.js000066400000000000000000000055671355016207600170600ustar00rootroot00000000000000module.exports = { 'extends': [ 'airbnb', 'prettier' ], 'parser': '@typescript-eslint/parser', 'parserOptions': { 'ecmaVersion': 2018, 'sourceType': 'module', 'modules': true }, 'plugins': [ '@typescript-eslint' ], 'settings': { 'import/resolver': { 'typescript': { } } }, 'rules': { 'quotes': [ 2, 'single', { 'allowTemplateLiterals': true } ], 'class-methods-use-this': 0, 'consistent-return': 0, 'func-names': 0, 'global-require': 0, 'guard-for-in': 0, 'import/no-duplicates': 0, 'import/no-dynamic-require': 0, 'import/no-extraneous-dependencies': 0, 'import/prefer-default-export': 0, 'lines-between-class-members': 0, 'no-await-in-loop': 0, 'no-bitwise': 0, 'no-console': 0, 'no-continue': 0, 'no-control-regex': 0, 'no-empty': 0, 'no-loop-func': 0, 'no-nested-ternary': 0, 'no-param-reassign': 0, 'no-plusplus': 0, 'no-restricted-globals': 0, 'no-restricted-syntax': 0, 'no-shadow': 0, 'no-underscore-dangle': 0, 'no-use-before-define': 0, 'prefer-const': 0, 'prefer-destructuring': 0, 'camelcase': 0, 'no-unused-vars': 0, // in favor of '@typescript-eslint/no-unused-vars' // 'indent': 0 // in favor of '@typescript-eslint/indent' '@typescript-eslint/no-unused-vars': 'warn', // '@typescript-eslint/indent': ['error', 2] // this might conflict with a lot ongoing changes '@typescript-eslint/no-array-constructor': 'error', '@typescript-eslint/adjacent-overload-signatures': 'error', '@typescript-eslint/class-name-casing': 'error', '@typescript-eslint/interface-name-prefix': 'error', '@typescript-eslint/no-empty-interface': 'error', '@typescript-eslint/no-inferrable-types': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-assertion': 'error', '@typescript-eslint/no-parameter-properties': 'error', '@typescript-eslint/no-triple-slash-reference': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', '@typescript-eslint/type-annotation-spacing': 'error', // '@typescript-eslint/array-type': 'error', // '@typescript-eslint/ban-types': 'error', // '@typescript-eslint/explicit-function-return-type': 'warn', // '@typescript-eslint/explicit-member-accessibility': 'error', // '@typescript-eslint/member-delimiter-style': 'error', // '@typescript-eslint/no-angle-bracket-type-assertion': 'error', // '@typescript-eslint/no-explicit-any': 'warn', // '@typescript-eslint/no-object-literal-type-assertion': 'error', // '@typescript-eslint/no-use-before-define': 'error', // '@typescript-eslint/no-var-requires': 'error', // '@typescript-eslint/prefer-interface': 'error' } } file-uri-to-path-2.0.0/.github/000077500000000000000000000000001355016207600161445ustar00rootroot00000000000000file-uri-to-path-2.0.0/.github/workflows/000077500000000000000000000000001355016207600202015ustar00rootroot00000000000000file-uri-to-path-2.0.0/.github/workflows/test.yml000066400000000000000000000014131355016207600217020ustar00rootroot00000000000000name: Node CI on: [push] jobs: build: name: Test Node.js ${{ matrix.node-version }} on ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] node-version: [6.x, 8.x, 10.x, 12.x] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v1 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Print Node.js Version run: node --version - name: Install Dependencies run: npm install env: CI: true - name: Run "build" step run: npm run build --if-present env: CI: true - name: Run tests run: npm test env: CI: true file-uri-to-path-2.0.0/.gitignore000066400000000000000000000000371355016207600165740ustar00rootroot00000000000000/dist /yarn.lock /node_modules file-uri-to-path-2.0.0/LICENSE000066400000000000000000000020731355016207600156130ustar00rootroot00000000000000Copyright (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-2.0.0/README.md000066400000000000000000000040701355016207600160640ustar00rootroot00000000000000file-uri-to-path ================ ### Convert a `file:` URI to a file path [![Build Status](https://github.com/TooTallNate/file-uri-to-path/workflows/Node%20CI/badge.svg)](https://github.com/TooTallNate/file-uri-to-path/actions?workflow=Node+CI) 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-2.0.0/package.json000066400000000000000000000026711355016207600171000ustar00rootroot00000000000000{ "name": "file-uri-to-path", "version": "2.0.0", "description": "Convert a file: URI to a file path", "main": "dist/src/index", "typings": "dist/src/index", "files": [ "dist/src" ], "scripts": { "prebuild": "rimraf dist", "build": "tsc", "postbuild": "cpy --parents src test '!**/*.ts' dist", "test": "mocha --reporter spec dist/test/*.js", "test-lint": "eslint src --ext .js,.ts", "prepublishOnly": "npm run build" }, "repository": { "type": "git", "url": "git://github.com/TooTallNate/file-uri-to-path.git" }, "engines": { "node": ">= 6" }, "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": { "@types/mocha": "^5.2.7", "@types/node": "^10.5.3", "@typescript-eslint/eslint-plugin": "1.6.0", "@typescript-eslint/parser": "1.1.0", "cpy-cli": "^2.0.0", "eslint": "5.16.0", "eslint-config-airbnb": "17.1.0", "eslint-config-prettier": "4.1.0", "eslint-import-resolver-typescript": "1.1.1", "eslint-plugin-import": "2.16.0", "eslint-plugin-jsx-a11y": "6.2.1", "eslint-plugin-react": "7.12.4", "mocha": "^6.2.0", "rimraf": "^3.0.0", "typescript": "^3.5.3" } } file-uri-to-path-2.0.0/src/000077500000000000000000000000001355016207600153735ustar00rootroot00000000000000file-uri-to-path-2.0.0/src/index.ts000066400000000000000000000031441355016207600170540ustar00rootroot00000000000000import { sep } from 'path'; /** * File URI to Path function. * * @param {String} uri * @return {String} path * @api public */ function fileUriToPath(uri: string): string { if ( typeof uri !== 'string' || uri.length <= 7 || uri.substring(0, 7) !== 'file://' ) { throw new TypeError( 'must pass in a file:// URI to convert to a file path' ); } const rest = decodeURI(uri.substring(7)); const firstSlash = rest.indexOf('/'); let host = rest.substring(0, firstSlash); let 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 (host === 'localhost') { 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; } export = fileUriToPath; file-uri-to-path-2.0.0/test/000077500000000000000000000000001355016207600155635ustar00rootroot00000000000000file-uri-to-path-2.0.0/test/test.ts000066400000000000000000000012711355016207600171130ustar00rootroot00000000000000import { sep } from 'path'; import assert from 'assert'; import uri2path from '../src'; import _tests from './tests.json'; const tests = _tests as { [input: string]: string }; describe('file-uri-to-path', function() { for (const uri of Object.keys(tests)) { // 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. const expected = tests[uri].replace(/\\/g, sep); it( `should convert ${ JSON.stringify(uri) } to ${ JSON.stringify(expected)}`, function() { const actual = uri2path(uri); assert.equal(actual, expected); } ); } }); file-uri-to-path-2.0.0/test/tests.json000066400000000000000000000014521355016207600176220ustar00rootroot00000000000000{ "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" } file-uri-to-path-2.0.0/tsconfig.json000066400000000000000000000005041355016207600173120ustar00rootroot00000000000000{ "compilerOptions": { "strict": true, "module": "CommonJS", "target": "es2015", "esModuleInterop": true, "lib": ["esnext"], "outDir": "dist", "sourceMap": true, "declaration": true, "resolveJsonModule": true }, "include": ["src/**/*", "test/**/*"], "exclude": ["node_modules"] }