# semver-truncate

> Truncate a semver version: `1.2.3` → `1.2.0`

Latest version **3.0.0** (published 2021-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install semver-truncate
pnpm add semver-truncate
yarn add semver-truncate
bun add semver-truncate
```

## Health

**Score 43/100 (D)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-04-28 |
| First published | 2014-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/semver-truncate) |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 1 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | semver, version, semantic, truncate, shorten, simplify |

## Links

- npm: https://www.npmjs.com/package/semver-truncate
- Repository: https://github.com/sindresorhus/semver-truncate
- Homepage: https://github.com/sindresorhus/semver-truncate#readme
- Issues: https://github.com/sindresorhus/semver-truncate/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/semver-truncate

## Dependencies (1)

- [semver](https://npm.io/package/semver.md) ^7.3.5

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2021-04-28
- 2.0.0 — 2019-04-27
- 1.1.2 — 2016-08-04
- 1.1.1 — 2016-08-04
- 1.1.0 — 2015-11-14
- 1.0.0 — 2014-10-07

## README

# semver-truncate

> Truncate a semver version: `1.2.3` → `1.2.0`

## Install

```
$ npm install semver-truncate
```

## Usage

```js
import semverTruncate from 'semver-truncate';

semverTruncate('1.2.3-foo', 'patch');
//=> '1.2.3'

semverTruncate('1.2.3', 'minor');
//=> '1.2.0'

semverTruncate('1.2.3', 'major');
//=> '1.0.0'
```

## API

### truncateSemver(version, type)

#### version

Type: `string`

Semver version.

#### type

Type: `'patch' | 'minor' | 'major'`

Version type to truncate to.

## Related

- [latest-semver](https://github.com/sindresorhus/latest-semver) - Get the latest stable semver version from an array of versions
- [to-semver](https://github.com/sindresorhus/to-semver) - Get an array of valid, sorted, and cleaned semver versions from an array of strings
- [semver-regex](https://github.com/sindresorhus/semver-regex) - Regular expression for matching semver versions
- [semver-diff](https://github.com/sindresorhus/semver-diff) - Get the diff type of two semver versions: `0.0.1` `0.0.2` → `patch`

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