Comparing version 0.1.3 to 0.1.4
31
index.js
/** | ||
* Relative <https://github.com/jonschlinkert/relative> | ||
* relative <https://github.com/jonschlinkert/relative> | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
@@ -7,9 +7,21 @@ * Licensed under the MIT license. | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
var file = require('fs-utils'); | ||
var path = require('path'); | ||
// True if the filepath is a directory. | ||
function isDir() { | ||
var filepath = path.join.apply(path, arguments); | ||
if (!fs.existsSync(filepath)) { | ||
return false; | ||
} | ||
return fs.statSync(filepath).isDirectory(); | ||
} | ||
// Unixify all slashes | ||
function normalizeSlash(str) { | ||
return str.replace(/\\/g, '/'); | ||
} | ||
/** | ||
@@ -28,5 +40,5 @@ * Return the relative path from | ||
from = !file.isDir(from) ? path.dirname(from) : from; | ||
from = !isDir(from) ? path.dirname(from) : from; | ||
var rel = path.relative(path.resolve(from), path.resolve(to)); | ||
return file.normalizeSlash(rel); | ||
return normalizeSlash(rel); | ||
}; | ||
@@ -47,7 +59,10 @@ | ||
basepath = path.resolve(basepath); | ||
if (filepath.indexOf(basepath) === 0) { | ||
filepath = filepath.replace(basepath, ''); | ||
} | ||
filepath = file.normalizeSlash(filepath); | ||
return filepath.replace(/^\//, '') | ||
filepath = normalizeSlash(filepath); | ||
// Remove leading slash. | ||
return filepath.replace(/^\//, ''); | ||
}; | ||
@@ -54,0 +69,0 @@ |
{ | ||
"name": "relative", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Easily calculate the relative path from file A to file B in Node.js project. Will calculate correctly from a file to a directory, file to file, directory to file, and directory to directory.", | ||
@@ -25,5 +25,2 @@ "repository": { | ||
}, | ||
"dependencies": { | ||
"fs-utils": "~0.3.0" | ||
}, | ||
"devDependencies": { | ||
@@ -30,0 +27,0 @@ "chai": "~1.9.0", |
@@ -13,3 +13,3 @@ /** | ||
var relative = require('../'); | ||
var relative = require('./'); | ||
@@ -16,0 +16,0 @@ describe('relative', function() { |
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
7928
0
8
132
- Removedfs-utils@~0.3.0
- Removedargparse@0.1.16(transitive)
- Removedasync@0.2.100.6.2(transitive)
- Removeddelims@0.1.4(transitive)
- Removedesprima@1.0.4(transitive)
- Removedfs-utils@0.3.100.4.3(transitive)
- Removedglob@3.2.11(transitive)
- Removedglobule@0.2.0(transitive)
- Removedgraceful-fs@2.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-yaml@3.0.2(transitive)
- Removedlodash@2.4.2(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.2.140.3.0(transitive)
- Removedmkdirp@0.3.5(transitive)
- Removedrimraf@2.2.8(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedtemplate@0.1.8(transitive)
- Removedunderscore@1.7.0(transitive)
- Removedunderscore.string@2.3.32.4.0(transitive)