Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "slash", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Convert Windows backslash paths to slash paths", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# slash [![Build Status](https://secure.travis-ci.org/sindresorhus/slash.png?branch=master)](http://travis-ci.org/sindresorhus/slash) | ||
Convert Windows backslash paths to slash paths. | ||
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 it's not an extended-length path and it doesn't contain Unicode. | ||
[Forward-slash paths can be used in Windows](http://superuser.com/a/176395/6877) as long as they're not extended-length paths and don't contain any non-ascii characters. | ||
@@ -10,7 +10,27 @@ | ||
Install with [npm](https://npmjs.org): `npm install --save slash` | ||
Download the library [manually](https://github.com/sindresorhus/slash/releases) or with a package-manager. | ||
#### [npm](https://npmjs.org/package/slash) | ||
``` | ||
npm install --save slash | ||
``` | ||
#### [Bower](http://bower.io) | ||
``` | ||
bower install --save slash | ||
``` | ||
#### [Component](https://github.com/component/component) | ||
``` | ||
component install sindresorhus/slash | ||
``` | ||
## Example | ||
Using Node.js: | ||
```js | ||
@@ -22,9 +42,12 @@ var path = require('path'); | ||
console.log(str); | ||
//=> foo\\bar | ||
// Unix => foo/bar | ||
// Windows => foo\\bar | ||
if (process.platform === 'win32') { | ||
str = slash(str); | ||
console.log(str); | ||
//=> foo/bar | ||
str = slash(str); | ||
} | ||
console.log(str); | ||
// Unix => foo/bar | ||
// Windows => foo/bar | ||
``` | ||
@@ -44,2 +67,2 @@ | ||
MIT License • © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
28
slash.js
@@ -1,14 +0,20 @@ | ||
'use strict'; | ||
module.exports = function (str) { | ||
// Windows converts slash paths to backslashes if it's not an | ||
// extended-length path and doesn't contain any Unicode | ||
// http://msdn.microsoft.com/en-us/library/aa365247.aspx | ||
var isExtendedLengthPath = /^\\\\\?\\/.test(str); | ||
var hasUnicode = /[^\x00-\x80]+/.test(str); | ||
(function () { | ||
'use strict'; | ||
if (isExtendedLengthPath || hasUnicode) { | ||
return str; | ||
function slash(str) { | ||
var isExtendedLengthPath = /^\\\\\?\\/.test(str); | ||
var hasNonAscii = /[^\x00-\x80]+/.test(str); | ||
if (isExtendedLengthPath || hasNonAscii) { | ||
return str; | ||
} | ||
return str.replace(/\\/g, '/'); | ||
} | ||
return str.replace(/\\/g, '/'); | ||
}; | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = slash; | ||
} else { | ||
window.slash = slash; | ||
} | ||
})(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2415
16
66