Full Code of sindresorhus/slash for AI

main 98b618f5a3bf cached
14 files
4.6 KB
1.6k tokens
1 symbols
1 requests
Download .txt
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<string>(slash('foo\\bar'));


================================================
FILE: license
================================================
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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);
});
Download .txt
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
Download .txt
SYMBOL INDEX (1 symbols across 1 files)

FILE: index.js
  function slash (line 1) | function slash(path) {
Condensed preview — 14 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (6K chars).
[
  {
    "path": ".editorconfig",
    "chars": 175,
    "preview": "root = true\n\n[*]\nindent_style = tab\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newlin"
  },
  {
    "path": ".gitattributes",
    "chars": 19,
    "preview": "* text=auto eol=lf\n"
  },
  {
    "path": ".github/funding.yml",
    "chars": 111,
    "preview": "github: sindresorhus\nopen_collective: sindresorhus\ntidelift: npm/slash\ncustom: https://sindresorhus.com/donate\n"
  },
  {
    "path": ".github/security.md",
    "chars": 179,
    "preview": "# Security Policy\n\nTo report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/s"
  },
  {
    "path": ".github/workflows/main.yml",
    "chars": 436,
    "preview": "name: CI\non:\n  - push\n  - pull_request\njobs:\n  test:\n    name: Node.js ${{ matrix.node-version }}\n    runs-on: ubuntu-la"
  },
  {
    "path": ".gitignore",
    "chars": 23,
    "preview": "node_modules\nyarn.lock\n"
  },
  {
    "path": ".npmrc",
    "chars": 19,
    "preview": "package-lock=false\n"
  },
  {
    "path": "index.d.ts",
    "chars": 560,
    "preview": "/**\nConvert Windows backslash paths to slash paths: `foo\\\\bar` ➔ `foo/bar`.\n\n[Forward-slash paths can be used in Windows"
  },
  {
    "path": "index.js",
    "chars": 181,
    "preview": "export default function slash(path) {\n\tconst isExtendedLengthPath = path.startsWith('\\\\\\\\?\\\\');\n\n\tif (isExtendedLengthPa"
  },
  {
    "path": "index.test-d.ts",
    "chars": 104,
    "preview": "import {expectType} from 'tsd';\nimport slash from './index.js';\n\nexpectType<string>(slash('foo\\\\bar'));\n"
  },
  {
    "path": "license",
    "chars": 1117,
    "preview": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby grant"
  },
  {
    "path": "package.json",
    "chars": 716,
    "preview": "{\n\t\"name\": \"slash\",\n\t\"version\": \"5.1.0\",\n\t\"description\": \"Convert Windows backslash paths to slash paths\",\n\t\"license\": \""
  },
  {
    "path": "readme.md",
    "chars": 676,
    "preview": "# slash\n\n> Convert Windows backslash paths to slash paths: `foo\\\\bar` ➔ `foo/bar`\n\n[Forward-slash paths can be used in W"
  },
  {
    "path": "test.js",
    "chars": 396,
    "preview": "import test from 'ava';\nimport slash from './index.js';\n\ntest('convert backwards-slash paths to forward slash paths', t "
  }
]

About this extraction

This page contains the full source code of the sindresorhus/slash GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 14 files (4.6 KB), approximately 1.6k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!