Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 2, 2016
1 parent c77fefb commit af9ce36
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 32 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Expand Up @@ -10,6 +10,3 @@ insert_final_newline = true
[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
12 changes: 0 additions & 12 deletions .jshintrc

This file was deleted.

18 changes: 8 additions & 10 deletions cli.js
Expand Up @@ -3,15 +3,13 @@
var meow = require('meow');
var fileUrl = require('./');

var cli = meow({
help: [
'Usage',
' $ file-url [path]',
'',
'Example',
' $ file-url',
' file:///Users/sindresorhus/dev/file-url'
]
});
var cli = meow([
'Usage',
' $ file-url [path]',
'',
'Example',
' $ file-url',
' file:///Users/sindresorhus/dev/file-url'
]);

console.log(fileUrl(cli.input[0] || process.cwd()));
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -6,15 +6,16 @@ module.exports = function (str, options) {
throw new Error('Expected a string');
}

options = options || {};

var pathName = str;

if (typeof options !== 'object' || options.resolve) {
if (options.resolve !== false) {
pathName = path.resolve(str);
}

pathName = pathName.replace(/\\/g, '/');


// Windows drive letter must be prefixed with a slash
if (pathName[0] !== '/') {
pathName = '/' + pathName;
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -14,7 +14,7 @@
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
"test": "xo && mocha"
},
"files": [
"cli.js",
Expand All @@ -33,9 +33,10 @@
"slash"
],
"dependencies": {
"meow": "^3.3.0"
"meow": "^3.7.0"
},
"devDependencies": {
"mocha": "*"
"mocha": "*",
"xo": "*"
}
}
4 changes: 2 additions & 2 deletions readme.md
Expand Up @@ -21,8 +21,8 @@ fileUrl('unicorn.jpg');
fileUrl('/Users/pony/pics/unicorn.jpg');
//=> 'file:///Users/pony/pics/unicorn.jpg'

// passing {resolve: false} as second argument will not call path.resolve() on the path
fileUrl('unicorn.jpg', {resolve: false);
// passing {resolve: false} will make it not call path.resolve() on the path
fileUrl('unicorn.jpg', {resolve: false});
//=> 'file:///unicorn.jpg'
```

Expand Down
2 changes: 2 additions & 0 deletions test.js
@@ -1,9 +1,11 @@
/* eslint-env mocha */
'use strict';
var assert = require('assert');
var fileUrl = require('./');

it('should convert path to file url', function () {
assert(/file:\/\/\/.*\/test\.jpg/.test(fileUrl('test.jpg')));

if (process.platform === 'win32') {
assert.strictEqual(fileUrl('C:\\Users\\sindresorhus\\dev\\te^st.jpg'), 'file:///C:/Users/sindresorhus/dev/te%5Est.jpg');
} else {
Expand Down

0 comments on commit af9ce36

Please sign in to comment.