find-root

WebJar for find-root

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

find-root
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

find-root
WebJar for find-root
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/suarasaur/find-root

Download find-root

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/find-root/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>find-root</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/find-root/
implementation 'org.webjars.npm:find-root:1.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/find-root/
implementation ("org.webjars.npm:find-root:1.1.0")
'org.webjars.npm:find-root:jar:1.1.0'
<dependency org="org.webjars.npm" name="find-root" rev="1.1.0">
  <artifact name="find-root" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='find-root', version='1.1.0')
)
libraryDependencies += "org.webjars.npm" % "find-root" % "1.1.0"
[org.webjars.npm/find-root "1.1.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

find-root

recursively find the closest package.json

Build Status

usage

Say you want to check if the directory name of a project matches its module name in package.json:

const path = require('path')
const findRoot = require('find-root')

// from a starting directory, recursively search for the nearest
// directory containing package.json
const root = findRoot('/Users/jsdnxx/Code/find-root/tests')
// => '/Users/jsdnxx/Code/find-root'

const dirname = path.basename(root)
console.log('is it the same?')
console.log(dirname === require(path.join(root, 'package.json')).name)

You can also pass in a custom check function (by default, it checks for the existence of package.json in a directory). In this example, we traverse up to find the root of a git repo:

const fs = require('fs')

const gitRoot = findRoot('/Users/jsdnxx/Code/find-root/tests', function (dir) {
  return fs.existsSync(path.resolve(dir, '.git'))
})

api

findRoot: (startingPath : string, check?: (dir: string) => boolean) => string

Returns the path for the nearest directory to startingPath containing a package.json file, eg /foo/module.

If check is provided, returns the path for the closest parent directory where check returns true.

Throws an error if no package.json is found at any level in the startingPath.

installation

> npm install find-root

running the tests

From package root:

> npm install
> npm test

contributors

  • jsdnxx

license

MIT. (c) 2017 jsdnxx

Versions

Version
1.1.0
0.1.2