find-parent-dir
Advanced tools
+10
-2
@@ -9,2 +9,10 @@ 'use strict'; | ||
| function splitPath(path) { | ||
| var parts = path.split(/(\/|\\)/); | ||
| if (!parts.length) return parts; | ||
| // when path starts with a slash, the first part is empty string | ||
| return !parts[0].length ? parts.slice(1) : parts; | ||
| } | ||
| exports = module.exports = function (currentFullPath, clue, cb) { | ||
@@ -23,3 +31,3 @@ | ||
| testDir(currentFullPath.split(/(\/|\\)/)); | ||
| testDir(splitPath(currentFullPath)); | ||
| } | ||
@@ -37,4 +45,4 @@ | ||
| } | ||
| return testDir(currentFullPath.split(/(\/|\\)/)); | ||
| return testDir(splitPath(currentFullPath)); | ||
| } |
+1
-1
| { | ||
| "name": "find-parent-dir", | ||
| "version": "0.2.0", | ||
| "version": "0.2.1", | ||
| "description": "Finds the first parent directory that contains a given file or directory.", | ||
@@ -5,0 +5,0 @@ "main": "find-parent-dir.js", |
@@ -6,2 +6,3 @@ 'use strict'; | ||
| var path = require('path') | ||
| var fs = require('fs') | ||
| var findParentDir = require('..') | ||
@@ -30,5 +31,16 @@ | ||
| test('sync finding this dir relative to the test dir', function (t) { | ||
| var dir = findParentDir.sync(__dirname, 'find-parent-dir.js'); | ||
| var dir = findParentDir.sync(__dirname, 'find-parent-dir.js') | ||
| t.equals(dir, path.resolve(__dirname)) | ||
| t.end() | ||
| }) | ||
| test('find no dir when file is in the test dir', function(t) { | ||
| var filepath = path.join(__dirname, 'shazam.txt') | ||
| fs.writeFileSync(filepath, 'shaq attack') | ||
| findParentDir('/etc', 'shazam.txt', function (err, dir) { | ||
| fs.unlinkSync(filepath) | ||
| t.equals(err, null) | ||
| t.equals(dir, null) | ||
| t.end() | ||
| }) | ||
| }) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
5300
11.56%76
28.81%2
100%