Repository: sindresorhus/slash Branch: main Commit: 98b618f5a3bf Files: 14 Total size: 4.6 KB Directory structure: gitextract_8dne78j3/ ├── .editorconfig ├── .gitattributes ├── .github/ │ ├── funding.yml │ ├── security.md │ └── workflows/ │ └── main.yml ├── .gitignore ├── .npmrc ├── index.d.ts ├── index.js ├── index.test-d.ts ├── license ├── package.json ├── readme.md └── test.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 ================================================ FILE: .gitattributes ================================================ * text=auto eol=lf ================================================ FILE: .github/funding.yml ================================================ github: sindresorhus open_collective: sindresorhus tidelift: npm/slash custom: https://sindresorhus.com/donate ================================================ FILE: .github/security.md ================================================ # Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. ================================================ FILE: .github/workflows/main.yml ================================================ name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 18 - 16 - 14 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test ================================================ FILE: .gitignore ================================================ node_modules yarn.lock ================================================ FILE: .npmrc ================================================ package-lock=false ================================================ FILE: index.d.ts ================================================ /** Convert Windows backslash paths to slash paths: `foo\\bar` ➔ `foo/bar`. [Forward-slash paths can be used in Windows](http://superuser.com/a/176395/6877) as long as they're not extended-length paths. @param path - A Windows backslash path. @returns A path with forward slashes. @example ``` import path from 'node:path'; import slash from 'slash'; const string = path.join('foo', 'bar'); // Unix => foo/bar // Windows => foo\\bar slash(string); // Unix => foo/bar // Windows => foo/bar ``` */ export default function slash(path: string): string; ================================================ FILE: index.js ================================================ export default function slash(path) { const isExtendedLengthPath = path.startsWith('\\\\?\\'); if (isExtendedLengthPath) { return path; } return path.replace(/\\/g, '/'); } ================================================ FILE: index.test-d.ts ================================================ import {expectType} from 'tsd'; import slash from './index.js'; expectType(slash('foo\\bar')); ================================================ FILE: license ================================================ MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) 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: package.json ================================================ { "name": "slash", "version": "5.1.0", "description": "Convert Windows backslash paths to slash paths", "license": "MIT", "repository": "sindresorhus/slash", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "types": "./index.d.ts", "engines": { "node": ">=14.16" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "path", "seperator", "slash", "backslash", "windows", "convert" ], "devDependencies": { "ava": "^5.2.0", "tsd": "^0.28.1", "xo": "^0.54.2" } } ================================================ FILE: readme.md ================================================ # slash > Convert Windows backslash paths to slash paths: `foo\\bar` ➔ `foo/bar` [Forward-slash paths can be used in Windows](http://superuser.com/a/176395/6877) as long as they're not extended-length paths. This was created since the `path` methods in Node.js outputs `\\` paths on Windows. ## Install ```sh npm install slash ``` ## Usage ```js import path from 'node:path'; import slash from 'slash'; const string = path.join('foo', 'bar'); // Unix => foo/bar // Windows => foo\\bar slash(string); // Unix => foo/bar // Windows => foo/bar ``` ## API ### slash(path) Type: `string` Accepts a Windows backslash path and returns a path with forward slashes. ================================================ FILE: test.js ================================================ import test from 'ava'; import slash from './index.js'; test('convert backwards-slash paths to forward slash paths', t => { t.is(slash('c:/aaaa\\bbbb'), 'c:/aaaa/bbbb'); t.is(slash('c:\\aaaa\\bbbb'), 'c:/aaaa/bbbb'); t.is(slash('c:\\aaaa\\bbbb\\★'), 'c:/aaaa/bbbb/★'); }); test('not convert extended-length paths', t => { const path = '\\\\?\\c:\\aaaa\\bbbb'; t.is(slash(path), path); });