# svn-project-root

> Get the root url for your svn project

Latest version **0.1.0** (published 2014-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install svn-project-root
pnpm add svn-project-root
yarn add svn-project-root
bun add svn-project-root
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2014-04-23 |
| First published | 2014-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | jtrussell |
| Maintainers | jtrussell |
| Keywords | node, svn, url |

## Links

- npm: https://www.npmjs.com/package/svn-project-root
- Repository: https://github.com/jtrussell/node-svn-project-root
- Issues: https://github.com/jtrussell/node-svn-project-root/issues
- npm.io page: https://npm.io/package/svn-project-root

## Dependencies (2)

- [findup](https://npm.io/package/findup.md) ^0.1.5
- [svn-info](https://npm.io/package/svn-info.md) ^0.1.3

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2014-04-23

## README

# SVN Project Root

> Get the root url for your svn project

## Usage

### svn-project-root

This module exports a function which asynchronously determines the project root
for your svn repository. 

```javascript
var doSomethingWithRoot = function(err, root) {
  // Handle error, do something with root
};

var getRoot = require('svn-project-root');

getRoot(doSomethingWithRoot);

// CWD not in the project you care about? You can pass directory path as
// thefirst parameter.
var otherProjectFldr = '/other/project/folder';
getRoot(otherProjectFldr, doSomethingWithRoot);
```

### svn-project-root#sync

The synchronous flavor of the above method. This may throw an error if for
example there is a problem parsing your project's `package.json` or if the
project in question is not an svn repository.

```javascript
var getRoot = require('svn-project-root')
  , otherProjectFldr = '/other/project/folder'
  , projectRoot;

try {
  projectRoot = getRoot.sync();
} catch(err) {
  // boo!
}

// or

try {
  projectRoot = getRoot.sync(otherProjectFldr);
} catch(err) {
  // boo!
}

// Do something with root
```

### svn-project-root#normalize

Our method for normalizing svn urls is also exported. If you already have a svn
url handy and just want to get the project root from that url the method may
satisfy your needs.

Usernames and passwords will be stripped away and the url will be chopped down
to just before `trunk|branches|tags` start.

```javascript
var uglyUrl = 'https://jtrussell@svnhub.com/fldr/branches/assets/scripts'
  , normalize = require('svn-project-root').normalize;
console.log(normalize(uglyUrl));
// --> 'https://svnhub.com/fldr'
```

## Usage Examples

```javascript
var getRoot = require('svn-project-root');

// Optionally specify a start directory as first param, defaults to
process.cwd(). Directory // must be above your package.json or inside a svn repo
getRoot(function(err, url) {
  if(err) {
    // Whoops!
  }
  // Do something with url
});

try {
  // Optionally you may pass a directory
  var url = getRoot.sync();
} catch(err) {
  // Whoops!
}
// Do something with url

var grossSvnUrl = 'http://jtrussell@foobar.com/fldr/branches/featureXYZ'
  , prettyUrl = getRoot.normalize(grossSvnUrl);
console.log(prettyUrl);
// --> 'http://foobar.com/fldr'
```

## Limitations

### Assumption: Sane folder names

This module assumes your svn project directory structure looks like:

```
/
  /<arbitrary-folders>
    /<root>
      /trunk
      /branches
      /tags
```

The root or your project is assumed to be the parent directory of the first
occurrence of `trunk|branches|root`, if you structure your repo such that it's
svn url looks like `https://svnhub.com/trunk/trunk/trunk/branches/foo` you may
have problems. I.e. please do not name repo ancestors `trunk|branches|tags`.

### Assumption: First valid package.json is the one you want

`svn-project-root` will grab your repo url from the `repository.url` field in
the first `package.json` it sees in the passed directory (defaults to
`process.cwd()`) or any of its ancestors where the following is true:

- `repository.type` is set and equals `'svn'`
- `repository.url` is set

## Tests

Tests are run with [grunt][1] and [mocha][2].

```shell
grunt test
```

## License

MIT

[1]: http://gruntjs.com/ "Grunt"
[2]: http://visionmedia.github.io/mocha/ "Mocha"

---
_Source: https://npm.io/package/svn-project-root · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
