Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/einenlum/composer-version-parser

A library to extract the potential higher version of a package from Composer requirements
https://github.com/einenlum/composer-version-parser

composer php semver

Last synced: about 7 hours ago
JSON representation

A library to extract the potential higher version of a package from Composer requirements

Awesome Lists containing this project

README

        

# Composer Version Parser

This small library allows to parse the version requirements from a `composer.json` file, allowing to get the probable version of a package (useful when no `composer.lock` is present).

Examples:

| Input | Output |
| -- | -- |
| `v1.0.*` | `1.0` |
| `1.0.*` | `1.0` |
| `^3.*` | `3` |
| `^3.4.*` | `3.4` |
| `^3.4` | `3` |
| `^3.4.9` | `3.4` |
| `~3` | `3` |
| `~3.4` | `3` |
| `~3.4.9` | `3.4` |
| `3` | `3` |
| `3.4` | `3.4` |
| `3.4.9` | `3.4.9` |
| `3.*` | `3` |
| `3.4.*` | `3.4` |
| `v3` | `3` |
| `v3.4` | `3.4` |
| `v3.4.9` | `3.4.9` |
| `v3.*` | `3` |
| `v3.4.*` | `3.4` |
| `*` | `null` |

More complex cases are not handled for now.

| Input | Output |
| -- | -- |
| `>1.0.*` | `null` |
| `>=1.0` | `null` |
| >=1.0 || 8.* | `null` |
| `>=1.0; <2.0` | `null` |

## Install

```
composer require einenlum/composer-version-parser
```

## Usage

```php
parse('v3.4.*'); // '3.4'
```