aboutsummaryrefslogtreecommitdiff
path: root/autoload/prettier/utils/version.vim
diff options
context:
space:
mode:
authorMitermayer Reis <mitermayer.reis@gmail.com>2023-10-10 12:02:33 +1100
committerGitHub <noreply@github.com>2023-10-10 12:02:33 +1100
commitd10bdd15af8a61eff9d279bd2815b4192506d1c0 (patch)
tree5cf0fd4ce325299bb3d989563ac862525e99b846 /autoload/prettier/utils/version.vim
parent5e6cca21e12587c02e32a06bf423519eb1e9f1b2 (diff)
parentba1d24036b35df89728344a46ed1f2006fbd1255 (diff)
downloadvim-prettier-d10bdd15af8a61eff9d279bd2815b4192506d1c0.tar.xz
Merge pull request #348 from victorspt/fix/consider_option_version
Fix/consider option version
Diffstat (limited to 'autoload/prettier/utils/version.vim')
-rw-r--r--autoload/prettier/utils/version.vim25
1 files changed, 25 insertions, 0 deletions
diff --git a/autoload/prettier/utils/version.vim b/autoload/prettier/utils/version.vim
new file mode 100644
index 0000000..3cbbb73
--- /dev/null
+++ b/autoload/prettier/utils/version.vim
@@ -0,0 +1,25 @@
+" Returns 1 if the first argument is the greater version, returns 0 if the
+" arguments are the same version, or returns -1 if the first argument is the
+" lesser version.
+function! prettier#utils#version#Compare_versions(a, b) abort
+ let [l:a_major, l:a_minor, l:a_patch; l:rest] = a:a->split('\D')
+ \ ->map('str2nr(v:val)')
+ let [l:b_major, l:b_minor, l:b_patch; l:rest] = a:b->split('\D')
+ \ ->map('str2nr(v:val)')
+ let l:is_a_greater =
+ \ l:a_major > l:b_major
+ \ || (l:a_major == l:b_major && l:a_minor > l:b_minor)
+ \ || (l:a_major == l:b_major && l:a_minor == l:b_minor
+ \ && l:a_patch > l:b_patch)
+ let l:is_a_equal_b =
+ \ l:a_major == l:b_major
+ \ && l:a_minor == l:b_minor
+ \ && l:a_patch == l:b_patch
+ return l:is_a_greater ? 1 : (l:is_a_equal_b ? 0 : -1)
+endfunction
+
+" Returns 1 if the first argument is greater than or equal to the second,
+" otherwise returns 0.
+function! prettier#utils#version#Is_greater_or_equal_version(a, b) abort
+ return prettier#utils#version#Compare_versions(a:a, a:b) != -1
+endfunction