前端框架选型是企业提升开发效率与用户体验的关键因素
725
2022-10-11
semiver 一个微小的实用程序来比较semver字符串(semivertex)
A tiny (187B) utility to compare semver strings.
Compare semver strings (eg, 1.8.2, 2.0.0-next.6, 0.0.0-alpha-1, etc) using the Intl.Collator class. Version suffixes are supported and are considered during comparison.
The output will always be 0, 1, or -1, allowing semiver to be used directly as a compare function for Array.sort().
This module exposes three module definitions:
ES Module: dist/semiver.mjsCommonJS: dist/semiver.jsUMD: dist/semiver.min.js
Install
$ npm install --save semiver
Usage
import semiver from 'semiver';// A === Bsemiver('0.0.0', '0.0.0'); //=> 0semiver('1.2.3', '1.2.3'); //=> 0// A > Bsemiver('2.1.0', '1.9.0'); //=> 1semiver('1.9.1', '1.9.0'); //=> 1semiver('10.0.0', '1.0.0'); //=> 1semiver('10.0.0', '8.9.0'); //=> 1semiver('1.2.3-next.10', '1.2.3-next.6'); //=> 1semiver('2.0.0-alpha-10', '2.0.0-alpha-6'); //=> 1semiver('2.0.0-beta.1', '2.0.0-alpha.8'); //=> 1// A < Bsemiver('1.9.0', '2.1.0'); //=> -1semiver('1.9.0', '1.9.1'); //=> -1semiver('1.0.0', '10.0.0'); //=> -1semiver('8.9.0', '10.0.0'); //=> -1semiver('1.2.3-next.6', '1.2.3-next.10'); //=> -1semiver('2.0.0-alpha-6', '2.0.0-alpha-10'); //=> -1semiver('2.0.0-alpha.8', '2.0.0-beta.1'); //=> -1// Sorting[ '4.11.6', '4.2.0', '1.5.19', '1.5.5', '1.0.0', '1.0.0-rc.1', '1.2.3', '1.2.3-alpha', '1.0.0-alpha.1', '1.0.0-alpha', '1.0.0-beta.11', '1.0.0-beta'].sort(semiver);/* [ '1.0.0-alpha', '1.0.0-alpha.1', '1.0.0-beta', '1.0.0-beta.11', '1.0.0-rc.1', '1.0.0', '1.2.3-alpha', '1.2.3', '1.5.5', '1.5.19', '4.2.0', '4.11.6' ]*/
API
semiver(a, b)
Returns: Number
0 indicates that a is equal to b-1 indicates that a is less than b1 indicates that a is greater than b
a
Type: String
The input string to compare.
b
Type: String
The string to compare against.
License
MIT © Luke Edwards
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~