Add nvm_is_valid_version
parent
8a87133f71
commit
e1b7496cf0
16
nvm.sh
16
nvm.sh
|
@ -263,6 +263,22 @@ $(nvm_ls_remote_iojs "$PATTERN")" | command grep -v "N/A" | command sed '/^$/d')
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_is_valid_version() {
|
||||||
|
if nvm_validate_implicit_alias "$1" 2> /dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
case "$1" in
|
||||||
|
"$(nvm_iojs_prefix)" | "$(nvm_node_prefix)")
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
local VERSION
|
||||||
|
VERSION="$(nvm_strip_iojs_prefix "$1")"
|
||||||
|
nvm_version_greater "$VERSION"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
nvm_normalize_version() {
|
nvm_normalize_version() {
|
||||||
echo "$1" | command sed -e 's/^v//' | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
|
echo "$1" | command sed -e 's/^v//' | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
nvm_is_valid_version 0.1.2 || die "nvm_is_valid_version 0.1.2 did not return 0"
|
||||||
|
nvm_is_valid_version foo && die "nvm_is_valid_version foo did not return 1"
|
||||||
|
nvm_is_valid_version iojs-1 || die "nvm_is_valid_version iojs-1 did not return 0"
|
||||||
|
nvm_is_valid_version iojs || die "nvm_is_valid_version iojs did not return 0"
|
||||||
|
nvm_is_valid_version node || die "nvm_is_valid_version node did not return 0"
|
||||||
|
nvm_is_valid_version stable || die "nvm_is_valid_version stable did not return 0"
|
||||||
|
nvm_is_valid_version unstable || die "nvm_is_valid_version unstable did not return 0"
|
Loading…
Reference in New Issue