New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

php_version_compare

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

php_version_compare

Compares two "PHP-standardized" version number strings

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

php_version_compare

License Coverage Build Dependencies

Compares two "PHP-standardized" version number strings.

PHP.NET documentation : "The function first replaces _, - and + with a dot . in the version strings and also inserts dots . before and after any non number so that for example '4.3.2RC1' becomes '4.3.2.RC.1'. Then it compares the parts starting from left to right. If a part contains special version strings these are handled in the following order: any string not found in this list < dev < alpha = a < beta = b < RC = rc < # < pl = p. This way not only versions with different levels like '4.1' and '4.1.2' can be compared but also any PHP specific version containing development state."

Written in pure JS. Passes all 700+ test cases of the standard PHP function source code.

Installing

npm install php_version_compare

Usage

php_version_compare(version1, version2[, operator])

Parameters

  • version1 : First version number.
  • version2 : Second version number.
  • operator : If the third optional operator argument is specified, test for a particular relationship. The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively. This parameter is case-sensitive, values should be lowercase.

Return value

By default, version_compare() returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower.

When using the optional operator argument, the function will return TRUE if the relationship is the one specified by the operator, FALSE otherwise.

Example

const versionCompare = require('php_version_compare')

console.log(versionCompare('1.11', '1.12')) // -1
console.log(versionCompare('1.11rc1', '1.11', 'lt')) // true

FAQs

Package last updated on 21 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts