# git-tags

> Get and parse semver Git tags using Node.js

Latest version **0.2.4** (published 2014-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install git-tags
pnpm add git-tags
yarn add git-tags
bun add git-tags
```

## 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.2.4 |
| Published | 2014-10-31 |
| First published | 2014-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+6 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Brian Frichette |
| Maintainers | bfricka |
| Keywords | Git, Tag, semver |

## Links

- npm: https://www.npmjs.com/package/git-tags
- Repository: git@github.com:bfricka/node-git-tags
- Homepage: https://github.com/bfricka/node-git-tags
- Issues: https://github.com/bfricka/node-git-tags/issues
- npm.io page: https://npm.io/package/git-tags

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [semver](https://npm.io/package/semver.md) ^3.0.1

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.2.4 (latest) — 2014-10-31
- 0.2.3 — 2014-09-20
- 0.2.2 — 2014-09-20

## README

# Node Git Tags

Gets and parses [semver](http://semver.org/) tags using Git and Node.js

## Usage

Assuming you have the following git tags:

* `v1.0.1`
* `v1.0.0`
* `v0.1.0-beta`
* `NonSemverTag`

**Get all semver tags**
#### `gittags.get([repo], callback(err, tags))`

Argument            | Type                | Description
------------------- | ------------------- | -------------
`repo` *(optional)* | `string`            | Optional repo path. Defaults to `process.cwd()`
`callback`          | `function`          | Required callback fn
`callback(err)`     | `null \| Error`     | Error, if there is one
`callback(tags)`    | `Array.<string>`    | Array of semver tags found (e.g. `['1.0.1', '1.0.0']`)

```js
var gittags = require('git-tags');

gittags.get(function(err, tags) {
  if (err) throw err;

  console.log(tags);
  // ['1.0.1', '1.0.0', '0.1.0-beta']
});

// Also takes a repo location:
gittags.get('/foorepo', function(err, tags) {});
```

**Latest**
#### `gittags.latest([repo], callback(err, latest))`

| Name                | Type            | Description                                     |
| ------------------- | --------------- | ----------------------------------------------- |
| `repo` *(optional)* | `string`        | Optional repo path. Defaults to `process.cwd()` |
| `callback`          | `function`      | Required callback                               |
| `err`               | `null \| Error` | Error if, there is one                          |
| `latest`            | `string`        | Latest semver tag found (e.g. `'1.0.1'`)        |

```js
gittags.latest(function(err, latest) {
  console.log(latest);
  // '1.0.1'
});
```

**Oldest**
#### `gittags.oldest([repo], callback(err, oldest))`
Same as `latest` but opposite.
```js
gittags.oldest(function(err, oldest) {
  console.log(oldest);
  // '0.1.0-beta'
});
```

**Semver Parse**

Two functions relating to semver exist for convenience. `parse` is just `semver.parse`, and `mmp` which stands for "Major, Minor, Patch". If you need more semver stuff, you should [use the node-semver module](https://github.com/npm/node-semver) directly.

#### `gittags.parse(tag) -> SemVer`

| Name  | Type     | Description         |
| ----- | -------- | ------------------- |
| `tag` | `string` | Version string to parse (e.g. `'v1.0.2-beta'`). See [node-semver](https://github.com/npm/node-semver) for more info. |

#### `gittags.mmp(tag) -> formattedTag`

| Name           | Type     | Description                                      |
| -------------- | -------- | ------------------------------------------------ |
| `tag`          | `string` | Tag to format (e.g. `'v1.0.2-beta'`)             |
| `formattedTag` | `string` | Major.Minor.Patch formatted tag (e.g. `'1.0.2'`) |

```js
gittags.mmp('v1.3.10-beta.12');
// => '1.3.10'

var version = gittags.parse('v1.3.10-beta.12');
// <SemVer "1.3.10-beta.12">
version.prerelease;
// ['beta', 12]
version.compare('v1.3.10');
// -1
version.compare('v1.3.9');
// 1
// etc...
```

**Note**
Stating the obvious, this module uses the callback fashion of async handling. This makes them easy to integrate w/ promises.

**Bluebird, for example**
```js
var Q = require('bluebird');
var gittags = Q.promisifyAll(require('gittags'));

gittags.latestAsync().then(console.log);
// 1.0.1
```

I originally intended this to use `child_process.spawn` and return a stream, but I then realized these are blocking in Linux/Unix, limiting the usefulness of that. And it's Git tags so who cares?

If you want streams, you can use something like [highland.js](http://highlandjs.org/) which is awesome, BTW.

## License
MIT

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