Coder Social home page Coder Social logo

slash's Introduction

slash

Convert Windows backslash paths to slash paths: foo\\barfoo/bar

Forward-slash paths can be used in Windows as long as they're not extended-length paths.

This was created since the path methods in Node.js outputs \\ paths on Windows.

Install

npm install slash

Usage

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.

slash's People

Contributors

bendingbender avatar birjj avatar dario-piotrowicz avatar emagers avatar kevva avatar paulmillr avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slash's Issues

Slash doesn't work on filepaths

I use this library for a project of mine and it's worked great to smooth stuff that has to be synced across windows and linux

I recently wrote a script that uses this on a filepath and noticed it was returning the filepath with the Windows format still in place

Support non-ASCII characters in Commonjs

HI. This lib has been updated to type module but electron still does not support modules, so I am not able to use the latest version of this lib. But the fix of non-ascii chars are only in the newest version.
Any way to get this fixed on the old versions too?
Thanks!

transform arrow function

// module.exports = path => {
module.exports = function (path) {
	const isExtendedLengthPath = /^\\\\\?\\/.test(path);
	const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex

	if (isExtendedLengthPath || hasNonAscii) {
		return path;
	}

	return path.replace(/\\/g, '/');
};

image

Support non-ASCII characters in paths

This project claims that

Forward-slash paths can be used in Windows as long as they're not extended-length paths and don't contain any non-ascii characters.

However, the linked SuperUser answer does not mention the non-ASCII limitation. The official documentation also makes no mention of it, instead noting that

File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections.

(this quote used to be on the documentation site linked in the SuperUser answer, but has since been moved to the "Maximum File Path Limitation" page)

Is there any documentation or examples to support the non-ASCII limitation in this project? From my own anecdotal testing it appears that paths with non-ASCII characters and forward slash path separators are supported in Windows and Node.js.

If there is no documentation, could this project be updated to support them? It appears to cause many problems in projects that rely on it, e.g. facebook/docusaurus#8124, gatsbyjs/gatsby#19600, and SAP/ui5-tooling#469, amongst others.

Not working with Unicode

Seems like this great util doesn't like Unicode:

> require('slash')('a\\b\\c')
'a/b/c'
> require('slash')('a\\b\\ц')
'a\\b\\ц'

Changelog

Please provide a brief change description in releases directly or in CHANGELOG.md

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.