Get the next major version of an npm package (NOT necessarily the latest!)

Solution for Get the next major version of an npm package (NOT necessarily the latest!)
is Given Below:

I’m writing a bash script to update & test packages in bulk. However, I want the script to not jump to the latest version, just the next major version if it exists and pasts test.

I’m looking at something akin to this (longer stretches of code reduced to pseudocode for brevity)

#!/bin/bash

# Assign package name to $packageName

# START MAIN LOOP

# Start code that does a preliminary test
...
# End code that does preliminary test
# Assign current package version to $current

npm install [email protected]#[next?]
# # The above line is the one I can't figure out. 
# Say, for example, $current is 3.4.7. and 
# [email protected] is 5.2.3. This should 
# update to 4.0.0, but if latest is 3.5.8, it would update
# to 3.5.8, but then not update if latest is 3.4.7

# Do post tests
# # If fails post tests
       # alert user to breaking version
       npm install [email protected]$current # revert to previous version

# # If succeeds post tests, check if now at @latest
# # # If not at @latest, repeat MAIN LOOP
# # # If at @latest, exit 0.

#!/usr/bin/bash
arr=('npm' 'yarn' 'puppetter' 'express')
for pkg in "${arr[@]}"; do
    pkg_noinstl=$(npm -g ls "$pkg" | grep -o '(empty)')
    if [[ "$pkg_noinstl" ]]; then
        echo "$pkg: Not Installed"
    else
        myversion=$(npm -g list "$pkg" | grep "@" | cut [email protected] -f2)
        int_myversion=$(echo "$myversion" | cut -f3 -d.)
        reg=$(echo "$myversion" | cut -f1,2 -d.)
        newversion=$(npm view "$pkg" versions | grep -oP "$reg.[0-9]{1,2}")
        int_newversion=$(echo "$newversion" | cut -f3 -d. | tail -1)

        if [[ "$int_newversion" -gt "$int_myversion" ]]; then
            n=$(echo "$newversion" | tail -1)
            echo "$pkg:$myversion you have an upgrade-->$n"
        else
            echo "$pkg: OK $myversion"
        fi
    fi
done

returns:
enter image description here

if you want +1 release 6.14.8-->6.14.9 then add:
 next_release=$(((int_myversion + 1)))
 intnr=$(echo "$newversion" | cut -d. -f3 | grep "$next_release")
 n=$(echo "$newversion" | tail -1)
 echo "$pkg:$myversion you have an upgrade-->$n, available-->$reg.$intnr"