index.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. declare namespace compareVersions {
  2. /**
  3. * Allowed arithmetic operators
  4. */
  5. type CompareOperator = '>' | '>=' | '=' | '<' | '<=';
  6. }
  7. declare const compareVersions: {
  8. /**
  9. * Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
  10. * This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
  11. * @param firstVersion - First version to compare
  12. * @param secondVersion - Second version to compare
  13. * @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
  14. */
  15. (firstVersion: string, secondVersion: string): 1 | 0 | -1;
  16. /**
  17. * Compare [semver](https://semver.org/) version strings using the specified operator.
  18. *
  19. * @param firstVersion First version to compare
  20. * @param secondVersion Second version to compare
  21. * @param operator Allowed arithmetic operator to use
  22. * @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.
  23. *
  24. * @example
  25. * ```
  26. * compareVersions.compare('10.1.8', '10.0.4', '>'); // return true
  27. * compareVersions.compare('10.0.1', '10.0.1', '='); // return true
  28. * compareVersions.compare('10.1.1', '10.2.2', '<'); // return true
  29. * compareVersions.compare('10.1.1', '10.2.2', '<='); // return true
  30. * compareVersions.compare('10.1.1', '10.2.2', '>='); // return false
  31. * ```
  32. */
  33. compare(
  34. firstVersion: string,
  35. secondVersion: string,
  36. operator: compareVersions.CompareOperator
  37. ): boolean;
  38. /**
  39. * Validate [semver](https://semver.org/) version strings.
  40. *
  41. * @param version Version number to validate
  42. * @returns `true` if the version number is a valid semver version number, `false` otherwise.
  43. *
  44. * @example
  45. * ```
  46. * compareVersions.validate('1.0.0-rc.1'); // return true
  47. * compareVersions.validate('1.0-rc.1'); // return false
  48. * compareVersions.validate('foo'); // return false
  49. * ```
  50. */
  51. validate(
  52. version: string
  53. ): boolean;
  54. };
  55. export = compareVersions;