Comparing version 0.1.1 to 1.0.0
@@ -1,4 +0,4 @@ | ||
"use strict"; | ||
var path = require("path"); | ||
var fs = require("fs"); | ||
'use strict' | ||
var path = require('path') | ||
var fs = require('fs') | ||
@@ -9,4 +9,18 @@ /** | ||
@module walk-back | ||
@example | ||
> walkBack = require('walk-back') | ||
> walkBack(process.cwd(), 'package.json') | ||
'/Users/lloyd/Documents/75lb/walk-back/package.json' | ||
> walkBack(process.cwd(), '75lb') | ||
'/Users/lloyd/Documents/75lb' | ||
> walkBack(process.cwd(), '.bash_profile') | ||
'/Users/lloyd/.bash_profile' | ||
> walkBack(process.cwd(), 'non-existent.file') | ||
null | ||
*/ | ||
module.exports = walkBack; | ||
module.exports = walkBack | ||
@@ -19,15 +33,15 @@ /** | ||
*/ | ||
function walkBack(startAt, lookingFor){ | ||
var dirs = startAt.split(path.sep); | ||
for (var i = 0; i < dirs.length; i++) { | ||
var basedir = i < dirs.length - 1 | ||
? dirs.slice(0, dirs.length - i).join(path.sep) | ||
: path.sep; | ||
function walkBack (startAt, lookingFor) { | ||
var dirs = startAt.split(path.sep) | ||
for (var i = 0; i < dirs.length; i++) { | ||
var basedir = i < dirs.length - 1 | ||
? dirs.slice(0, dirs.length - i).join(path.sep) | ||
: path.sep | ||
if (fs.existsSync(path.join(basedir, lookingFor))){ | ||
return path.join(basedir, lookingFor); | ||
} | ||
if (fs.existsSync(path.join(basedir, lookingFor))) { | ||
return path.join(basedir, lookingFor) | ||
} | ||
/* if we reached here, nothing was found */ | ||
return null; | ||
} | ||
/* if we reached here, nothing was found */ | ||
return null | ||
} |
{ | ||
"name": "walk-back", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "Walk up the directory tree until the specified path is found.", | ||
@@ -9,5 +9,2 @@ "repository": "https://github.com/75lb/walk-back.git", | ||
"main": "./lib/walk-back.js", | ||
"bin": { | ||
"walk-back": "bin/cli.js" | ||
}, | ||
"keywords": [ | ||
@@ -14,0 +11,0 @@ "walk", |
@@ -5,2 +5,3 @@ [![view on npm](http://img.shields.io/npm/v/walk-back.svg)](https://www.npmjs.org/package/walk-back) | ||
[![Dependency Status](https://david-dm.org/75lb/walk-back.svg)](https://david-dm.org/75lb/walk-back) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard) | ||
@@ -11,2 +12,18 @@ <a name="module_walk-back"></a> | ||
**Example** | ||
```js | ||
> walkBack = require('walk-back') | ||
> walkBack(process.cwd(), 'package.json') | ||
'/Users/lloyd/Documents/75lb/walk-back/package.json' | ||
> walkBack(process.cwd(), '75lb') | ||
'/Users/lloyd/Documents/75lb' | ||
> walkBack(process.cwd(), '.bash_profile') | ||
'/Users/lloyd/.bash_profile' | ||
> walkBack(process.cwd(), 'non-existent.file') | ||
null | ||
``` | ||
<a name="exp_module_walk-back--walkBack"></a> | ||
@@ -13,0 +30,0 @@ ### walkBack(startAt, lookingFor) ⇒ <code>string</code> ⏏ |
@@ -1,24 +0,23 @@ | ||
var test = require("tape"); | ||
var walkBack = require("../"); | ||
var fs = require("fs"); | ||
var test = require('tape') | ||
var walkBack = require('../') | ||
test("basic", function(t){ | ||
t.plan(1); | ||
test('basic', function (t) { | ||
t.plan(1) | ||
var filename = walkBack(__dirname + "/fixture/subdir", "file.txt"); | ||
t.ok(filename.search("walk-back/test/fixture/subdir/file.txt") > 0); | ||
}); | ||
var filename = walkBack(__dirname + '/fixture/subdir', 'file.txt') | ||
t.ok(filename.search('walk-back/test/fixture/subdir/file.txt') > 0) | ||
}) | ||
test("basic2", function(t){ | ||
t.plan(1); | ||
test('basic2', function (t) { | ||
t.plan(1) | ||
var filename = walkBack(__dirname + "/fixture", "file.txt"); | ||
t.ok(filename.search("walk-back/test/fixture/file.txt") > 0); | ||
}); | ||
var filename = walkBack(__dirname + '/fixture', 'file.txt') | ||
t.ok(filename.search('walk-back/test/fixture/file.txt') > 0) | ||
}) | ||
test("not found", function(t){ | ||
t.plan(1); | ||
test('not found', function (t) { | ||
t.plan(1) | ||
var filename = walkBack(__dirname + "/fixture", "adskjfhladfn"); | ||
t.strictEqual(filename, null); | ||
}); | ||
var filename = walkBack(__dirname + '/fixture', 'adskjfhladfn') | ||
t.strictEqual(filename, null) | ||
}) |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5669
54
1
41
2