diff options
-rw-r--r-- | semver.el | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -39,32 +39,36 @@ ;;; Code: (defun semver--constraint (semver-spec) - "Extract the constraint indicator from a semver spec + "Extract the constraint indicator from a semver spec. + +SEMVER-SPEC is the specification string to extract the constraint from. Example: (semver--constraint \"^1.1.0\") => \"^\" (semver--constraint \"1.1.0\") => nil - (semver--constraint \">=1.1.0\") => \">=\" -" + (semver--constraint \">=1.1.0\") => \">=\"" (if (string-match "\\([~^<>=]*\\)" semver-spec) (match-string 1 semver-spec) nil)) (defun semver--version (semver-spec) - "Extract the version number from a semver spec as a version triplet + "Extract the version number from a semver spec as a version triplet. + +SEMVER-SPEC is the version string to extract the version triplet from. Example: (semver--version \"^1.1.0\") => (1 1 0) (semver--version \"1.1.0\") => (1 1 0) - (semver--version \">=1.1.0\") => (1 1 0) -" - (if (string-match "\\([~^<>=]*\\)?\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" semver-spec) - (list (string-to-number (match-string 2 semver-spec)) - (string-to-number (match-string 3 semver-spec)) - (string-to-number (match-string 4 semver-spec))))) + (semver--version \">=1.1.0\") => (1 1 0)" + (if (string-match "\\([~^<>=]*\\)?\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" semver-spec) + (list (string-to-number (match-string 2 semver-spec)) + (string-to-number (match-string 3 semver-spec)) + (string-to-number (match-string 4 semver-spec))))) (defun semver--format-constraint (constraint version) - "Expresses version constraints in a readable format and retrun as string" + "Expresses version constraints in a readable format and retrun as string. +CONSTRAINT is a constraint string like `>=' or `^'. +VERSION is the version triplet as a list like `(major minor patch'." (if (not constraint) (format "%d.%d.%d" (car version) (cadr version) (caddr version)) (let ((major (car version)) @@ -82,11 +86,13 @@ Example: (defun semver--expand (semver-spec) - (interactive "sSemver spec: ") "Translates a semver spec to more explicit version constraints. +SEMVER-SPEC is the version string to extract the version triplet from. + Takes in a semver spec like `^1.1.0' and return the version range in a more human-readable format like `>=1.1.0 <2.0.0'." + (interactive "sSemver spec: ") (let ((constraint (semver--constraint semver-spec)) (version (semver--version semver-spec))) (message (semver--format-constraint constraint version)))) |